matlab程序设计第三章课后习题答案资料

m a t l a b程序设计第三章课后习题答案
1. p138 第6题在同一坐标轴中绘制下列两条曲线并标注两曲线交叉点。

>> t=0:0.01:pi;
>> x1=t;
>> y1=2*x1-0.5;
>> x2=sin(3*t).*cos(t);
>> y2=sin(3*t).*sin(t);
>> plot(x1,y1,'r-',x2,y2,'g-')
>> axis([-1,2,-1.5,1])
>> hold on
>> s=solve('y=2*x-0.5','x=sin(3*t)*cos(t)','y=sin(3*t)*sin(t)');
>> plot(double(s.x),double(s.y),'*');
截图:
p366 第4题绘制极坐标曲线,并分析对曲线形状的影响。

function [ output_args ] = Untitled2( input_args )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
theta=0:0.01:2*pi;
a=input('请输入a的值:');
b=input('请输入b的值:');
n=input('请输入n的值:');
rho=a*sin(b+n*theta);
polar(theta,rho,'k');
end
下面以a=1,b=1,n=1的极坐标图形为基础来分析a、b、n的影响。

对a的值进行改变:对比发现a只影响半径值的整倍变化
对b的值进行改变:对比发现b的值使这个圆转换了一定的角度
对n的值进行改变:对比发现当n>=2时有如下规律
1、当n为整数时,图形变为2n个花瓣状的图形
2、当n为奇数时,图形变为n个花瓣状的图形
分别让n为2、3、4、5
同时改变b和n的值,对比发现图形变为2n个花瓣状,并且还旋转了一定角度
1 绘制sin(x)曲线,通过句柄修改曲线的颜色,要求:
a)生成曲线的同时,获取句柄,再修改颜色;
>> x=0:pi/50:2*pi;
>> y=sin(x);
>> h=plot(x,y)
h =
174.0101
>> set(h,'color','r');
截图如下:
b)先生成曲线,然后再获取句柄,再完成颜色修改。

>> x=0:pi/50:2*pi;
>> y=sin(x);
>> plot(x,y);
>> h1=plot(x,y)
h1 =
174.0095
>> set(h1,'color','r');
截图如下:
2.制作一个动画片,让一个马鞍面旋转起来。

function [ output_args ] = Untitled( input_args ) %UNTITLED Summary of this function goes here
% Detailed explanation goes here
m=-10:0.05:10;
n=-10:0.05:10;
[x,y]=meshgrid(m,n);
z=1/2.*x.^2-1/4.*y.^2;
mesh(x,y,z)
axis off;
[x,y,z]=peaks(30);
m=moviein(15);
for i=1:15
view(-37.5+24*(i-1),30);
m(:,i)=getframe;
end
movie(m)
end
动图效果如下:
matlab3_4.fig
3.根据绘制平面曲线,并分析参数a对其形状的影响,其中。

动画效果版:
>> syms a x y
>> eq=x^2/a^2+y^2/(25-a^2)-1;
>> aa=[0.5:0.5:4.5,5.5:8];
>> [m,n]=size(aa);
>> for i=1:n
eq1=subs(eq,a,aa(i));
ezplot(eq1,[-20,20]);
drawnow
axis([-20,20,-20,20]);
pause(0.5);
end
动图如下:
matlab_a.fig
普通版:
>> t=0:pi/50:2*pi;
>> i=1;
>> for a=0:0.5:4.5
x=a*cos(t);
y=sqrt(25-a.^2)*sin(t); subplot(3,3,i);
plot(x,y);
axis([-8,8,-8,8]);
i=i+1;
end
截图如下:。

合集下载

MATLAB原理及应用实验报告第三章答案

MATLAB原理及应用实验报告第三章答案

《MATLAB 原理及应用》实验报告9.课后练习题答案1.提取符号表达式222m z u ar +++的自由变量(当符号表达式中含有多余一个符号变量时,只有一个变量是独立变量,其余的符号当作常量。

如果不指定那一个变量当作是自由变量,matlab 将基于一定原则选择一个自由变量。

) 提示:findsym (s ,n )程序如下:>> syms a r u z mh=sym('a*r^2+u^2+z+m^2');>> findsym (h)ans =a, m, r, u, z 2.在MATLAB 中计算多项式2352212-+++-x x x x 的父母和分子 (提示:使用[n ,d]=numden (A ))程序如下:>> s=sym('(x^2-1)/(x+2)+(2*x+5)/(3*x-2)');[n,d]=numden(s)n =3*x^3+6*x+12d =(x+2)*(3*x-2)2.1、建立符号函数5332232-+x x (1)提取该表达式的分子和分母,并分别付给两个变量(2)对这两个变量分别进行代数运算(加减乘除及乘方)程序如下:>> s=sym('3/2*x^2+2/3*x-3/5');>> [n,d]=numden(s)n =45*x^2+20*x-18d =30>> s1=n-d;>> s2=n+d;>> s3=n*d;>> s4=n/d;>> s5=n^d;>> s=[s1;s2;s3;s4;s5]s =45*x^2+20*x-4845*x^2+20*x+121350*x^2+600*x-5403/2*x^2+2/3*x-3/5(45*x^2+20*x-18)^303.在MA TLAB 中,按照不同的方式合并表达式)()(23x e y x y x e x y y --+*-+的参数类项。

最优化方法及其matlab程序设计 马昌凤 课后答案

最优化方法及其matlab程序设计 马昌凤 课后答案

yT
Gy)
−
[
1 2
(λx)T
G(λx)
+
1 2
(1
−
λ)yT G(1
−
λ)y
+
1 2
λxT
G(1
−
λ)y
+
1 2
(1
−
λ)yT Gλx]
=
1 2
λxT
G(1
−
λ)x
+
1 2
(1
−
λ)yT
Gλy
−
1 2
λxT
G(1
−
λ)y
−
1 2
(1
−
λ)yT
Gλx
2
= =
1 21 2
λxT λ(1
G(1
−
λ)(x
0 1.1459 1.8541 3.0000
0 0.7082 1.1459 1.8541
0 0.4377 0.7082 1.1459
0.4377 0.7082 0.8754 1.1459 0.7082 0.8754 0.9787 1.1459
(6)
0.7082 0.8115 0.8754 0.9787
−
y)
+
1 2
(1
− λ)(x − y)T G(x − y)
− >
λ)yT Gλ(y − x) 0 G正定保障了严格不等式成立。
反之,必要性:严格凸函数=》Hesse矩阵G正定.
类似,当对任意x ̸= y,及任意实数λ ∈ (0, 1)都有f (λx + (1 − λ)y) < λf (x) + (1 − λ)f (y).

