MATLAB教程 R2014a 答案 全 张志涌-matlab2014答案 下载本文

目录

第一章................................................................................................................................. 1 第二章................................................................................................................................. 5 第三章............................................................................................................................... 12 第四章............................................................................................................................... 32 第五章............................................................................................................................... 47 第六章............................................................................................................................... 54 补充题 欧拉法,龙格库塔法解方程,黑板上的题..................................................... 57

第一章

1.创建表达式

%可以用syms先符号运算再带入值 x=1; y=2;

z=(sqrt(4*x^2+1)+0.5457*exp(-0.75*x^2-3.75*y^2-1.5*x))/(2*sin(3*y)-1)

z =

-1.4345

2.计算复数

x=(-1+sqrt(-5))/4; y=x+8+10j

y =

7.7500 +10.5590i

3.help命令学三维曲线

x=-5:0.1:5; y=x;

[X,Y]=meshgrid(x,y);

Z=(sin(sqrt(X.^2+Y.^2)))./(sqrt(X.^2+Y.^2)); subplot(221); surf(X,Y,Z); colormap(cool); subplot(222);

plot3(X,Y,Z,'linewidth',4); %绘制三维曲线,也可以随意给定一个三维曲线的函数。如果画这个曲面,那么将绘出一族三维曲线 grid on;

subplot(223);

meshz(X,Y,Z); %地毯绘图 subplot(224);

meshc(X,Y,Z); %等高线绘图

4.peaks等高线(更改原函数)

subplot(221);

contour(peaks1,20); subplot(222);

contour3(peaks1,10); %可以定义等高线条数 subplot(223);

contourf(peaks1,10); subplot(224); peaks1;

z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...

- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ... - 1/3*exp(-(x+1).^2 - y.^2)

5. LOGO绘制

membrane

logo

第一章书后习题 1.合法性

不合法 合法 不合法 不合法 合法

2.运行命令及探讨

a=sqrt(2)

a =

1.4142

答:不是精确的2。是一个近似。可通过改变format进行位数显示调整。 例如:

format long; a=sqrt(2)

format short;

a =

1.414213562373095

或可使用digits任意指定输出位数。 例如:

digits(50); a=sqrt(2); vpa(a)

ans =

1.4142135623730950488016887242096980785696718753769 常见情况下毋需太高精度。

3.运行结果讨论

format long; w1=a^(2/3)

w2=a^2^(1/3) w3=(a^(1/3))^2

w1 =

1.259921049894873 w2 =

1.259921049894873 w3 =

1.259921049894873

测试结果为相同,说明MATLAB程序执行时经过的过程相同。

4.clear clf clc

clear 为从内存中清除变量和函数

clf 为清除figure中的已绘图形以及子图形 clc 为清除命令行窗口

5.产生二维数组

显然第一第二个方法可以实现。 例如:

s=[1 2 3;4 5 6;7 8 9]

s =

1 2 3 4 5 6 7 8 9

即是一个简便的键入矩阵的方法。

第二章 1 数据类型

class(3/7+0.1)

class(sym(3/7+0.1))

class(vpa(sym(3/7+0.1),4)) class(vpa(sym(3/7+0.1)))

ans = double ans = sym ans = sym ans = sym

2 哪些精准?

a1=sin(sym(pi/4)+exp(sym(0.7)+sym(pi/3)));

a2=sin(sym(pi/4)+exp(sym(0.7))*exp(sym(pi/3)));

a3=sin(sym('pi/4')+exp(sym('0.7'))*exp(sym('pi/3'))); a4=sin(sym('pi/4')+exp(sym('0.7+pi/3'))); a5=sin(sym(pi/4)+exp(sym(0.7+pi/3))); a6=sin(sym(pi/4)+sym(exp(0.7+pi/3))); a7=sin(sym(pi/4+exp(0.7+pi/3))); a8=sym(sin(pi/4+exp(0.7+pi/3)));

digits(64);