薛山matlab基础教程第三版习题解答2
第2章习题参考答案
1.创建double的变量,并进行计算。
(1) a=87,b=190,计算 a+b、a-b、a*b。
(2) 创建 uint8 类型的变量,数值与(1)中相同,进行相同的计算。参考答案:
(1)
>> a=87
a =
87
>> b=190
b =
190
>> a+b
ans =
277
>> a-b
ans =
-103
>> a*b
ans =
16530
(2)
>> c=uint8(87)
c =
87
>> d=uint8(190)
d =
190
>> c+d
ans =
255
>> c-d
ans =
>> c*d
ans =
255
2.计算:
(1) ()
sin60
(2) e3
(3) 3cos 4??π ???
参考答案:
(1)
>> sind(60)
ans =
0.8660
(2)
>> exp(3)
ans =
20.0855
(3)
>> cos(3*pi/4)
ans =
-0.7071
3.设2u =,3v =,计算: (1) 4log uv v
(2) ()
22e u v v u +-
参考答案:
(1)
>> u=2;
>> v=3;
>> 4*u*v/log(v)
ans =
21.8457
(2)
>> (exp(u)+v)^2/(v^2-u)
ans =
15.4189
(3)
>> sqrt(u-3*v)/(u*v)
ans =
0 + 0.4410i
4.计算如下表达式:
(1) ()()
i i
-+
3542
(2) ()
-
sin28i
参考答案:
(1)
>> (3-5*i)*(4+2*i)
ans =
22.0000 -14.0000i
(2)
>> sin(2-8*i)
ans =
1.3553e+03 + 6.2026e+02i
5.判断下面语句的运算结果。
(1) 4 < 20
(2) 4 <= 20
(3) 4 == 20
(4) 4 ~= 20
(5) 'b'<'B'
参考答案:
(1)
>> 4<20
ans =
1
(2)
>> 4<=20
ans =
1
(3)
>> 4==20
ans =
(4)
>> 4~=20
ans =
1
(5)
>> 'b'<'B'
6.设39a =,58b =,3c =,7d =,判断下面表达式的值。
(1) a b >
(2) a c <
(3) &&a b b c >>
(4) a d ==
(5) |a b c >
(6) ~~d
参考答案:
(1)
>> a=39;
>> b=58;
>> c=3;
>> d=7;
>> a>b
ans =
(2)
>> a ans = (3) >> a>b&&b>c ans = (4) >> a==d ans = (5) >> a|b>c ans = 1 (6) >> ~~d ans = 7.编写脚本,计算上面第2题中的表达式。 脚本文件容为: disp('sin(60)='); disp(sind(60)); disp('exp(3)='); disp(exp(3)); disp('cos(3*pi/4)='); disp(cos(3*pi/4)); 8.编写脚本,输出上面第6题中的表达式的值。脚本文件容为: a=39; b=58; c=3; d=7; disp('a>b'),disp(a>b); disp('a disp('a>b&&b>c'),disp(a>b&&b>c) disp('a==d'),disp(a==d); disp('a|b>c'),disp(a|b>c); disp('~~d'),disp(~~d); 《MATLAB及应用》实验指导书《MATLAB及应用》实验指导书 班级:T1243-7 姓名:柏元强 学号:20120430724 总评成绩: 汽车工程学院 电测与汽车数字应用中心 目录 实验04051001 MATLAB语言基础 (1) 实验04051002 MATLAB科学计算及绘图 (18) 实验04051003 MATLAB综合实例编程 (31) 实验04051001 MATLAB语言基础 1实验目的 1)熟悉MATLAB的运行环境 2)掌握MATLAB的矩阵和数组的运算 3)掌握MATLAB符号表达式的创建 4)熟悉符号方程的求解 2实验内容 第二章 1.创建double的变量,并进行计算。 (1)a=87,b=190,计算 a+b、a-b、a*b。 clear,clc a=double(87); b=double(190); a+b,a-b,a*b (2)创建 uint8 类型的变量,数值与(1)中相同,进行相同的计算。 clear,clc a=uint8(87); b=uint8(190); a+b,a-b,a*b 2.计算: (1) () sin 60 (2) e3 (3) 3cos 4??π ??? clear,clc a=sind(60) b=exp(3) c=cos(3*pi/4) 3.设2u =,3v =,计算: (1) 4 log uv v (2) () 2 2 e u v v u +- (3) clear,clc u=2;v=3; a=(4*u*v)/log(v) b=((exp(u)+v)^2)/(v^2-u) c=(sqrt(u-3*v))/(u*v) 4.计算如下表达式: (1) ()() 3542i i -+ (2) () sin 28i - clear,clc (3-5*i)*(4+2*i) sin(2-8*i) 第2章习题参考答案 1.创建double的变量,并进行计算。 (1)a=87,b=190,计算a+b、a-b、a*b。 (2) 创建uint8 类型的变量,数值与(1)中相同,进行相同的计算。参考答案: (1) >> a=87 a = 87 >> b=190 b = 190 >> a+b ans = 277 >> a-b ans = -103 >> a*b ans = 16530 (2) >> c=uint8(87) c = 87 >> d=uint8(190) d = 190 >> c+d ans = 255 >> c-d ans = >> c*d ans = 255 2.计算: (1) () sin60o (2) e3 (3) 3cos 4??π ??? 参考答案: (1) >> sind(60) ans = 0.8660 (2) >> exp(3) ans = 20.0855 (3) >> cos(3*pi/4) ans = -0.7071 3.设2u =,3v =,计算: (1) 4log uv v (2) ()22e u v v u +- (3) 参考答案: (1) >> u=2; >> v=3; >> 4*u*v/log(v) ans = 21.8457 (2) >> (exp(u)+v)^2/(v^2-u) ans = 15.4189 (3) >> sqrt(u-3*v)/(u*v) ans = 0 + 0.4410i 4.计算如下表达式: (1) ()() i i -+ 3542 (2) () - sin28i 参考答案: (1) >> (3-5*i)*(4+2*i) ans = 22.0000 -14.0000i (2) >> sin(2-8*i) ans = 1.3553e+03 + 6.2026e+02i 5.判断下面语句的运算结果。 (1)4 < 20 (2)4 <= 20 (3)4 == 20 (4)4 ~= 20 (5)'b'<'B' 参考答案: (1) >> 4<20 ans = 1 (2) >> 4<=20 ans = 1 (3) >> 4==20 ans = (4) >> 4~=20 ans = 1 (5) >> 'b'<'B' 1-1、基本运算与函数 在MATLAB下进行基本数学运算,只需将运算式直接打入提示号(>>)之後,并按入Enter键即可。例如: >> (5*2+1.3-0.8)*10/25 ans =4.2000 MATLAB会将运算结果直接存入一变数ans,代表MATLAB运算後的答案(Answer)并显示其数值於萤幕上。 小提示: ">>"是MATLAB的提示符号(Prompt),但在PC中文视窗系统下,由於编码方式不同,此提示符号常会消失不见,但这并不会影响到MATLAB的运算结果。 我们也可将上述运算式的结果设定给另一个变数x: x = (5*2+1.3-0.8)*10^2/25 x = 42 此时MATLAB会直接显示x的值。由上例可知,MATLAB认识所有一般常用到的加(+)、减(-)、乘(*)、除(/)的数学运算符号,以及幂次运算(^)。 小提示: MATLAB将所有变数均存成double的形式,所以不需经过变数宣告(Variable declaration)。MATLAB同时也会自动进行记忆体的使用和回收,而不必像C语言,必须由使用者一一指定.这些功能使的MATLAB易学易用,使用者可专心致力於撰写程式,而不必被软体枝节问题所干扰。 若不想让MATLAB每次都显示运算结果,只需在运算式最後加上分号(;)即可,如下例: y = sin(10)*exp(-0.3*4^2); 若要显示变数y的值,直接键入y即可: >>y y =-0.0045 在上例中,sin是正弦函数,exp是指数函数,这些都是MATLAB常用到的数学函数。 下表即为MATLAB常用的基本数学函数及三角函数: 小整理:MATLAB常用的基本数学函数 abs(x):纯量的绝对值或向量的长度 angle(z):复数z的相角(Phase angle) sqrt(x):开平方 real(z):复数z的实部 imag(z):复数z的虚部 conj(z):复数z的共轭复数 round(x):四舍五入至最近整数 fix(x):无论正负,舍去小数至最近整数 floor(x):地板函数,即舍去正小数至最近整数 ceil(x):天花板函数,即加入正小数至最近整数 rat(x):将实数x化为分数表示 rats(x):将实数x化为多项分数展开 Matlab入门教程--环境设置 1-5、搜寻路径 在前一节中,test.m所在的目录是d:\mlbook。如果不先进入这个目录,MATLAB就找不到你要执行的M档案。如果希望MATLAB不论在何处都能执行test.m,那麽就必须将d:\mlbook加入MATLAB的搜寻路径(Search path)上。要检视MATLAB的搜寻路径,键入path即可: path MATLABPATH d:\matlab5\toolbox\matlab\general d:\matlab5\toolbox\matlab\ops d:\matlab5\toolbox\matlab\lang d:\matlab5\toolbox\matlab\elmat d:\matlab5\toolbox\matlab\elfun d:\matlab5\toolbox\matlab\specfun d:\matlab5\toolbox\matlab\matfun d:\matlab5\toolbox\matlab\datafun d:\matlab5\toolbox\matlab\polyfun d:\matlab5\toolbox\matlab\funfun d:\matlab5\toolbox\matlab\sparfun d:\matlab5\toolbox\matlab\graph2d d:\matlab5\toolbox\matlab\graph3d d:\matlab5\toolbox\matlab\specgraph d:\matlab5\toolbox\matlab\graphics d:\matlab5\toolbox\matlab\uitools d:\matlab5\toolbox\matlab\strfun d:\matlab5\toolbox\matlab\iofun d:\matlab5\toolbox\matlab\timefun d:\matlab5\toolbox\matlab\datatypes d:\matlab5\toolbox\matlab\dde d:\matlab5\toolbox\matlab\demos d:\matlab5\toolbox\tour d:\matlab5\toolbox\simulink\simulink d:\matlab5\toolbox\simulink\blocks d:\matlab5\toolbox\simulink\simdemos d:\matlab5\toolbox\simulink\dee d:\matlab5\toolbox\local 此搜寻路径会依已安装的工具箱(Toolboxes)不同而有所不同。要查询某 一命令是在搜寻路径的何处,可用which命令: which expo d:\matlab5\toolbox\matlab\demos\expo.m 很显然c:\data\mlbook并不在MATLAB的搜寻路径中,因此MATLAB找不到test.m这个M档案: which test c:\data\mlbook\test.m 要将d:\mlbook加入MATLAB的搜寻路径,还是使用path命令: path(path, 'c:\data\mlbook'); 此时d:\mlbook已加入MATLAB搜寻路径(键入path试看看),因此MATLAB已经"看"得到test.m: 第三章习题及参考答案 解答: >> p=[1 -1 -1]; >> roots(p) ans = -0.6180 1.6180 解答: 取n=5,m=61 >> x=linspace(0,2*pi,5); y=sin(x); >> xi=linspace(0,2*pi,61); >> y0=sin(xi); >> y1=interp1(x,y,xi); >> y2=interp1(x,y,xi,'spline'); >> plot(xi,y0,'o',xi,y1,xi,y2,'-.'); >> subplot(2,1,1); plot(xi,y1-y0);grid on >> subplot(2,1,2); plot(xi,y2-y0);grid on 分段线性和三次样条插值方法与精确值之差取n=11,m=61 >> x=linspace(0,2*pi,11); y=sin(x); >> xi=linspace(0,2*pi,61); >> y0=sin(xi); >> y1=interp1(x,y,xi); >> y2=interp1(x,y,xi,'spline'); >> plot(xi,y0,'o',xi,y1,xi,y2,'-.'); >> subplot(2,1,1); plot(xi,y1-y0);grid on >> subplot(2,1,2); plot(xi,y2-y0);grid on 分段线性和三次样条插值方法与精确值之差 解答: >> x=[0,300,600,1000,1500,2000]; >> y=[0.9689,0.9322,0.8969,0.8519,0.7989,0.7491]; >> xi=0:100:2000; >> y0=1.0332*exp(-(xi+500)/7756); >> y1=interp1(x,y,xi,'spline'); >> p3=polyfit(x,y,3); >> y3=polyval(p3,xi); >> subplot(2,1,1);plot(xi,y0,'o',xi,y1,xi,y3,'-.'); >> subplot(2,1,2);plot(xi,y1-y0,xi,y3-y0);grid on 插值和拟合方法相比较,都合理,误差也相近。 解答: 梯形法积分 >> x=-3:0.01:3;MATLAB基础教程 薛山第二版 课后习题答案
薛山matlab基础教程第三版习题解答2
Matlab基础教程
Matlab入门教程3
MATLAB基础及其应用教程-周开利-邓春晖课后答案