MATLAB(定稿).doc_第1页
MATLAB(定稿).doc_第2页
MATLAB(定稿).doc_第3页
MATLAB(定稿).doc_第4页
MATLAB(定稿).doc_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验一练习1 使用who whos查看变量内容 a=2.5a = 2.5000 b=1 2;3 4b = 1 2 3 4 c=ac =a d=sin(a*b*pi/180)d = 0.0436 0.0872 0.1305 0.1736 e=a+ce = 99.5000 whoYour variables are:a b c d e whos Name Size Bytes Class Attributes a 1x1 8 double b 2x2 32 double c 1x1 2 char d 2x2 32 double e 1x1 8 double 2 绘制柱状图 x=1 2 3 4 5; y=sin(x)y = 0.8415 0.9093 0.1411 -0.7568 -0.9589 plot(y,DisplayName,y,YDataSource,y);figure(gcf) hist(y);figure(gcf); x=1 2 3 4 5; y=sin(x)y = 0.8415 0.9093 0.1411 -0.7568 -0.9589 hist(y);figure(gcf);自我练习x=1 3 5 7 9y=2*xplot(y)实验二 练习1使用全下标方式获取a矩阵中第二列子矩阵块a=1 2 3;4 5 6;7 8 9b=a(:,2)a = b = 1 2 3 2 4 5 6 5 7 8 9 8 2使用logspace函数创建0-4*pi行向量 有二十个元素,查看元素分布情况。 c=logspace(0,4*pi,20)c = 1.0e+12 * Columns 1 through 7 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 Columns 8 through 14 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0004 Columns 15 through 20 0.0018 0.0083 0.0382 0.1752 0.8035 3.68443 验证关系式A=1/3 0 0;0 1/4 0;0 0 1/7B=inv(A)*inv(inv(A)-eye(3)*6*AZUO=A(B*A)YOU=6*A+B*AA = 0.3333 0 0 0 0.2500 0 0 0 0.1429B = 3.0000 0 0 0 2.0000 0 0 0 1.0000ZUO = 3.0000 0 0 0 2.0000 0 0 0 1.0000YOU = 3.0000 0 0 0 2.0000 0 0 0 1.00004 將矩正的乘除运算改为数组的点除运算A=1 2 3;4 5 6;7 8 9B=1 1 1;2 2 2;3 3 3A*Bc1=A.*Bd1=A/Bd2=A./BA = B = 1 2 3 1 1 1 4 5 6 2 2 2 7 8 9 3 3 3ans = c1 = 14 14 14 1 2 3 32 32 32 8 10 12 50 50 50 21 24 27Warning: Matrix is singular to working precision. In matlabP322 at 5 d1 = NaN NaN NaN NaN NaN NaN NaN NaN Nad2 = 1.0000 2.0000 3.0000 2.0000 2.5000 3.00002.3333 2.6667 3.00005 使用数组编辑窗口查看变量a,b,c6 使用setfield命令进行上述修改 student(1)=struct(name,Rose,Id,20030102,score,95,93,84,72,88)student = name: Rose Id: 20030102 score: 95 93 84 72 88 student=setfield(student,1,score,95,73,84,72,88)student = name: Rose Id: 20030102 score: 95,73,84,72,887 使用图形和文字显示average的各元胞内容 student(1)=struct(name,John,Td,20030115,scores,85,96,74,82,68)student = name: John Td: 20030115 scores: 85 96 74 82 68 student(2)=struct(name,Rose,Td,20030102,scores,95,93,84,72,88)student = 1x2 struct array with fields: name Td scores student(3)=struct(name,Billy,Td,20030117,scores,72,83,78,80,83)student = 1x3 struct array with fields: name Td scores all_scores=cat(1,student.scores)all_scores = 85 96 74 82 68 95 93 84 72 88 72 83 78 80 83 average_scores=mean(all_scores)average_scores = 84.0000 90.6667 78.6667 78.0000 79.6667方法一 average=平均成绩,average_scoresaverage = 平均成绩 1x5 double方法二 average(1)=平均成绩average = 平均成绩 average(2)=average_scoresaverage = 平均成绩 1x5 double方法三 average1=平均成绩; average2=average_scoresaverage = 平均成绩 1x5 double自我练习1 使用LU和QR分解线性方程A=2 -3 0 2;1 5 2 1;3 -1 1 -1;4 1 2 2B=8;2;7;12X=ABL,U=lu(A)X=U(LB)Q,R=qr(A)X=R(QB)A = B = 2 -3 0 2 8 1 5 2 1 2 3 -1 1 -1 7 4 1 2 2 12X = L = 3.0000 0.5000 -0.7368 1.0000 0 0.0000 0.2500 1.0000 0 0 -1.0000 0.7500 -0.3684 0.5000 1.0000 1.0000 1.0000 0 0 0U = X = 4.0000 1.0000 2.0000 2.0000 3.0000 0 4.7500 1.5000 0.5000 0.0000 0 0 0.1053 1.3684 -1.0000 0 0 0 -3.0000 1.0000Q = -0.3651 0.5000 0.6708 0.4082 -0.1826 -0.8333 0.5217 -0.0000 -0.5477 0.1667 0.0745 -0.8165 -0.7303 -0.1667 -0.5217 0.4082R = X = -5.4772 0 -2.3735 -1.8257 3.0000 0 -6.0000 -1.8333 -0.3333 -0.0000 0 0 0.0745 0.7454 -1.0000 0 0 0 2.4495 1.0000 Untitled3A = B = 2 -3 0 2 8 1 5 2 1 2 3 -1 1 -1 7 4 1 2 2 12 X = L = 3.0000 0.5000 -0.7368 1.0000 0 0.0000 0.2500 1.0000 0 0 -1.0000 0.7500 -0.3684 0.5000 1.0000 1.0000 1.0000 0 0 0 U = X = 4.0000 1.0000 2.0000 2.0000 3.0000 0 4.7500 1.5000 0.5000 0.0000 0 0 0.1053 1.3684 -1.0000 0 0 0 -3.0000 1.0000 Q = R = -0.3651 0.5000 0.6708 0.4082 -5.4772 0 -2.3735 -1.8257 -0.1826 -0.8333 0.5217 -0.0000 0 -6.0000 -1.8333 -0.3333 -0.5477 0.1667 0.0745 -0.8165 00 0 0.0745 0.7454 -0.7303 -0.1667 -0.5217 0.4082 0 0 0 2.4495 X = 3.0000 -0.0000 -1.0000 1.00002 按表达式得出三阶,五阶拟合表达式和曲线 x=0:100; y=6 4 2 -7 10 y0=polyval(y,x); p3=polyfit(x,y0,3); p5=polyfit(x,y0,5); y3=polyval(p3,x); y5=polyval(p5,x); plot(x,y0,o) hold on plot(x,y3,r) plot(x,y5,g) 实验三练习1 用y替换x,查看结果及其数据类型 f=sym(sin(x)f =sin(x) x=0:10; y=subs(f,x)y = Columns 1 through 7 0 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794 Columns 8 through 11 0.6570 0.9894 0.4121 -0.5440 z=subs(f,y)z = Columns 1 through 7 0 0.7456 0.7891 0.1407 -0.6866 -0.8186 -0.2758 Columns 8 through 11 0.6107 0.8357 0.4006 -0.5176 2 将y1用sym函数转换为符号对象,并用d f e r四种格式表示 f=sym(sin(x) x=0:10; y=subs(f,x) whos z=subs(f,y) whos y1=sym(sin(5) y=double(y1) d=sym(y,d) f=sym(y,f) e=sym(y,e) r=sym(y,r) f =sin(x)y = Columns 1 through 7 0 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794 Columns 8 through 11 0.6570 0.9894 0.4121 -0.5440 Name Size Bytes Class Attributes A 4x4 128 double B 4x1 32 double L 4x4 128 double Q 4x4 128 double R 4x4 128 double U 4x4 128 double X 4x1 32 double f 1x1 112 sym f1 1x1 112 sym f2 1x1 112 sym f3 1x1 112 sym x 1x11 88 double y 1x11 88 double z = Columns 1 through 7 0 0.7456 0.7891 0.1407 -0.6866 -0.8186 -0.2758 Columns 8 through 11 0.6107 0.8357 0.4006 -0.5176 Name Size Bytes Class Attributes A 4x4 128 double B 4x1 32 double L 4x4 128 double Q 4x4 128 double R 4x4 128 double U 4x4 128 double X 4x1 32 double f 1x1 112 sym f1 1x1 112 sym f2 1x1 112 sym f3 1x1 112 sym x 1x11 88 double y 1x11 88 double z 1x11 88 double y1 =sin(5)y = -0.9589d =-0.95892427466313845396683746002964f =-8637222012098867/9007199254740992e =-8637222012098867/9007199254740992r =-8637222012098867/90071992547409923 使用expand collect simplify 函数进行,f=sym(x2+3*x+2)f1=simplify(f)f2=expand(f1)f3=collect(f2)f = x2 + 3*x + 2f1 = (x + 1)*(x + 2)f2 =x2 + 3*x + 2f3 =x2 + 3*x + 24 将f转换为以t为符号变量的符号表达式,f=poly2sym(1 3 2)f =x2 + 3*x + 2h=poly2sym(1 3 2,sym(t)h = t2 + 3*t + 25 对符号举证A进行求特征值,对角阵等运算A=sym(x2;2*x cos(2*t)A = x, x2 2*x, cos(2*t) diag(A)ans = x cos(2*t)6 对符号举证A求极限和积分 int(A)ans = x2/2, x3/3 x2, x*cos(2*t) limit(A)ans = 0, 0 0, cos(2*t)7 当y(0)=1,z(0)=5等,求微分方程组的解 y,z=dsolve(Dy-z=cos(x),Dz+y=1,y(0)=1,z(0)=5,x)y = (11*sin(x)/2 + (x*cos(x)/2 + 1z = 5*cos(x) - (x*sin(x)/2自我练习1 已知开环传递函数F(S)=;syms R F C sR=1/s;F=(2*s2+3*s+3)/(s+1)*(s+3)3);C=R*F;sym f;f=ilaplace(C)f = (5*exp(-3*t)/36 - exp(-t)/4 + (t*exp(-3*t)/6 + t2*exp(-3*t) + 1/92 用notebook计算,实验四 练习1 修改横坐标的刻度为“0 pi/2 2”:t1=0:0.01:2;y1=sin(2*pi*t1);plot(t1,y1)axis(0,2,-2,2)set(gca,XTick,0:pi/2:2)set(gca,XTicklabel,0,pi/2,2*pi)2 将三条曲线用不同的线性,为图形加坐标框t1=0:0.01:2;y1=exp(-t1);plot(t1,y1,r-)hold ony2=exp(-2*t1);plot(t1,y2,o);hold ony3=exp(-3*t1);plot(t1,y3,*);axis on 3 添加图形的网格并添加文字指数曲线在第一条旁边4 将坐标轴字体设置为12号粗体,蓝色5 使用area和scatter命令,绘制面积图和点图。 x=0:0.3:2*pi; y=sin(x); subplot(1,2,1) area(x,y) subplot(1,2,2) scatter(x,y)6 使用plottools窗口查看图形和变量。GUI设计:% - Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)grid on msgbox(Grid on,message)% - If Enable = on, executes on mouse press in 5 pixel border.% - Otherwise, executes on mouse press in 5 pixel border or over pushbutton1.function pushbutton1_ButtonDownFcn(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)x=0 1 1 2 2 3;y=1 1 0 0 1 1;plot(x,y)axis(0 4 0 2)msgbox(Painting square wave,message)自我练习1 在图中画出一排两个子图 分别用条形图和饼状图画成3*3魔方阵: magic(3) subplot(1,2,1) bar(ans) subplot(1,2,2)pie(ans) 2 绘制双纵坐标曲 纵坐标分别为正弦和余弦曲线 x1=0:0.1:2*pi; x2=-pi:0.1:pi;plotyy(x1,sin(x1),x2,cos(x2) 实验五练习1将该M函数文件改为M脚本文件,将数列元素个数通过键盘输入,程序该如何修改。f(1)=1;f(2)=1;%i=2;%while i50 break; else f(i+1)=f(i-1)+f(i); endend2 修改程序,使用while循环代替for循环实现本例功能function f=shiyan0501(n)%UNTITLED3 Summary of this function goes here% Detailed explanation goes here%SHIYAN0501 Fibonacci%Fibonacci%n %f Fibonacci%copyright 2003-08-01f(1)=1;f(2)=1;i=2;while i=n;f(i+1)=f(i-1)+f(i);i=i+1;end3 如果不使用子函数factorial,而直接在cal函数中计算阶乘,应如何修改程序。function k = cal(n1 )%UNTITLED6 Summary of this function goes here% Detailed explanation goes here%k%global n;for m=1:n1k=factorial(2*n1)/(2(2*n1)*(factorial(n1)2*(2*n1+1); m=1;while m a=0.1; b=0.5; f=inline(sin(t).2.*exp(.1*t)-0.5*abs(t),t)f = Inline function: f(t) = (sin(t).2.*exp(.1*t)-0.5*abs(t) x1=fminbnd(f,6,10)x1 = 9.5214自我练习1 编写函数计算苏如参数r为圆半径的圆面积和周长:function S,C=exercise(r)%UNTITLED6 Summary of this function goes here% Detailed explanation goes hereS=pi*r2;C=2*pi*r;%S,C=exercises(z);%function x,y=exercises(r)end2 创建内联函数,并绘制其曲线:function exercise2( )%UNTITLED7 Summary of this function goes here% Detailed explanation goes heret=-10:0.01:10;h_plotxy=str2func(plotxy)y=feval(h_plotxy,t);function y1=plotxy(r)y1=inline(sin(r)./r,r);plot(r,y1(r)实验六练习1 将传递函数转换为状态空间法和零极点增益描述a = -3.3333 -5.3333 -4.5000 -2.5000 -1.5000 1.0000 0 0 0 0 0 1.0000 0 0 0 0 0 1.0000 0 0 0 0 0 1.0000 0b = 1 0 0 0 0c = 0 0 0 0 0.8333d = 0z = Empty matrix: 0-by-1p = -1.0388 + 1.0728i -1.0388 - 1.0728i -1.2799 0.0122 + 0.7248i 0.0122 - 0.7248ik = 0.83332 查看所有共轭极点的阻尼系数和固有频率wn,zeta=damp(GT2)wn = 0 0.7249 0.7249 1.2799 1.3333 1.4934 1.4934zeta = -1.0000 -0.0168 -0.0168 1.0000 1.0000 0.6956 0.69563 GT1转换为状态空间法模型和零极点增益模型并查看属性a,b,c,d=tf2ss(num1,den1)get(GT1)z,p,k=tf2zp(num1,den1)get(GT1)a = -3.3333 -5.3333 -4.5000 -2.5000 -1.5000 1.0000 0 0 0 0 0 1.0000 0 0 0 0 0 1.0000 0 0 0 0 0 1.0000 0b = 1 0 0 0 0c = 0 0 0 0 0.8333d = 0 num: 0 0 0 0 0 0.8333 den: 1 3.3333 5.3333 4.5000 2.5000 1.5000 Variable: z ioDelay: 0 InputDelay: 0 OutputDelay: 0 Ts: 0.1000 TimeUnit: seconds InputName: InputUnit: InputGroup: 1x1 struct OutputName: OutputUnit: OutputGroup: 1x1 struct Name: Notes: UserData: z = Empty matrix: 0-by-1p = -1.0388 + 1.0728i -1.0388 - 1.0728i -1.2799 0.0122 + 0.7248i 0.0122 - 0.7248ik = 0.8333 num: 0 0 0 0 0 0.8333 den: 1 3.3333 5.3333 4.5000 2.5000 1.5000 Variable: z ioDelay: 0 InputDelay: 0 OutputDelay: 0 Ts: 0.1000 TimeUnit: seconds InputName: InputUnit: InputGroup: 1x1 struct OutputName: OutputUnit: OutputGroup: 1x1 struct Na

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论