数字信号处理及MATLAB实现第三章答案

数字信号处理及MATLAB实现第三章答案
另设,它的N点DFT为,求得2N点DFT和的关系。 解: 3-10 x(n)为长为N有限长序列,分别为x(n)的圆周共轭偶部及奇部,也 即: 证明:
3-11设是周期为N的周期序列,通过系统H(z)以后,求证序列为 证明:
在单位圆上对H(z)N等分采样,x(n)通过系统H(z)以后,输出频谱为
3-1求序列的DFS展开 解: 已知 ,则 3-2 (1) (2)
(3) (4) (5) (6) 解:(1) (2) (3) (4)
(5) 由,得 所以 (6) 因为,所以 3-3.答案略 3-4若,,,证明 证明: 3-5若,求证 证: 而
(为整数) 0 所以 于是 3-6令表示N点序列的N点DFT,试证明: (1)如果满足关系式,则。 (2)当N为偶数时,如果,则。 证: (1) N为偶数:N奇数: 而中间的一项应当满足:
因此必然有
这就是说,当N为奇数时,也有。 (b)当N为偶数:
当N为偶数时,为奇数,故;又由于故有 3-7 已知是N点有限长序列,。现将的每两点之间补进个零值点,得到 一个点的有限长序列
试求点DFT[]与的关系。 解:由 可得 而 所以是将(周期为N)延拓次形成的,即周期为。 3-8答案略 3-9设是一个2N点序列,具有如下性质

MATLAB课后习题集附标准答案

MATLAB课后习题集附标准答案

第2章MATLAB概论1、与其他计算机语言相比较,MA TLAB语言突出的特点是什么?答:起点高、人机界面适合科技人员、强大而简易的作图功能、智能化程度高、功能丰富,可扩展性强.2、MA TLAB系统由那些部分组成?答:开发环境、MATLAB数学函数库、MATLAB语言、图形功能、应用程序接口3、安装MATLAB时,在选择组件窗口中哪些部分必须勾选,没有勾选的部分以后如何补安装?答:在安装MATLAB时,安装内容由选择组件窗口中各复选框是否被勾选来决定,可以根据自己的需要选择安装内容,但基本平台(即MATLAB选项)必须安装.第一次安装没有选择的内容在补安装时只需按照安装的过程进行,只是在选择组件时只勾选要补装的组件或工具箱即可.4、MATLAB操作桌面有几个窗口?如何使某个窗口脱离桌面成为独立窗口?又如何将脱离出去的窗口重新放置到桌面上?答:在MATLAB操作桌面上有五个窗口,在每个窗口的右下角有两个小按钮,一个是关闭窗口的Close 按钮,一个是可以使窗口称为独立的Undock按钮,点击Undock按钮就可以使该窗口脱离桌面称为独立窗口,在独立窗口的view菜单中选择Dock,菜单项就可以将独立的窗口重新防止的桌面上.5、如何启动M文件编辑/调试器?答:在操作桌面上选择“建立新文件”或“打开文件”操作时,M文件编辑/调试器将被启动.在命令窗口中键入edit命令时也可以启动M文件编辑/调试器.6、存储在工作空间中的数组能编辑吗?如何操作?答:存储在工作空间的数组可以通过数组编辑器进行编辑:在工作空间浏览器中双击要编辑的数组名打开数组编辑器,再选中要修改的数据单元,输入修改内容即可.7、命令历史窗口除了可以观察前面键入的命令外,还有什么用途?答:命令历史窗口除了用于查询以前键入的命令外,还可以直接执行命令历史窗口中选定的内容、将选定的内容拷贝到剪贴板中、将选定内容直接拷贝到M文件中.8、如何设置当前目录和搜索路径,在当前目录上的文件和在搜索路径上的文件有什么区别?答:当前目录可以在当前目录浏览器窗口左上方的输入栏中设置,搜索路径可以通过选择操作桌面的file菜单中的Set Path菜单项来完成.在没有特别说明的情况下,只有当前目录和搜索路径上的函数和文件能够被MATLAB运行和调用,如果在当前目录上有与搜索路径上相同文件名的文件时则优先执行当前目录上的文件,如果没有特别说明,数据文件将存储在当前目录上.9、在MA TLAB中有几种获得帮助的途径?答:(1)帮助浏览器:选择view菜单中的Help菜单项或选择Help菜单中的MATLAB Help菜单项可以打开帮助浏览器.(2)help命令:在命令窗口键入“help”命令可以列出帮助主题,键入“help 函数名”可以得到指定函数的在线帮助信息.(3)lookfor命令:在命令窗口键入“lookfor 关键词”可以搜索出一系列与给定关键词相关的命令和函数.(4)模糊查询:输入命令的前几个字母,然后按Tab键,就可以列出所有以这几个字母开始的命令和函数.注意:lookfor和模糊查询查到的不是详细信息,通常还需要在确定了具体函数名称后用help命令显示详细信息.第3章 MATLAB 数值运算3.1在MA TLAB 中如何建立矩阵⎥⎦⎤⎢⎣⎡194375,并将其赋予变量a ? 答:在Command Window 窗口输入操作:>> a=[5 7 3;4 9 1]3.2有几种建立矩阵的方法?各有什么优点? 答:(1)直接输入法,如a=[1 2 3 4],优点是输入方法方便简捷;(2)通过M 文件建立矩阵,该方法适用于建立尺寸较大的矩阵,并且易于修改; (3)由函数建立,如y=sin(x),可以由MATLAB 的内部函数建立一些特殊矩阵; (4)通过数据文件建立,该方法可以调用由其他软件产生数据.3.3在进行算术运算时,数组运算和矩阵运算各有什么要求?答:进行数组运算的两个数组必须有相同的尺寸.进行矩阵运算的两个矩阵必须满足矩阵运算规则,如矩阵a 与b 相乘(a*b )时必须满足a 的列数等于b 的行数.渗釤呛俨匀谔鱉调硯錦。

