托馬斯微積分 從入門到失望


決定把例題用程序都完成一遍。從最基本的開始:語言選擇用python,vex,Houdini作圖

<1>

a,求球的體積.半徑為4,中心點為0,左斷點為-4,右斷點為4

import math
radius = 4.000
diameter = radius *2
# sphere r=4 R=8
# this spere is y=sqrt(16-x*x)
# per cylinder volume is PI*r*r*dtx
def sphere_function(xpos,dtx):
    return math.sqrt(16.00-xpos*xpos) * math.sqrt(16.00-xpos*xpos)*dtx

# @n is the is this sphere that will split to n piece along xpos
# if sphere r=4, slice is 8, dtx= R/8 = 1
def calculateVolume(n):
    v = 0
    dtx = diameter/n
    for j in range(0,n,1):
        xp = j*(diameter/n) - radius   #if sphere radius is 4,left plot is -4 ,right plot is 4
        v += sphere_function(xp,dtx)
    return v

# sphere volume use base function : 3/4 * PI * (R*R*R)
def ruleCacluateVolume(r):
    return 4/3.000 * r*r*r

if __name__ == "__main__":
    #split a sphere to 20 cylinder
    print "use 4   slice :"  ,calculateVolume(4)
    print "use 8   slice :"  ,calculateVolume(8)
    print "use 20  slice :"  ,calculateVolume(20)
    print "use 120 slice :"  ,calculateVolume(120)
    print "use 200 slice :"  ,calculateVolume(200)
View Code

 

python volume.py

use 4   slice : 80.0
use 8   slice : 84.0
use 20  slice : 85.12
use 120 slice : 85.3274074074
use 200 slice : 85.3312
use sphere volume function : 85.3333333333

可以看到和標准體積的球體不差多少。200個切片就很精確了 幾乎一樣

 

 b,半球體積:

 

<2>求類似火箭頭的曲線體積:

import math

#
# curve function is y=sqrt(x)
# x range->0-5
#

maxRange = 5.0

def clinder_volume(xpos,dtx):
    return math.sqrt(xpos*xpos) * dtx

def curve_volume(n):
    v = 0.0
    dtx = maxRange/n
    for x in range(0,n,1):
        xpos = x*(maxRange/n)
        v += clinder_volume(xpos,dtx)
    return v

if __name__ == "__main__":
    print curve_volume(15)
View Code

 


 

<3> 求a和b為什么值,積分的值最大

 

 <4> 梯形法求積分,simpson法求積分

 

# Trapezoidal
# S = 1/2(y0+ 2y1 + 2y2 + 2y3+...+ 2yn-1 + yn)

def Trapezoidal(down,up,n,func):
    if up==down:
        return 0.0
    h = float(up-down) / float(n)
    start = func(down)
    end = func(up)

    process = 0.0
    for dt in xrange(0,n+1,1):
        if dt == 0 or dt == n:
            continue
        process += 2 * func(down + dt * h)
    sum =  (start + end + process) * (h/2.0)
    return sum



# Simpson
# S = h/3(y0 + 4y1 + 2y2 + 4y3 + 2y4 + ... + 2yn-1 + yn)
# func is f(x)
def Simpson(down,up,n,func):
    if up==down:
        return 0.0
    h = float(up-down) / float(n)
    start = func(down)
    end = func(up)
    process = 0.0
    for dt in xrange(0,n+1,1):
        if dt == 0 or dt == n:
            continue
        # select the 1 3 5 7 9... index
        if dt%2 == 1:
            process += 4 * func(down + dt * h)
        # select the 2 4 6 8 10... index
        if dt%2 == 0:
            process += 2 * func(down + dt * h)

    sum =  (start + end + process) * (h/3.0)
    return sum



