语法知识
差分与近似微分
微分运算
不定积分与定积分运算
数值积分
实战演练
差分与近似微分实例
>> t=1:10;
>> s=[2 6 12 20 30 42 56 72 90 110];
>> v=diff(s)./diff(t)
v =
4 6 8 10 12 14 16 18 20
>> a=diff(v)./diff(t(1:9))
a =
2 2 2 2 2 2 2 2
微分运算实例
>> syms x
>> y=x*sin(x)+15;
>> diff(y)
ans =
sin(x) + x*cos(x)
>> x=pi/4;
>> eval(ans)
ans =
1.2625
>> syms x y
>> z=x*x+2*x*y-y*y-2*x
z =
x^2 + 2*x*y - 2*x - y^2
>> x1=diff(z,'x')
x1 =
2*x + 2*y - 2
>> y1=diff(z,'y')
y1 =
2*x - 2*y
>> x1=simplify(x1)
x1 =
2*x + 2*y - 2
>> yx=-x1/y1
yx =
-(2*x + 2*y - 2)/(2*x - 2*y)
不定积分与定积分运算实例
>> syms x a b
>> y=exp(a*x)*sin(b*x)
y =
exp(a*x)*sin(b*x)
>> z=int(y,'x')
z =
-(exp(a*x)*(b*cos(b*x) - a*sin(b*x)))/(a^2 + b^2)
>> syms x
>> y=sqrt(1-sin(2*x))
y =
(1 - sin(2*x))^(1/2)
>> z=int(y,0,pi/2)
z =
2*2^(1/2) - 2
>> eval(z)
ans =
0.8284
数值积分实例
>> x=0:pi/150:pi;
>> y=sin(x).^2;
>> z=sqrt(1/pi*pi/150*trapz(y))
z =
0.7071
>> x=0:pi/20:pi;
>> y=sin(x)./(x.^3+3*x+5);
>> z=trapz(x,y)
z =
0.1616
>> q=quad('sin(x)./(x.^3+3*x+5)',0,pi)
q =
0.1620