1 建立一个命令M 文件:求数60.70.80,权数分别为1.1,1.3,1.2的加权平均数。
在指令窗口输入指令edit ,打开空白的M 文件编辑器;里面输入s=60*1.1+70*1.3+80*1.2;ave=s/3然后保存即可2 编写函数M 文件SQRT.M;函数()f x = x=567.889与0.0368处的近似值(保留有效数四位)在指令窗口输入指令edit ,打开空白的M 文件编辑器;里面输入syms x1 x2 s1 s2 zhi1 zhi2x1=567.889;x2=0.368;s1=sqrt(x1);s2=sqrt(x2);zhi1=vpa(s1,4)zhi2=vpa(s2,4)然后保存并命名为SQRT.M 即可3用matlab 计算()f x a b=-的值,其中a=2.3,b=4.89. >> syms a b>> a=2.3;b=4.89;>> sqrt(a^2+b^2)/abs(a-b)ans =2.08644用matlab 计算函数()f x =x=3π处的值. >> syms x>> x=pi/3;>> sqrt(sin(x)+cos(x))/abs(1-x^2)ans =12.09625用matlab 计算函数()arctan f x x =在x=1.23处的值.>> syms x>> x=1.23;>> atan(x)+sqrt(log(x+1))ans =1.78376 用matlab 计算函数222sin cos ()()31a b x x f x f x a b xπ++==--在x=-2.1处的值. >> syms x >> x=-2.1;>> 2-3^x*log(abs(x))ans =1.92617 用蓝色.点连线.叉号绘制函数y=2x 在[0,2]上步长为0.1的图像.>> syms x y>> x=0:0.2:2;y=2*sqrt(x);>> plot(x,y,'b.-')8 用紫色.叉号.实连线绘制函数ln 10y x =+在[20,15]--上步长为0.2的图像. >> syms x y>> x=-20:0.2:-15;y=log(abs(x+10));>> plot(x,y,'mx-')ln 10[20,15]y x x=+--9 用红色.加号连线 虚线绘制函数sin()22x y π=-在[-10,10]上步长为0.2的图像. >> syms x y;>> x=-10:0.2:10;y=sin(x/2-pi/2);>> plot(x,y,'r+--')10用紫红色.圆圈.点连线绘制函数sin(2)3y x π=+在[0,4]π上步长为0.2的图像.sin(2)sin()[0,4]322x y x y πππ=+=- >> syms x y >> x=0:0.2:4*pi;y=sin(2*x+pi/3);>> plot(x,y,'mo-.')11 在同一坐标中,用分别青色.叉号.实连线与红色.星色.虚连线绘制y=cos3x 与y x =.>> syms x y1 y2>> x=0:pi/50:2*pi;y1=cos(3*sqrt(x));y2=3*cos(sqrt(x));>> plot(x,y1,'cx-',x,y2,'r*--')12 在同一坐标系中绘制函数234,,y x y x y x ===这三条曲线的图标,并要求用两种方法加各种标注.234,,y x y x y x ===>> syms x y1 y2 y3;>> x=-2:0.1:2;y1=x.^2;y2=x.^3;y3=x.^4;plot(x,y1,x,y2,x,y3);13 作曲线2sinx ty tz t⎧=⎪=⎨⎪=⎩的3维图像>> syms x y t z>> t=0:1/50:2*pi; >> x=t.^2;y=sin(t);z=t;>> stem3(x,y,z)14 作环面(1cos)cos(1cos)sinsinx u vy u vz u=+⎧⎪=+⎨⎪=⎩在(0,2)(0,2)ππ⨯上的3维图像>> syms x y u v z>> u=0:pi/50:2*pi;v=0:pi/50:2*pi;>>x=(1+cos(u)).*cos(v);y=(1+cos(u)).*sin(v);z=sin(u); >> plot3(x,y,z)15 求极限0lim x +→0lim x +→>> syms x y>> y=sin(2^0.5*x)/sqrt(1-cos(x));>> limit(y,x,0,'right')ans =216 求极限1201lim ()3x x +→ >> syms y x>> y=(1/3)^(1/(2*x));>> limit(y,x,0,'right')ans =17求极限lim x>> syms x y>> y=(x*cos(x))/sqrt(1+x^3);>> limit(y,x,+inf)ans =18 求极限21lim ()1x x x x →+∞+- >> syms x y>> y=((x+1)/(x-1))^(2*x);>> limit(y,x,+inf)ans =exp(4)19 求极限01cos 2lim sin x x x x→->> syms x y>> y=(1-cos(2*x))/(x*sin(x));>> limit(y,x,0)ans =220 求极限 0x → >> syms x y>> y=(sqrt(1+x)-sqrt(1-x))/x;>> limit(y,x,0)ans =121 求极限2221lim 2x x x x x →+∞++-+ >> syms x y>> y=(x^2+2*x+1)/(x^2-x+2);>> limit(y,x,+inf)ans =122 求函数y=5(21)arctan x x -+的导数>> syms x y>> y=(2*x-1)^5+atan(x);>> diff(y)ans =10*(2*x - 1)^4 + 1/(x^2 + 1)23 求函数y=2tan 1x x y x=+的导数 >> syms y x>> y=(x*tan(x))/(1+x^2);>> diff(y)ans =tan(x)/(x^2 + 1) + (x*(tan(x)^2 + 1))/(x^2 + 1) - (2*x^2*tan(x))/(x^2 + 1)^224 求函数3tan x y e x -=的导数>> syms y x>> y=exp^(-3*x)*tan(x)>> y=exp(-3*x)*tan(x)y =exp(-3*x)*tan(x)>> diff(y)ans =exp(-3*x)*(tan(x)^2 + 1) - 3*exp(-3*x)*tan(x)25 求函数y=22ln sin 2xx π+在x=1的导数>> syms x y>> y=(1-x)/(1+x);>> diff(y,x,2)ans =2/(x + 1)^2 - (2*(x - 1))/(x + 1)^3>> syms x y>> y=2*log(x)+sin(pi*x/2)^2;>> dxdy=diff(y)dxdy =2/x + pi*cos((pi*x)/2)*sin((pi*x)/2)zhi=subs(dxdy,1)zhi =226 求函数y=01cos 2limsin x x x x →-11x x-+的二阶导数 >> syms x y>> y=(1-x)/(1+x);>> diff(y,x,2)ans =2/(x + 1)^2 - (2*(x - 1))/(x + 1)^327 求函数; >> syms x y>> y=((x-1)^3*(3+2*x)^2/(1+x)^4)^0.2;>> diff(y)ans =(((8*x + 12)*(x - 1)^3)/(x + 1)^4 + (3*(2*x + 3)^2*(x - 1)^2)/(x + 1)^4 - (4*(2*x + 3)^2*(x -1)^3)/(x + 1)^5)/(5*(((2*x + 3)^2*(x - 1)^3)/(x + 1)^4)^(4/5))28在区间(,-∞+∞)内求函数43()341f x x x =-+的最值.>> f='-3*x^4+4*x^3-1';>> [x,y]=fminbnd(f,-inf,inf)x =NaNy =NaN>> f='3*x^4-4*x^3+1';>> [x,y]=fminbnd(f,-inf,inf)x =NaNy =NaN29在区间(-1,5)内求函数发()(f x x =-的最值.>> f='(x-1)*x^0.6';>> [x,y]=fminbnd(f,-1,5)x =0.3750y =-0.3470>>>> f='-(x-1)*x^0.6';>> [x,y]=fminbnd(f,-1,5)x =4.9999y =-10.505930 求不定积分(ln32sin )x x dx -⎰(ln32sin )x x dx -⎰ >> syms x y>> y=log(3*x)-2*sin(x);>> int(y)ans =2*cos(x) - x + x*log(3) + x*log(x)31求不定积分2sin x e xdx ⎰>> syms x y>> y=exp(x)*sin(x)^2;>> int(y)ans =-(exp(x)*(cos(2*x) + 2*sin(2*x) - 5))/1032. 求不定积分>> syms x y>> y=x*atan(x)/(1+x)^0.5;>> int(y)Warning: Explicit integral could not be found.ans =int((x*atan(x))/(x + 1)^(1/2), x)33.计算不定积分2(2cos )x x x e dx --⎰ >> syms x y>> y=1/exp(x^2)*(2*x-cos(x));>> int(y)Warning: Explicit integral could not be found.ans =int(exp(-x^2)*(2*x - cos(x)), x)34.计算定积分10(32)x e x dx -+⎰>> syms x y>> y=exp(-x)*(3*x+2);>> int(y,0,1)ans =5 - 8*exp(-1)10(32)x e x dx -+⎰35.计算定积分0lim x x→120(1)cos x arc xdx +⎰>> syms y x>> y=(x^2+1)*acos(x);>> int(y,0,1)ans =11/936.计算定积分10cos ln(1)x x dx +⎰>> syms x y>> y=(cos(x)*log(x+1));>> int(y,0,1)Warning: Explicit integral could not be found.ans =int(log(x + 1)*cos(x), x == 0..1)37计算广义积分2122x x dx +∞++-∞⎰;>> syms y x>> y=(1/(x^2+2*x+2));>> int(y,-inf,inf)ans =pi38.计算广义积分20x dx x e +∞-⎰; >> syms x y>> y=x^2*exp(-x);>> int(y,0,+inf)ans =2。