Matlab编程英文版(Stephen J. Chapman )课后答案3

Matlab编程英文版(Stephen J. Chapman )课后答案3

MATLAB Programming forEngineers姓名:户桂民学号:********班级:0290601日期:2008/05/11One:objectives1.Help the students to became more familiar with branching statements.2.Put what the students have learned into practice.Two :contents3.1 Conmand lines and results:% This is program evaluate tan()theta=input('Please input the \theta in degrees:');if abs(cos(theta))>= 1.0e-20m=sin(theta)/cos(theta);fprintf('tan(theta)=%8.5f\n',m);elsefprintf('Error message input!');end>> Please input the theta in degrees:3tan(theta)=-0.142553.2 .Conmand lines and results:temp=input('input a number:');if temp >103.0disp('Temperature dangerousely high');elseif temp >99.5disp('Temperature slightly high');elseif temp >=97.5disp('Temperature normal');elsedisp('Temperature below normal');end>> hu2input a number:3Temperature below normal>> hu2input a number:100Temperature slightly high3.3 Conmand lines and results:temp= input('input the weight of the package in pounds:'); if temp>100frintf('Can;t accepted(太重了)');elseif temp>70money=10+68*3.75+10;fprintf('Cost:%4.2f dollars',money);elseif temp>2money=10+(temp-2)*3.75;fprintf('Cost:%4.2f dollars',money);elsefprintf('Cost:10 dollars');end>> hu3input the weight of the package in pounds:100Cost:275.00 dollars>> hu3input the weight of the package in pounds:50Cost:190.00 dollars3.4 Conmand lines and results:x=input('input x:');y=input('input y:');if x>=0if y>=0funxy=x+y;elsefunxy=x+y^2;endelseif y>=0funxy=x^2+y;elsefunxy=x^2+y^2;endendfprintf('f(x,y)=%10.2f',funxy);>> hu4input x:5input y:6f(x,y)= 11.003.5Conmand lines and results:x=input('input x(x<1):');if x<1y=log(1/(1-x));fprintf('y(%f)=%f',x,y);elsefprintf('Error input')end>> hu5input x(x<1):0.2y(0.200000)=0.2231443.11 Conmand lines and results:r=16000;c=1.0e-6;subplot(2,1,1);f=1:2:1000;v_oi=abs(j*2*pi*r*c*f./(1+j*2*pi*f*r*c)); loglog(f,v_oi);title('Amplitude response');xlabel('frequence(HZ)');ylabel('Ouput/Input ratio');grid onsubplot(2,1,2);ff=1:2:1000;phase_oi=angle(j*2*pi*r*c*ff./(1+j*2*pi*ff*r*c)); semilogx(ff,phase_oi);title('Phase response');xlabel('frequence(HZ)');ylabel('Ouput-Input phase(rad)');grid on3.12.Conmand lines and results:k=0.5theta=0:0.1:6*pi;r=k.*theta;x=r.*cos(theta);y=r.*sin(theta);plot(x,y);grid onxlabel('X');ylabel('Y');title('The Spiral of Archimedes');Three: ExperienceWe must use MATLAB regularity.Because we may forget something if we don’t use it for a long time.。

