刘卫国版MATLAB程序设计与应用课后实验六八九

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

实验六 高层绘图操作
%第一题:
程序代码如下:
x=linspace(0,2*pi,101);
y=(0.5+3*sin(x)./(1+x.^2)).*cos(x); plot(x,y)
01234567
-1
-0.5
0.5
1
1.5
%第二题: %(1)
程序代码如下:
x=linspace(-2*pi,2*pi,100); y1=x.^2;
y2=cos(2*x); y3=y1.*y2;
plot(x,y1,'b-',x,y2,'r:',x,y3,'y--'); text(4,16,'\leftarrow y1=x^2');
text(6*pi/4,-1,'\downarrow y2=cos(2*x)');
text(-1.5*pi,-2.25*pi*pi,'\uparrow y3=y1*y2');
-8
-6
-4
-2
2
4
6
8
-30-20
-10
10
20
30
40
%(2)
程序代码如下:
x=linspace(-2*pi,2*pi,100); y1=x.^2;
y2=cos(2*x); y3=y1.*y2;
subplot(1,3,1);%分区 plot(x,y1);
title('y1=x^2');%设置标题 subplot(1,3,2); plot(x,y2);
title('y2=cos(2*x)'); subplot(1,3,3); plot(x,y3);
title('y3=x^2*cos(2*x)');
-10
10
0510
15202530
35
40y1=x 2
-10
10
-1-0.8
-0.6
-0.4-0.200.20.4
0.6
0.8
1y2=cos(2*x)
-10
10
-30-20
-10
10
20
30
40
y3=x 2*cos(2*x)
%(3)
程序代码如下:
x=linspace(-2*pi,2*pi,20); y1=x.^2;
subplot(2,2,1);%分区 bar(x,y1);
title('y1=x^2的条形图');%设置标题 subplot(2,2,2); stairs(x,y1);
title('y1=x^2的阶梯图'); subplot(2,2,3); stem(x,y1);
title('y1=x^2的杆图'); subplot(2,2,4);
fill(x,y1,'r');%如果少了'r'则会出错 title('y1=x^2的填充图'); %其他的函数照样做。

-10
-5
05
10
0102030
40-10
-50510
010
2030
40y1=x 的阶梯图
0102030
40y1=x 2的杆图
-10
-50510
010203040y1=x 2的填充图
%第三题
程序代码如下:
x=-5:0.01:5;
y=[];%起始设y 为空向量 for x0=x
if x0<=0 %不能写成x0=<0
y=[y,(x0+sqrt(pi))/exp(2)]; %将x 对应的函数值放到y 中 else
y=[y,0.5*log(x0+sqrt(1+x0^2))]; end end
plot(x,y)
-10
-5
05
10
0102030
40-10
-50510
010
2030
40y1=x 的阶梯图
0102030
40y1=x 2的杆图
-5
05
-0.500.511.5
%第四题:
程序代码如下:
a=input('a='); b=input('b='); n=input('n=');
t=-2*pi:0.01:2*pi; r=a*sin(b+n*t); polar(t,r) a=8 b=6 n=12
90
270
%第五题
程序代码如下:
x=linspace(-5,5,21);
y=linspace(0,10,31);
[x,y]=meshgrid(x,y);%在[-5,5]*[0,10]的范围内生成网格坐标z=cos(x).*cos(y).*exp(-sqrt(x.^2+y.^2)/4);
subplot(2,1,1);
surf(x,y,z);
subplot(2,1,2);
contour3(x,y,z,50);%其中50为高度的等级数,越大越密
%第六题
程序代码如下:
ezsurf('cos(s)*cos(t)','cos(s)*sin(t)','sin(s)',[0,0.5*pi,0,1.5*p i]); %利用ezsurf隐函数
shading interp
%进行插值着色处理
0.20.40.60.8
11.2x
x = cos(s) cos(t), y = cos(s) sin(t), z = sin(s)
y
z
实验八 数据处理与多项式运算
%第一题 %(1)
程序代码如下:
A=rand(1,30000); b=mean(A) std(A,0,2) %(2) max(A) min(A) %(3) n=0;
for i=1:30000 if A(i)>0.5 n=n+1; end end
p=n/30000 b =
0.5026
ans =
0.2899
ans =
1.0000
ans =
1.5584e-005
p =
0.5044
%第二题
%(1)
程序代码如下:
A=45+51*rand(100,5);
[Y,U]=max(A)
[a,b]=min(A)
Y =
95.9123 95.6103 95.8956 95.7209 95.8496 U =
87 63 80 53 94
a =
45.6179 45.1797 45.5863 45.0149 45.1109
b =
67 8 86 78 74
%(2)
程序代码如下:
m=mean(A)
s=std(A)
m =
69.5675 68.0574 67.0498 71.7785 71.6872 s =
14.0750 14.5617 15.0046 14.9842 14.8491
%(3)
sum(A,2)
[Y,U]=max(ans)
[a,b]=min(ans)
ans =
329.5253
355.2437
361.9882
382.9321
321.6361
335.0289
322.4588
378.5933
349.8230
331.9004
429.4166
384.8956
335.0518
314.4342
347.8612
362.8625
327.3319
414.6802
384.9432 335.0784 325.4819 359.5369 344.5517 322.0939 323.0906 376.0888 364.3966 310.7507 334.6912 340.1887 335.4254 331.0611 307.5110 369.8695 367.3127 375.6964 325.8224 358.1734 297.8471 288.9244 285.8521 353.1431 346.2313 352.4237 313.1714 307.7676 352.4772 377.6382 391.4384 335.1801 373.4749 418.3996 415.3718 303.9919 314.5437 355.4934 302.5830 359.3754 373.0907 370.2539 342.8401 352.8497
425.8064 290.5902 391.0810 343.6866 341.2658 285.1690 383.5670 322.7536 290.7171 332.9745 351.3878 306.9964 374.7525 321.7565 296.2626 332.9247 351.9840 424.2966 327.2428 343.7518 374.2802 291.3005 421.8186 326.5739 405.9575 364.3370 374.2841 360.0279 289.0985 415.8491 297.5530 343.0118 394.9058 357.8329 348.0287 348.4106 344.1757 355.8473
Y =
429.4166
U =
11
a =
285.1690
b =
68
%(4)
程序代码如下:
[zcj,xsxh]=sort(ans) zcj =
285.1690
285.8521
288.9244
289.0985
290.5902
290.7171
291.3005
296.2626
297.5530
297.8471
302.5830
303.9919
306.9964
307.5110
307.7676
310.7507
313.1714
314.4342
314.5437
321.6361
321.7565
322.0939
322.7536 323.0906 325.4819 325.8224 326.5739 327.2428 327.3319 329.5253 331.0611 331.9004 332.9247 332.9745 334.6912 335.0289 335.0518 335.0784 335.1801 335.4254 340.1887 341.2658 342.8401 343.0118 343.6866 343.7518 344.1757 344.5517 346.2313 347.8612 348.0287 348.4106 349.8230 351.3878 351.9840 352.4237 352.4772 352.8497 353.1431 355.2437 355.4934 355.8473 357.8329 358.1734 359.3754
360.0279 361.9882 362.8625 364.3370 364.3966 367.3127 369.8695 370.2539 373.0907 373.4749 374.2802 374.2841 374.7525 375.6964 376.0888 377.6382 378.5933 382.9321 383.5670 384.8956 384.9432 391.0810 391.4384 394.9058 405.9575 414.6802 415.3718 415.8491 418.3996 421.8186 424.2966 425.8064 429.4166
xsxh =
68
41
40
91
64
71
77 93 39 57 54 74 33 46 28 45 14 55 5 76 24 7 70 25 21 37 86 81 17 1 32 10 78 72 29 6 13 20 50 31 30 67 61 94 66 82 99 23 43
97
98 9 73 79 44 47 62 42 2 56 100 96 38 58 22 90 3 16 88 27 35 34 60 59 51 83 89 75 36 26 48 8 4 69 12 19 65 49 95 87 18 53
52
85
80
63
11
%第三题
程序代码如下:
h=6:2:18;
x=6.5:2:17.5;
t1=[18,20,22,25,30,28,24];
t2=[15,19,24,28,34,32,30];
T1=spline(h,t1,x)
T2=spline(h,t2,x)
T1 =
18.5020 20.4986 22.5193 26.3775 30.2051 26.8178 T2 =
15.6553 20.3355 24.9089 29.6383 34.2568 30.9594
%第四题
程序代码如下:
x=1:0.1:101;
y1=log10(x);
p=polyfit(x,y1,5)
y2=polyval(p,x);
plot(x,y1,':',x,y2,'-')
%第五题
%(1)
程序代码如下:
p1=[1,2,4,0,5];
p2=[1,2];
p3=[1,2,3];
p=p1+[0,conv(p2,p3)] %为使两向量大小相同,所以补0
1 3 8 7 11
%(2)
程序代码如下:
A=roots(p)
A =
-1.3840 + 1.8317i
-1.3840 - 1.8317i
-0.1160 + 1.4400i
-0.1160 - 1.4400i
%(3)
程序代码如下:
A=[-1,1.2,-1.4;0.75,2,3.5;0,5,2.5];
polyval(p,A)
ans =
1.0e+003 *
0.0100 0.0382 0.0125
0.0223 0.0970 0.4122
0.0110 1.2460 0.1644
%(4)
程序代码如下:
polyvalm(p,A)
实验九数值微积分与方程数值求解
2,(1).
x=0:pi/100:2*pi;
y=sqrt(cos(x.^2)+4*sin(2*x).^2+1);
trapz(x,y)
g=inline('sqrt(cos(x.^2)+4*sin(2*x).^2+1)'); i=quadl(g,0,2*pi)
j=quad(g,0,2*pi)
format short
2,(2).
x=0:0.001:1;
y=log(1+x)./(1+x.^2);
trapz(x,y)
g=inline('log(1+x)./(1+x.^2)');
i=quadl(g,0,1)
j=quad(g,0,1)
format short
3, a=[6,5,-2,5;9,-1,4,-1;3,4,2,-2;3,-9,0,2];
b=[-4;13;1;11];
x1=a\b
[l,u]=lu(a);
x2=u\(l\b)
[q,r]=qr(a);
x3=r\(q\b)
format short
5,
function f=fz(x);
f=3*x+sin(x)-exp(x);
6,(1):f=inline('(x^3+cos(x)+x*log(x))/exp(x)'); fminbnd(f,0,1)
(2):function f=fxy(u)
x=u(1);
y=u(2);
f=2*x.^3+4*x.*y.^2-10*x.*y+y.^2;。

相关文档
最新文档