1、y findsym(g,2)y,t (3):用常数替换符号变量: x=0:10; y=subs(f,x)y = Columns 1 through 8 0 Columns 9 through 11练习:用y替换x,查看结果及其数据类型。z=subs(f,y)z = class(z)double (4):符号对象与数值的转换和任意精度控制: f1=subs(f,5f1 =sin(5) y1=double(f1)y1 = y2=eval(f1)y2 =将y1用sym函数转换为符号对象,并用d,f,e,r4种格式表示。 y2=sym(y1,d vpa(y2,8)-0. class(y2)sym y3
2、=sym(y1,fy3 =-/9007 y4=sym(y1,ey4 = y5=sym(y1,ry5 =采用digits和vpa实现任意精度控制: digitsDigits = 32 vpa(f1) vpa(f1,10)(5):求反函数和复合函数 用finverse函数求f,g的反函数); finverse(f)Warning: finverse(sin(x) is not unique. asin(x) finverse(g)y/exp(2*t) finverse(g,tlog(t/y)/2 用compose函数求f,g的复合函数 compose(f,g)sin(y*exp(2*t) comp
3、ose(f,g,zsin(z*exp(2*t)2;自建两个一元四次符号表达式,分别进行其符号表达式的加、减、乘等运算,并提交命令行和结果; syms x f=x4+2*x3-5*x2+6*x+8x4 + 2*x3 - 5*x2 + 6*x + 8 class(f) g=2*x4-5*x3+8*x2+7*x-22*x4 - 5*x3 + 8*x2 + 7*x - 2 f+g3*x4 - 3*x3 + 3*x2 + 13*x + 6 f-g- x4 + 7*x3 - 13*x2 - x + 10 f*g(x4 + 2*x3 - 5*x2 + 6*x + 8)*(2*x4 - 5*x3 + 8*x2
4、 + 7*x - 2)3:自建一个可化简一元五次多项式和一个三角函数符号表达式,依次使用pretty, horner, factor, simplify和simple等函数对该表达式进行化简,并提交命令行和结果;syms x y f=x5+x4+2*x+2x5 + x4 + 2*x + 2 g=cos(y)2-sin(y)2cos(y)2 - sin(y)2 class(g) pretty(f) 5 4 x + x + 2 x + 2 horner(f)x*(x3*(x + 1) + 2) + 2 factor(f)(x + 1)*(x4 + 2) simplify(f)(x4 + 2)*(x
5、 + 1) simple(f)simplify:radsimp:simplify(100):combine(sincos):combine(sinhcosh):combine(ln):factor:expand:combine:rewrite(exp):rewrite(sincos):rewrite(sinhcosh):rewrite(tan):mwcos2sin:collect(x): pretty(g) 2 2 cos(y) - sin(y) horner(g) factor(g)(cos(y) - sin(y)*(cos(y) + sin(y) simplify(g)cos(2*y) s
6、imple(g) (cos(y) - sin(y)*(cos(y) + sin(y) (1/exp(y*i)/2 + exp(y*i)/2)2 - (i*exp(i*y)/2 - i/(2*exp(i*y)2cosh(-y*i)2 + sinh(-y*i)2 (tan(y/2)2 - 1)2/(tan(y/2)2 + 1)2 - (4*tan(y/2)2)/(tan(y/2)2 + 1)21 - 2*sin(y)2collect(y):4:完成教材实验四第1节“1.绘制二维图线”中的所有内容,绘制4种二维曲线,把图形窗口分割为2行2列,并分别标明图名、坐标值等;M文件:clf;clc;clea
7、r;%2行2列子图的第1个图figure(1);subplot(2,2,1);t1=0:y1=sin(2*pi*t1);plot(t1,y1);title(y=sin(2pit)%2行2列子图的第2个图subplot(2,2,2);t2=0:y2=exp(-t2);exp(-2*t2);exp(-3*t2); plot(t2,y2); axis(0 2 ); title(y=e-t,y=e-2t,y=e-3t %2行2列子图的第3个图 subplot(2,2,3); t3=0 1 1 2 2 3 4; y3=0 0 2 2 0 0 0; plot(t3,y3); axis(0 4 3);脉冲信
8、号 %2行2列子图的第4个图 subplot(2,2,4); t4=0:2*pi; plot(sin(t4),cos(t4); axis( ); axis equal;圆 插图:5:参照教材实验四第3节“3.绘制特殊图形”中的相关内容,分别绘制条形图、实心图、阶梯图和火柴杆图,建议选取不同的函数来产生曲线;figure(2);%条形图x1=3:6;y1= 13 ;bar(x1,y1);条形图xlabel(it X,fontsize,10);ylabel(Ytext(5,7,my picture%实心图x2=0:y2=cos(x2);plot(x2,y2);fill(x2,y2,y实心图it Y
9、text(3,0,the secondFontNamecommercialscript BT%阶梯图subplot(2,2,3);x3=0:y3=sin(x3);stairs(x3,y3);阶梯图the thridFontsize%火柴杆图subplot(2,2,4);x4=0:y4=cos(x4)+;stem(x4,y4);火柴杆图the fourth6:产生10个服从正态分布的随机数,计算该数组的统计变量(包括均值、标准差、最大值、最小值等),并绘制二维和三维饼状图。注意程序运行时是否出现警告信息,思考为什么?figure(3);y=randn(10,1);mean(y)std(y)max(y)min(y)subplot(2,1,1);explode=0 0 0 0 0 1 0 0 0 0;pie(y,explode,1234678910);subplot(2,1,2);pie3(y,explode,运行结果: Ignoring non-positive data in pie chart. In pie at 41 In hc5 at 14 In pie3 at 43 In hc5 at 17有警告出现,原因是:随机数产生有负数,无法在饼图上表示。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1