matlab课后习题答案第三章

matlab课后习题答案第三章

第3章数值数组及其运算习题3及解答1 要求在闭区间]2,0[ 上产生具有10个等距采样点的一维数组。

试用两种不同的指令实现。

〖目的〗●数值计算中产生自变量采样点的两个常用指令的异同。

〖解答〗%方法一t1=linspace(0,2*pi,10)%方法二t2=0:2*pi/9:2*pi %要注意采样间距的选择,如这里的2*pi/9.t1 =Columns 1 through 70 0.6981 1.3963 2.0944 2.7925 3.4907 4.1888 Columns 8 through 104.88695.58516.2832t2 =Columns 1 through 70 0.6981 1.3963 2.0944 2.7925 3.4907 4.1888 Columns 8 through 104.88695.58516.28322 由指令rng('default'),A=rand(3,5)生成二维数组A,试求该数组中所有大于0.5的元素的位置,分别求出它们的“全下标”和“单下标”。

〖目的〗●数组下标的不同描述:全下标和单下标。

●sub2ind, int2str, disp的使用。

●随机发生器的状态控制:保证随机数的可复现性。

〖解答〗rng('default')A=rand(3,5)[ri,cj]=find(A>0.5);id=sub2ind(size(A),ri,cj);ri=ri';cj=cj';disp(' ')disp('大于0.5的元素的全下标')disp(['行号 ',int2str(ri)])disp(['列号 ',int2str(cj)])disp(' ')disp('大于0.5的元素的单下标')disp(id')A =0.8147 0.9134 0.2785 0.9649 0.95720.9058 0.6324 0.5469 0.1576 0.48540.1270 0.0975 0.9575 0.9706 0.8003大于0.5的元素的全下标行号 1 2 1 2 2 3 1 3 1 3列号 1 1 2 2 3 3 4 4 5 5大于0.5的元素的单下标1 2 4 5 8 9 10 12 13 153 采用默认全局随机流,写出产生长度为1000的“等概率双位(即取-1,+1)取值的随机码”程序指令,并给出 -1码的数目。

Matlab编程英文版(Stephen J. Chapman )课后答案3

MATLAB Programming forEngineers姓名:户桂民学号:********班级:0290601日期:2008/05/11One:objectives1.Help the students to became more familiar with branching statements.2.Put what the students have learned into practice.Two :contents3.1 Conmand lines and results:% This is program evaluate tan()theta=input('Please input the \theta in degrees:');if abs(cos(theta))>= 1.0e-20m=sin(theta)/cos(theta);fprintf('tan(theta)=%8.5f\n',m);elsefprintf('Error message input!');end>> Please input the theta in degrees:3tan(theta)=-0.142553.2 .Conmand lines and results:temp=input('input a number:');if temp >103.0disp('Temperature dangerousely high');elseif temp >99.5disp('Temperature slightly high');elseif temp >=97.5disp('Temperature normal');elsedisp('Temperature below normal');end>> hu2input a number:3Temperature below normal>> hu2input a number:100Temperature slightly high3.3 Conmand lines and results:temp= input('input the weight of the package in pounds:'); if temp>100frintf('Can;t accepted(太重了)');elseif temp>70money=10+68*3.75+10;fprintf('Cost:%4.2f dollars',money);elseif temp>2money=10+(temp-2)*3.75;fprintf('Cost:%4.2f dollars',money);elsefprintf('Cost:10 dollars');end>> hu3input the weight of the package in pounds:100Cost:275.00 dollars>> hu3input the weight of the package in pounds:50Cost:190.00 dollars3.4 Conmand lines and results:x=input('input x:');y=input('input y:');if x>=0if y>=0funxy=x+y;elsefunxy=x+y^2;endelseif y>=0funxy=x^2+y;elsefunxy=x^2+y^2;endendfprintf('f(x,y)=%10.2f',funxy);>> hu4input x:5input y:6f(x,y)= 11.003.5Conmand lines and results:x=input('input x(x<1):');if x<1y=log(1/(1-x));fprintf('y(%f)=%f',x,y);elsefprintf('Error input')end>> hu5input x(x<1):0.2y(0.200000)=0.2231443.11 Conmand lines and results:r=16000;c=1.0e-6;subplot(2,1,1);f=1:2:1000;v_oi=abs(j*2*pi*r*c*f./(1+j*2*pi*f*r*c)); loglog(f,v_oi);title('Amplitude response');xlabel('frequence(HZ)');ylabel('Ouput/Input ratio');grid onsubplot(2,1,2);ff=1:2:1000;phase_oi=angle(j*2*pi*r*c*ff./(1+j*2*pi*ff*r*c)); semilogx(ff,phase_oi);title('Phase response');xlabel('frequence(HZ)');ylabel('Ouput-Input phase(rad)');grid on3.12.Conmand lines and results:k=0.5theta=0:0.1:6*pi;r=k.*theta;x=r.*cos(theta);y=r.*sin(theta);plot(x,y);grid onxlabel('X');ylabel('Y');title('The Spiral of Archimedes');Three: ExperienceWe must use MATLAB regularity.Because we may forget something if we don’t use it for a long time.。

matlab第三章课后部分答案

matlab第三章课后部分答案习题三3-2 从键盘输入一个三位整数,将它反向输出。

如输入639,输出为936程序如下:m=input('请输入一个三位整数:');m1=fix(m/100);%求m的百位整数m2=rem(fix(m/10),10);%求m的十位数字m3=rem(m,10);%求m的个位数字m=m3*100+m2*10+m1%反向输出m3-3 输入一个百分制成绩,要求输出成绩等级A,B,C,D,E。

其中90~100分为A,80~89分为B,70~79分为C,60~69分为D,60分以下为E。

要求:(1)分别用if语句和switch语句实现。

(2)输入百分制成绩后要判断该成绩的合理性,对不合理的成绩应输出出错信息。

程序如下:(1)if语句c=input('请输入成绩:');if c>=90&c<=100disp('A 成绩合理');elseif c>=80&c<=89disp('B 成绩合理');elseif c>=70&c<=79disp('C 成绩合理');elseif c>=60&c<=69disp('D 成绩合理');elseif c<60disp('E 成绩合理');elsedisp('成绩错误');end(2)switch语句c=input('请输入成绩:');switch fix(c)case num2cell(90:100)disp('A 成绩合理');case num2cell(80:89)disp('B 成绩合理');case num2cell(70:79)disp('C 成绩合理');case num2cell(60:69)disp('D 成绩合理');case num2cell(0:59)disp('E 成绩合理');otherwisedisp('成绩错误');end3-4 建立5*6矩阵,要求输出矩阵第N行元素。

MATLAB程序设计教程(第二版)课后答案

MA TLAB第二版课后答案unit3-8 unit3实验指导1、 n=input('请输入一个三位数:');a=fix(n/100);b=fix((n-a*100)/10);c=n-a*100-b*10;d=c*100+b*10+a2(1)n=input('请输入成绩');switch ncase num2cell(90:100)p='A';case num2cell(80:89)p='B';case num2cell(70:79)p='C';case num2cell(60:69)p='D';otherwisep='E';endprice=p(2)n=input('请输入成绩');if n>=90&n<=100p='A';elseif n>=80&n<=89p='B';elseif n>=70&n<=79p='C';elseif n>=60&n<=69p='D';elsep='E';endprice=p(3)tryn;catchprice='erroe'end3n=[1,5,56,4,3,476,45,6,3,76,45,6,4,3,6,4,23,76,908,6];b=n(1);for m=2:20if n(m)>aa=n(m);elseif n(m)<bb=n(m);endendmax=amin=b法2n=[1,5,56,4,3,476,45,6,3,76,45,6,4,3,6,4,23,76,908,6];min=min(n)max=max(n)4b=[-3.0:0.1:3.0];for n=1:61a=b(n);y(n)=(exp(0.3*a)-exp(-0.3*a))/2*sin(a+0.3)+log((0.3+a)/2);endy5y1=0;y2=1;n=input('请输入n的值:');for i=1:ny1=y1+1/i^2;y2=y2*((4*i*i)/((2*i-1)*(2*i+1)));endy1y26A=[1,1,1,1,1,1;2,2,2,2,2,2;3,3,3,3,3,3;4,4,4,4,4,4;5,5,5,5,5,5;6,6,6,6,6,6]; n=input('请输入n的值:');if n<=5&n>=0disp(A([n],:));elseif n<0disp(lasterr);else disp(A([6],:));disp(lasterr);end7(1)f=[];f(n)=n+10*log(n^2+5);endy=f(40)/(f(30)+f(20))(2)f=[];a=0;for n=1:40f(n)=a+n*(n+1);a=f(n);endy=f(40)/(f(30)+f(20))8y=0;m=input('输入m的值:');n=input('输入n值:');for i=1:ny=y+i^m;endy************************************************************ function s=shi8_1(n,m)s=0;for i=1:ns=s+i^m;end************************************************************ shi8_1(100,1)+shi8_1(50,2)+shi8_1(10,1/2)思考练习2N=[1,2,3,4,5];2.*NN./21./N1./N.^23s=fix(100*rand(1,20)*9/10+10)y=sum(s)/20j=0;for i=1:20if s(i)<y&rem(s(i),2)==0j=j+1;A(j)=s(i);else continue;endendA4y1=0;y2=0;n=input('请输入n的值:'); for i=1:ny1=y1+-(-1)^i/(2*i-1);y2=y2+1/4^i;endy1y2unit4实验指导1(1)x=-10:0.05:10;y=x-x.^3./6;plot(x,y)(2)x=-10:0.5:10;ezplot('x^2+2*y^2-64',[-8,8]); grid on;2t=-pi:pi/10:pi;y=1./(1+exp(-t));subplot(2,2,1);bar(t,y);title('条形图(t,y)');axis([-pi,pi,0,1]);subplot(2,2,2);stairs(t,y,'b');title('阶梯图(t,y)');axis([-pi,pi,0,1]);subplot(2,2,3);stem(t,y,'k');title('杆图(t,y)');axis([-pi,pi,0,1]);subplot(2,2,4);loglog(t,y,'y');title('对数坐标图(t,y)');3(1)t=0:pi/50:2*pi;r=5.*cos(t)+4;polar(t,r);title('\rho=5*cos\theta+4'); (2)t=-pi/3:pi/50:pi/3;r=5.*((sin(t)).^2)./cos(t); polar(t,r);4(1)t=0:pi/50:2*pi;x=exp(-t./20).*cos(t);y=exp(-t./20).*sin(t);z=t;plot3(x,y,z);grid on;(2)[x,y]=meshgrid(-5:5);z=zeros(11)+5;mesh(x,y,z);shading interp;5[x,y,z]=sphere(20);surf(x,y,z);axis off;shading interp;m=moviein(20);for i=1:20axis([-i,i,-i,i,-i,i])m(:,i)=getframe;endmovie(m,4);思考练习2(1)x=-5:0.1:5;y=(1./(2*pi)).*exp((-(x.^2))/2); plot(x,y);(2)t=-2*pi:0.1:2*pi;x=t.*sin(t);y=t.*cos(t);plot(x,y);grid on;3t=0:pi/1000:pi;x=sin(3.*t).*cos(t);y1=sin(3.*t).*sin(t);y2=2.*x-0.5;plot(x,y1,'k',x,y2);hold on;k=find(abs(y1-y2)<1e-2);x1=x(k);y3=2.*x1-0.5;plot(x1,y3,'rp');4x=-2:0.01:2;y=sin(1./x);subplot(2,1,1);plot(x,y);subplot(2,1,2);fplot('sin(1./x)',[-2,2],1e-4);5(1)i=-4*pi:0.1:10;j=12./sqrt(i);polar(i,j);title('{\rho}=12/sqrt(\theta)')(2)a=-pi/6:0.01:pi/6;b=3.*asin(a).*cos(a)./((sin(a)).^3+(cos(a)).^3); polar(a,b);6(1)[u,v]=meshgrid(-4:0.1:4);x=3.*u.*sin(v);y=2.*u.*cos(v);z=4.*u.^2;subplot(2,1,1);mesh(x,y,z);subplot(2,1,2);surf(x,y,z);(2)[x,y]=meshgrid(-3:0.2:3);z=-5./(1+x.^2+y.^2);subplot(1,2,1);mesh(x,y,z);subplot(1,2,2);surf(x,y,z);unit5实验指导1A=randn(10,5)x=mean(A)y=std(A)Max=max(max(A))Min=min(min(A))Sumhang=sum(A,2)SumA=sum(Sumhang)B=sort(A);C=sort(B,2,'descend');C2(1)a=0:15:90;b=a./180.*pi;s=sin(b)c=0:15:75;d=c./180.*pi;t=tan(d)e=input('请输入想计算的值:'); S=sin(e/180*pi)T=tan(e/180*pi)S1=interp1(a,s,e,'spline')T1=interp1(c,t,e,'spline')P1=polyfit(a,s,5);P2=polyfit(c,t,5);S2=polyval(P1,e)T2=polyval(P2,e)(2)n=[1,9,16,25,36,49,64,81,100]; N=sqrt(n);x=input('ji suan zhi : ');interp1(n,N,x,'cubic')3N=64;T=5;t=linspace(0,T,N);h=exp(-t);dt=t(2)-t(1);f=1/dt;X=fft(t);F=X(1:N/2+1);f=f*(0:N/2)/N;plot(f,abs(F),'-*')4P=[2,-3,0,5,13];Q=[1,5,8];p=polyder(P)q=polyder(P,Q)[a,b]=polyder(P,Q)5P1=[1,2,4,0,5];P2=[0,1,2];P3=[1,2,3];P=P1+conv(P2,P3)X=roots(P)A=[-1,1.2,-1.4;0.75,2,3.5;0,5,2.5];p=polyval(P,A)思考练习4A=rand(1,30000);a=mean(A)b=std(A)Max=max(A)Min=min(A)n=0;for i=1:30000if(A(i)>0.5)n=n+1;endendny=n/300005p=[45,74,54,55,14;78,98,45,74,12;87,98,85,52,65][M,S]=max(p)[N,H]=min(p)junzhi=mean(p,1)fangcha=std(p,1,1)zong=sum(p,2);[Max,wei]=max(zong)[Min,wei]=min(zong)[zcj,xsxh]=sort(zong,'descend')6x=[1:10:101];y=[0,1.0414,1.3222,1.4914,1.6128,1.7076,1.7853,1.8513,1.9085,1.9590,2.0043]; [p,s]=polyfit(x,y,5)a=1:5:101;y1=polyval(p,a);plot(x,y,':o',a,y1,'-*')unit6实验指导1A=[1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6];p=[0.95,0.67,0.52]';x=A\pA=[1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6]; p=[0.95,0.67,0.53]';x=A\pcond(A)2(1)x1=fzero(@funx1,-1)function fx=funx1(x)fx=x^41+x^3+1;(2)x2=fzero(@funx2,0.5)function fx=funx2(x)fx=x-sin(x)/x;(3)options=optimset('Display','off');x=fsolve(@fun3,[1,1,1]',options)q=fun3(x)function q=fun3(p)x=p(1);y=p(2);z=p(3);q(1)=sin(x)+y^2+log(z)-7;q(2)=3*x+2^y-z^3+1;q(3)=x+y+z-5;3(1)t0=0;tf=5;y0=1;[t,y]=ode23(@fun4,[t0,tf],y0);t'y'function yp=fun4(t,y)yp=-(1.2+sin(10*t))*y;(2)t0=0;tf=5;y0=1;[t,y]=ode23(@fun5,[t0,tf],y0);t'y'function yp=fun5(t,y)yp=cos(t)-y/(1+t^2);4x=fminbnd(@mymin,0,2);-mymin(x)function fx=mymin(x)fx=-(1+x.^2)/(1+x.^4);5options=optimset('Display','off');[x,fval]=fmincon(@fun6,[0,0,0],[],[],a,b,lb,ub)-fvalfunction f=fun6(x)f=-(sqrt(x(1))+(400-x(1))*1.1+(sqrt(x(2))+(400-x(1))*1.1-x(2))*1.1+sqrt(3)+(((400-x(1))*1. 1-x(2))*1.1-x(3))*1.1+sqrt(x(x4)));思考练习1(1)A=[2,3,5;3,7,4;1,-7,1];B=[10,3,5]';C1=inv(A)*BC2=A\B[L,U]=lu(A);x=U\(L\B)(2)A=[6,5,-2,5;9,-1,4,-1;3,4,2,-2;3,-9,0,2];B=[-4,13,1,11]';C1=inv(A)*BC2=A\B[L,U]=lu(A);x=U\(L\B)2(1)x1=fzero(@funx1,1.5)function fx=funx1(x)fx=3*x+sin(x)-exp(x);(2)x1=fzero(@funx2,1)function fx=funx2(x)fx=x-1/x+5;(3)options=optimset('Display','off');x=fsolve(@fun3,[3,0]',options)q=fun3(x)function q=fun3(p)x=p(1);y=p(2);q(1)=x^2+y^2-9;q(2)=x+y-1;3(1)t0=0;tf=5;y0=[0,1];[t,y]=ode45(@vdpol,[t0,tf],y0);[t,y]function ydot=vdpol(t,y);ydot(1)=(2-3*y(2)-2*t*y(1))./(1+t^2);ydot(2)=y(1);ydot=ydot';(2)t0=0;tf=5;y0=[1;0;2];[t,y]=ode45(@vdpoll,[t0,tf],y0);[t,y]function ydot=vdpoll(t,y);ydot(1)=cos(t)-y(3)./(3+sin(t))+5*y(1).*cos(2*t)/((t+1).^2)-y(2); ydot(2)=y(1);ydot(3)=y(2);ydot=ydot';4x=fminbnd(@mymin,0,pi);-mymin(x)function fx=mymin(x)fx=-sin(x)-cos(x.^2);5[x,y1]=fminbnd(@mymax,0,1.5);-y1function fx=mymax(x);fx=-(9*x+4*x.^3-12*x.^2);unit7实验指导1(1)format longfx=inline('sin(x)./x');[I,n]=quadl(fx,0,2,1e-10)(2)format longfx=inline('1./((x-0.3).^2+0.01)-1./((x-0.9).^2+0.04)-6');[I,n]=quad(fx,0,1,1e-10)2(1)global ki;ki=0;I=dblquad(@fxy,0,1,0,1)ki(2)f=inline('abs(cos(x+y))','x','y');I=dblquad(f,0,pi,0,pi)3X=0.3:0.2:1.5;F=[0.3895,0.6598,0.9147,1.1611,1.3971,1.6212,1.8325];trapz(X,F)4p=0:pi/5:2*pi;for n=1:3nDX=diff(sin(p),n)end5f=inline('sin(x)./(x+cos(2.*x))');g=inline('(cos(x).*(x+cos(2*x))-sin(x).*(1-2.*sin(2*x)))/(x+cos(2.*x)).^2');x=-pi:0.01:pi;p=polyfit(x,f(x),5);dp=polyder(p);dpx=polyval(dp,x); %求dp在假设点的函数值dx=diff(f([x,3.01]))/0.01; %直接对f(x)求数值导数gx=g(x); %求函数f的导函数g在假设点的导数plot(x,dpx,x,dx,'.',x,gx,'-'); %作图思考练习2format longfx=inline('1./(1+x.^2)');[I,n]=quad(fx,-Inf,Inf,1e-10)[I,n]=quadl(fx,-Inf,Inf,1e-10)x=-100000:100000;y=1./(1+x.^2);trapz(x,y)format short3(1)format longfx=inline('log(1+x)./(1+x.^2)');[I,n]=quad(fx,0,1,1e-10)(2)format longfx=inline('sqrt(cos(t.^2)+4*sin((2*t).^2)+1)'); [I,n]=quad(fx,0,2*pi,1e-10)4f=inline('4.*x.*z.*exp(-z.^2.*y-x.^2)');I=triplequad(f,0,pi,0,pi,0,1)5f=inline('sin(x)');g=inline('cos(x)');x=0:0.01:2*pi;p=polyfit(x,f(x),5);dp=polyder(p);dpx=polyval(dp,x);dx=diff(f([x,2*pi+0.01]))/0.01;gx=g(x);plot(x,dpx,x,dx,'.',x,gx,'-')unit8实验指导1syms x y;s=x^4-y^4;factor(s)factor(5135)2syms x;f=(x-2)/(x^2-4);limit(f,x,2)sym x;f=(sqrt(pi)-sqrt(acos(x)))/sqrt(x+1);limit(f,x,-1,'right')3sym x;f=sin(1/x);diff(f,'x')diff(f,'x',2)sym x;f=(1-cos(2*x))/x;diff(f,'x')diff(f,'x',2)4sym x;f=sqrt(exp(x)+1);int(f,'x')syms x y;f=x/(x+y);int(f,'y')sym x;f=exp(x)*(1+exp(x))^2;int(f,'x',0,log(2))sym x;f=x*log(x);int(f,'x',1,exp(1))5sym x;s=symsum((-1)^(x+1)/x,1,Inf)sym y;z=symsum(y^(2*y-1)/(2*y-1),1,Inf)6sym x;f1=(exp(x)+exp(-x))/2;f2=sqrt(x^3-2*x+1);taylor(f1,x,5,0)taylor(f2,x,6,0)7syms x y a;x=solve('x^3+a*x+1=0','x')x=solve('sin(x)+2*cos(x)-sqrt(x)=0','x')[x y]=solve('log(x/y)=9','exp(x+y)=3','x','y')8syms n;[x,y]=dsolve('x*(D2y)+(1-n)*(Dy)+y=0','y(0)=0','Dy(0)=0','x') 思考练习2syms x B1 B2 a bs1=2*((cos(x))^2)-(sin(x))^2;s2=sin(B1)*cos(B2)-cos(B1)*sin(B2);s3=sqrt((a+sqrt(a^2-b))/2)+sqrt((a-sqrt(a^2-b))/2); s4=(4*x^2+8*x+3)/(2*x+1);h1=simplify(s1)h2=simplify(s2)h3=simplify(s3)h4=simplify(s4)3syms x a;f=abs(x)/x;limit(f,x,0,'left')f=(x+a/x)^x;limit(f,x,inf)4syms x y mf=sqrt(x+sqrt(x+sqrt(x)));m=diff(f,'x')diff(m,'x')syms x y;f=x+y-sqrt(x^2+y^2);z1=diff(f,x)z2=diff(f,y)5syms x y;f=x+y-sqrt(x^2+y^2);z1=diff(f,x)z2=diff(f,y)sym x;f=1/(asin(x)^2*(1-x^2)^(1/2));int(f)6syms xf=1/(1+x);int(f,0,4)sym x;f=x^3*sin(x)^2/(x^6+2*x^4+1);int(f,-1,1)sym x;f=x^3*sin(x)^2/(x^6+2*x^4+1);int(f,-1,1)7syms ns=symsum(1/4^n,1,inf)sym n;s=symsum(((n+1)/n)^(1/2),1,inf)eval(y)8syms xf=tan(x);taylor(f,x,3,0)syms xf=sin(x)^2;taylor(f,x,5,0)9syms xx=solve('log(1+x)-5/(1+sin(x))=2','x')syms x y z[x y z]=solve('4*x^2/(4*x^2+1)=y','4*y^2/(4*y^2+1)=z','4*z^2/(4*z^2+1)=x','x','y','z') 10[x ,y]=dsolve('Dx=3*x+4*y','Dy=5*x-7*y','x(0)=0','y(0)=1','t')。

MATLAB教程2012a第3章习题解答 张志涌

第3章 数值阵列及其运算习题3及解答1 在MATLAB 中,先运行指令A=magic(3), B=[1,2,1;3,4,3;5,6,7]生成阵列33⨯A ,33⨯B ,然后根据运行结果回答以下问题:〖目的〗● 体验矩阵乘法次序不可交换;● 体验矩阵左除、右除的不同;● 体验数组乘法次序可交换;● 体验数组左除、右除的相同性;● 体验矩阵乘法与数组乘法的根本性差别● 体验矩阵求逆的两种方法;● 体验数组“逆”概念〖解答〗A=magic(3), B=[1,2,1;3,4,3;5,6,7]%创建阵列A =8 1 63 5 74 9 2B =1 2 13 4 35 6 7(1)C1amb=A*B%相乘矩阵的次序不可交换C1bma=B*AC1amb =41 56 5353 68 6741 56 45C1bma =18 20 2248 50 5286 98 86(2)C2adb=A\B %矩阵左除和右除根本不同C2bda=B/AC2adb =0.0333 0.1000 0.16110.5333 0.6000 0.74440.0333 0.1000 -0.1722C2bda =0.0056 0.0889 0.17220.1389 0.2222 0.30560.2333 0.7333 0.2333(3)C3amb=A.*B %数组乘法不分左、右乘,因为是“元素对元素的运算”C3bma=B.*AC3amb =8 2 69 20 2120 54 14C3bma =8 2 69 20 2120 54 14(4)C4adb=A.\B %数组除法不分左、右除,因为是“元素对元素的运算”C4bda=B./AC4adb =0.1250 2.0000 0.16671.0000 0.8000 0.42861.2500 0.6667 3.5000C4bda =0.1250 2.0000 0.16671.0000 0.8000 0.42861.2500 0.6667 3.5000(5)C5ada=A\A %相当于inv(A)*A,所以得到“单位阵”C5adda=A.\A %相当于“数组逆”乘数组,得到“单位数组”C5ada =1 0 00 1 00 0 1C5adda =1 1 11 1 11 1 1(6)C6ade=A\eye(3) %矩阵求逆的代数方程法C6inv=inv(A) %直接利用求逆指令。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档