第九章 MATLAB符号计算
一、选择题
1~5:BDADC
二、填空题
1.符号对象;sym;syms。
2.NaN;Inf。
3.55。
4.符号表达式;符号变量。
5.D2y。
三、应用题
1.
程序:
syms x y z;
%第(1)问
f1=x^9-1;
res1=factor(f1)
%第(2)问
f2=x^4+x^3+2*x^2+x+1;
res2=factor(f2)
%第(3)问
f3=125*x^6+75*x^4+15*x^2+1;
res3=factor(f3)
%第(4)问
f4=x^2+y^2+z^2+2*(x*y+y*z+x*z);
res4=factor(f4)
结果:
res1 =
[ x - 1, x^2 + x + 1, x^6 + x^3 + 1]
res2 =
[ x^2 + 1, x^2 + x + 1]
res3 =
[ 5x^2 + 1, 5x^2 + 1, 5*x^2 + 1]
res4 =
[ x + y + z, x + y + z]
2.
程序:
syms x;
%第(1)问
f1=(x^2-6*x+8)/(x^2-5*x+4);
res1=limit(f1,x,4)
%第(2)问
f2=(abs(x))/(x);
res2=limit(f2,x,0,'left')
结果:
res1 = 2/3
res2 = -1
3.
(1)
程序:
syms x y;
f1=sin(x)-x^2/2;
dy=diff(f1)
d2y=diff(f1,x,2)
结果:
dy =cos(x) - x
d2y =- sin(x) - 1
(2)
程序:
syms x y;
f2=x+y-sqrt(x^2+y^2);
d2z_dxdy=diff(diff(f2,x),y)
dy_dx=diff(y,x)
结果:
d2z_dxdy =(x*y)/(x^2 + y2)(3/2)
dy_dx =0
4.
程序:
syms x a;
%第(1)问
f1=1/(x+a);
res1=int(f1,x)
%第(2)问
f2=x^2/sqrt(a^2+x^2);
res2=int(f2,x)
结果:
res1 =log(a + x)
res2 =(x*(a^2 + x2)(1/2))/2 - (a^2*log(x + (a^2 + x2)(1/2)))/2
5.
程序:
syms x ;
%第(1)问
f1=x*(2-x^2)^12;
res1=int(f1,x,0,1)%符号计算
y1=@(t) t.*(2-t.^2).^12;
resy1=quad(y1,0,1)%数值计算
%第(2)问
f2=abs(log(x));
res2=int(f2,x,exp(-1),exp(1))%符号计算
y2=@(t) abs(log(t));
resy2=quad(y2,exp(-1),exp(1))%数值计算
结果:
res1 =8191/26%符号计算结果
resy1 =315.0385%数值计算结果
res2 =(828390857088487log(828390857088487/2251799813685248))/2251799813685248 + (3060513257434037log(3060513257434037/1125899906842624))/1125899906842624 - 2445817744586065/2251799813685248%符号计算结果
resy2 = 1.2642%数值计算结果
从结果可以看出,符号计算的结果为精确的数学表达式,而数值计算的结果近似为一个有限小数。
6.
程序:
syms x n;
%第(1)问
f1=(-1)*(2*x-1)/(2^(x-1));
res1=symsum(f1,x,1,inf)
%第(2)问
f2=x^(2*n-1)/(2*n-1);
res2=symsum(f2,x,1,inf)
结果:
res1 =-6
res2 = piecewise(real(n) < 0, zeta(1 - 2n)/(2n - 1))
7.
程序:
syms x ;
%第(1)问
f1=(exp(x)+exp(-x))/2;
res1=taylor(f1,x,0,'order',6)
%第(2)问
f2=tan(x);
res2=taylor(f2,x,2,'order',4)
结果:
res1 =x^4/24 + x^2/2 + 1
res2 =tan(2) + (tan(2) + tan(2)^3)(x - 2)^2 + (tan(2)^2 + 1)(x - 2) + (x - 2)3*(tan(2)2 + tan(2)*(tan(2)/3 + tan(2)^3) + 1/3)
8.
程序:
syms x a b c ;
%第(1)问
f1=a*x^2+b*x+c;
res1=solve(f1,x)
%第(2)问
f2=2*tan(3*x-pi/4)-1;
res2=solve(f2,x)
结果:
res1 = -(b + (b^2 - 4ac)^(1/2))/(2a)和-(b - (b^2 - 4ac)^(1/2))/(2a)
res2 =pi/12 + atan(1/2)/3
9.
程序:
第(1)问
syms x y z;
f1=log(x/y)-9;
f2=exp(x+y)-3
[x1,y1]=solve(f1,f2,[x,y])
结果:
x1 =1.0984767258705762263860477746359
y1 =0.00013556279753346500919746228658192
第(2)问
f3=4*x^2/(4*x^2+1)-y;
f4=4*y^2/(4*y^2+1)-z;
f5=4*z^2/(4*z^2+1)-x;
[x2,y2,z2]=solve(f3,f4,f5,[x,y,z])
结果:
x2 =
(327root(z1^6 + (25z1^5)/89 + (31z1^4)/356 + (3z1^3)/178 + (7z1^2)/1424 + z1/1424 + 1/5696, z1, 6)^2)/89 - (110root(z1^6 + (25z1^5)/89 + (31z1^4)/356 + (3z1^3)/178 + (7z1^2)/1424 + z1/1424 + 1/5696, z1, 6)^3)/89 - (1924root(z1^6 + (25z1^5)/89 + (31z1^4)/356 + (3z1^3)/178 + (7z1^2)/1424 + z1/1424 + 1/5696, z1, 6)^4)/89 - 20root(z1^6 + (25z1^5)/89 + (31z1^4)/356 + (3z1^3)/178 + (7z1^2)/1424 + z1/1424 + 1/5696, z1, 6)^5 - (21root(z1^6 + (25z1^5)/89 + (31z1^4)/356 + (3z1^3)/178 + (7z1^2)/1424 + z1/1424 + 1/5696, z1, 6))/356 - 1/89
0
1/2
y2 =
(451root(z1^6 + (25z1^5)/89 + (31z1^4)/356 + (3z1^3)/178 + (7z1^2)/1424 + z1/1424 + 1/5696, z1, 6)^2)/178 + (926root(z1^6 + (25z1^5)/89 + (31z1^4)/356 + (3z1^3)/178 + (7z1^2)/1424 + z1/1424 + 1/5696, z1, 6)^3)/89 + (9863root(z1^6 + (25z1^5)/89 + (31z1^4)/356 + (3z1^3)/178 + (7z1^2)/1424 + z1/1424 + 1/5696, z1, 6)^4)/89 + 156root(z1^6 + (25z1^5)/89 + (31z1^4)/356 + (3z1^3)/178 + (7z1^2)/1424 + z1/1424 + 1/5696, z1, 6)^5 + (107root(z1^6 + (25z1^5)/89 + (31z1^4)/356 + (3z1^3)/178 + (7z1^2)/1424 + z1/1424 + 1/5696, z1, 6))/356 + 139/1424
0
1/2
z2 =
root(z1^6 + (25z1^5)/89 + (31z1^4)/356 + (3z1^3)/178 + (7z1^2)/1424 + z1/1424 + 1/5696, z1, 6)
0
1/2
10.
主程序:
res=dsolve('x^2*(D2y)-x*Dy+y-x*log(x)','y(1)=1','Dy(1)=1','x');
x1=-10:0.1:10;
y1=(x1.*(log(x1).^3 + 6))./6;
subplot(2,1,1)
plot(x1,y1,'r')
title('符号计算')
[x2,y2]=ode45('odefun',[-10,10],[1,1]);
subplot(2,1,2)
plot(x2,y2,'b')
title('数值计算')
函数文件:
function dy= odefun(x,y)
dy=zeros(2,1);
dy(1)=y(2);
dy(2)=(x*log(x)-y(1)+x*y(2))/x^2;
end
(ps:绘图的时候不知道什么原因导致两种结果绘制到同一个坐标系导致图形混乱,因此分成两部分比较了 /(ㄒoㄒ)/~~)
从结果可以看出,符号计算相较于数值计算结果较为精确
若想要讲解可下方留言,看到就会回复!!!