if __name__ == "__main__":

    # part1
    # fx = 5x^4 [0,2]  n=4
    func = lambda x:5*x*x*x*x
    T = Simpson(0,2,4,func)
    print T
    # part2
    # fx = x [1,2] n=4
    func2 = lambda x:x
    T2 = Simpson(1,2,4,func2)
    print T2

    # part3
    # fx = x*x
    func3 = lambda x:x*x
    T3 = Trapezoidal(1,2,4,func3)
    print T3

    func4 = lambda x:x*x + 1
    T_T4 = Trapezoidal(-1,1,4,func4)
    S_T4 = Simpson(-1,1,4,func4)
    print T_T4,S_T4
View Code

 

 

 

 

<4> 復習黎曼和 和 定積分關系

 

 

 

 

 

5,求椎體體積:

 

Houdini求出-55

 

 fx = x^2;

則積分為x^3 / 3

上限為y最大值

下限為y最小值

float ptsx[];
float ptsy[];
float ptsz[];
int npt = npoints(0);
resize(ptsx,npt);
resize(ptsy,npt);
resize(ptsz,npt);

for(int i=0;i<npt;i++)
{
    vector pos = point(0,"P",i);
    ptsx[i] = pos.x;
    ptsy[i] = pos.y;
    ptsz[i] = pos.z;
}

float maxy = max(ptsy);
float miny = min(ptsy);


printf("%f,%f\n",miny,maxy);


float dttop = pow(maxy,3)  /  3.0;
float dtbottom = pow(miny,3) / 3.0;

float volume = dttop - dtbottom; 

adddetailattrib(geoself(),"cvolume",volume);
View Code

 

 

 6,一個立方體x=0 和 x=4 出垂直於x軸的兩個平面之間,在0<= X <= 4 垂直於x橫截面都是正方形,並且他們對角線都是從拋物線y = -sqrt(x) 和 y = sqrt(x)。

如圖:

 

 

 

 對角線長度則為2sqrt(x)

對角線一半為d = sqrt(x)

要求變長 h , 已知sina = d / h , 因為a = 45,所以 h =( 2sqrt(x) ) / sqrt(2)

A(x) = h^2  = 2x

求積分2x        0 <=x <= 4

F(x) = x^2

F(4) - F(0) = 16

 

 7,x = sqrt(5) y^2 的曲線(0<y<2),從曲線Y到這條曲線形成的立體,由圓盤組成。

求這個形體體積.

 

 8,

 

 區域有y = x ^2  + 1,y = x+3圍成的面積 沿着X軸向旋轉,求旋轉體體積,。

 

 

 

兩線交點:-1 , 2 

PI * R(x) ^2 - PI * r(x)^2 的積分.

PI(x+3)^2 - PI(x^2+1)^2 = PI[  (x+3)^2 -  (x^2+1)^2  ]  

-1<x<2

 求積分.

 

 9,y=0與y=5 之間的y = x^2 / 2 

a,圖像繞Y旋轉一周所形成的碗狀體積。

b,並且求如果每秒3立方單位的常數速率往碗里灌水,當水深為4個單位時,水面上升的速率。

 

 

 

 

 旋轉法求體積,因為繞Y旋轉,所以半徑是x = sqrt(2y)

面積:PI * r^2 = 2 *PI *y

求積分0,5 區間 , 2*pi*y dy 的積分 是25PI

 

 v(h) = | A(h) dh

則dv/dh = A(h) = 2 * PI * y

dv/dt = (dv/dh) * (dh/dt)

dh/dt 則是我們的速率。 dh/dt = (dv/dt) * (1 / 2*PI*y )

則速率:dh/dt = 3 * (   1  /    2*PI*4 )

 

 

 

  5章 5.2 7題

y=x, y=-x/2 , x=2  求兩條曲線 和給定的范圍 ,沿着Y旋轉的體積。(圓柱薄殼法)

 

 

 圓柱薄殼法:

 

 

微分:根據二階導y''和一階導y'大概畫函數圖像。

<1>

x<2                 y'<0 ,y'' <0 
2           y=1     y'=0 ,y''<0
2<x<4               y'>0 ,y''<0
4           y=4
4<x<6               y'>9,y''<0
6           y=7
x>6                 y'<0.y''<0

 

 

 

 

 

。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM