matlab基础实验doc.docx

上传人:b****1 文档编号:478391 上传时间:2023-04-29 格式:DOCX 页数:60 大小:629.31KB
下载 相关 举报
matlab基础实验doc.docx_第1页
第1页 / 共60页
matlab基础实验doc.docx_第2页
第2页 / 共60页
matlab基础实验doc.docx_第3页
第3页 / 共60页
matlab基础实验doc.docx_第4页
第4页 / 共60页
matlab基础实验doc.docx_第5页
第5页 / 共60页
matlab基础实验doc.docx_第6页
第6页 / 共60页
matlab基础实验doc.docx_第7页
第7页 / 共60页
matlab基础实验doc.docx_第8页
第8页 / 共60页
matlab基础实验doc.docx_第9页
第9页 / 共60页
matlab基础实验doc.docx_第10页
第10页 / 共60页
matlab基础实验doc.docx_第11页
第11页 / 共60页
matlab基础实验doc.docx_第12页
第12页 / 共60页
matlab基础实验doc.docx_第13页
第13页 / 共60页
matlab基础实验doc.docx_第14页
第14页 / 共60页
matlab基础实验doc.docx_第15页
第15页 / 共60页
matlab基础实验doc.docx_第16页
第16页 / 共60页
matlab基础实验doc.docx_第17页
第17页 / 共60页
matlab基础实验doc.docx_第18页
第18页 / 共60页
matlab基础实验doc.docx_第19页
第19页 / 共60页
matlab基础实验doc.docx_第20页
第20页 / 共60页
亲,该文档总共60页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

matlab基础实验doc.docx

《matlab基础实验doc.docx》由会员分享,可在线阅读,更多相关《matlab基础实验doc.docx(60页珍藏版)》请在冰点文库上搜索。

matlab基础实验doc.docx

matlab基础实验doc

实验一MATLAB基础知识

一、实验目的

1.熟练掌握Matlab的启动与退出;

2.熟悉Matalb的命令窗口,常用命令和帮助系统;

3.熟悉Matalb的数据类型;

4.熟悉Matlab的基本矩阵操作,运算符和字符串处理

二、实验设备

1.方正电脑

2.MATLAB软件

三、实验内容

1.已知矩阵

A=[34-11-910;65074-16;1-47-16-8;2-45-612-8;-36-78-11;8-49130]

写出完成下列操作的命令:

(1)将矩阵A的第2-5行中第1,3,5列元素赋给矩阵B;

(2)删除矩阵A的第7号元素;

(3)将矩阵A的每个元素加上30;

(4)求矩阵A的大小和维数;

(5)将矩阵A的右下角3*2矩阵构成矩阵C;

(6)输出[-5,5]范围内的所有元素;

程序:

A=[34-11-910;65074-16;1-47-16-8;2-45-612-8;-36-78-11;8-49130]

%

(1)

B=A(2:

5,[135])

%

(2)

A2=A;

A2(7)=[]

%(3)

A3=A+30

%(4)

length(A)

size(A)

%(5)

C=A(end-2:

end,end-1:

end)

%(6)

A6=A.*(A>=-5&A<=5)

结果:

A=

34-11-910

65074-16

1-47-16-8

2-45-612-8

-36-78-11

8-49130

 

B=

604

176

2512

-3-7-1

 

A2=

Columns1through7

3612-385

Columns8through14

-4-46-4-107

Columns15through21

5-7917-1-6

Columns22through28

81-94612-1

Columns29through35

310-16-8-810

 

A3=

333429312140

363530373414

312637293622

322635244222

273623382931

382639313330

 

ans=

6

 

ans=

66

 

C=

12-8

-11

30

 

A6=

34-1100

050040

1-40-100

2-45000

-3000-11

0-40130

 

2.设x=-74o,y=27o,求

的值。

程序:

x=(-74/180)*pi;

y=(27/180)*pi;

sin(x^2+y^2)/(sqrt(tan(abs(x+y)))+pi)

结果:

ans=

0.2273

3.当a取-3.0,-2.9,-2.8,…,2.8,2.9,3.0时,求

在各点的函数值。

程序:

a=[-3.0:

0.1:

3.0]

m=exp(-0.3.*a).*sin(a+0.3)

结果:

a=

Columns1through4

-3.0000-2.9000-2.8000-2.7000

Columns5through8

-2.6000-2.5000-2.4000-2.3000

Columns9through12

-2.2000-2.1000-2.0000-1.9000

Columns13through16

-1.8000-1.7000-1.6000-1.5000

Columns17through20

-1.4000-1.3000-1.2000-1.1000

Columns21through24

-1.0000-0.9000-0.8000-0.7000

Columns25through28

-0.6000-0.5000-0.4000-0.3000

Columns29through32

-0.2000-0.100000.1000

Columns33through36

0.20000.30000.40000.5000

Columns37through40

0.60000.70000.80000.9000

Columns41through44

1.00001.10001.20001.3000

Columns45through48

1.40001.50001.60001.7000

Columns49through52

1.80001.90002.00002.1000

Columns53through56

2.20002.30002.40002.5000

Columns57through60

2.60002.70002.80002.9000

Column61

3.0000

 

m=

Columns1through4

-1.0512-1.2305-1.3863-1.5184

Columns5through8

-1.6267-1.7116-1.7734-1.8129

Columns9through12

-1.8309-1.8285-1.8069-1.7675

Columns13through16

-1.7117-1.6411-1.5572-1.4617

Columns17through20

-1.3564-1.2428-1.1228-0.9978

Columns21through24

-0.8696-0.7397-0.6095-0.4804

Columns25through28

-0.3538-0.2308-0.11260.0000

Columns29through32

0.10600.20470.29550.3779

Columns33through36

0.45150.51600.57140.6174

Columns37through40

0.65430.68210.70100.7115

Columns41through44

0.71380.70850.69590.6768

Columns45through48

0.65160.62100.58560.5460

Columns49through52

0.50300.45720.40930.3597

Columns53through56

0.30930.25860.20800.1582

Columns57through60

0.10970.06280.0180-0.0245

Column61

-0.0641

4.已知

求下列表达式的值:

(1)A*B和A.*B

(2)A^3和A.^3

(3)A/B和B\A

(4)[A,B]和[A([1,3]);B^2]

程序:

A=[3542;34-457;879015];

B=[1-267;2874;930];

A*B

A.*B

A^3

A.^3

A/B

A\B

[A,B]

[A([1,3],:

);B^2]

结果;

ans=

1294324197

7-407-1052

40259112489

 

ans=

3-108134

68-360518

7832700

 

ans=

-28917240246-4368

137883-25910127669

17133325250438673

 

ans=

271574648

39304-91125343

6585037290003375

 

ans=

-5.88455.3549-0.2028

6.3554-5.65964.3293

-6.63256.20789.0241

 

ans=

0.1071-0.0667-8.7156

0.0172-0.0708-0.1894

-0.12401.011751.6870

 

ans=

35421-267

34-4572874

879015930

 

ans=

3542

879015

600183-81

684282726

156825

 

5.设a=1+2i,b=-3+4i,

的值。

程序:

a=1+2*i;

b=3+4*i;

c=exp((pi/6)*i);

c+a*b/(a+b)

结果:

ans=

1.6353+1.8462i

 

实验二MATLAB程序设计

一、实验目的

1.学会编写简单函数m文件,调用及调试函数m文件;

2.学会MATLAB的简单程序编写。

二、实验设备

1.方正电脑

2.MATLAB软件

三、实验内容

1.从键盘输入一个4位整数,按如下规则加密后输出。

加密规则:

每位数字都加上7,然后用和除以10的余数取代该数字;然后将第1位数与第3位数交换,第2位数与第4位数交换。

程序:

a=input('请输入一个四位整数:

');

a1=fix(a/1000);%千

a2=rem(fix(a/100),10);%百

a3=rem(fix(a/10),10);%十

a4=rem(a,10);%个

%加密

a1=a1+7;

a2=a2+7;

a3=a3+7;

a4=a4+7;

a1=rem(a1,10);

a2=rem(a2,10);

a3=rem(a3,10);

a4=rem(a4,10);

m=a3*1000+a4*100+a1*10+a2;

ifa3==0

disp(['输出:

','0',num2str(m)])

else

disp(['输出:

',num2str(m)])

end

结果:

请输入一个四位整数:

1234

输出:

0189

2.硅谷公司员工的工资计算方法如下:

(1)工作时数超过120h者,超过部分加发15%;

(2)工作时数低于60h者,扣发700元;

(3)其余按每小时84元计发。

试编程按输入的工号和该员工的工时数,计算应发工资。

程序:

clearall;

clc;

a=input('请输入工号:

');

b=input('请输入工时:

');

if60<=b&b<=120

m=b*84;

end

ifb<60

m=b*84-700;

end

ifb>120

m=(b-120)*84*(1+0.15)+120*84;

end

disp(['工号为',num2str(a),'的员工应发工资',num2str(m),'元'])

结果:

请输入工号:

2453

请输入工时:

24

工号为2453的员工应发工资1316元

3.根据

,求

的近似值。

当n分别取100,1000,10000时,结果是多少?

(要求:

分别用循环结构和向量运算(使用sum函数)来实现)

程序

(1):

clc;;

clearall;

n=input('输入n:

');

v=0;

fori=1:

n

v=[v,1/(i^2)];

end

m=sum(v);

disp(sqrt(6*m))%pi的近似值

结果:

输入n:

1000

3.1406

程序

(2):

clc;

clearall;

n=input('输入n:

');

v=0;

fori=1:

n

v=v+1/(i^2);

end

disp(sqrt(6*v))%pi的近似值

结果:

输入n:

1000

3.1406

4.根据

,求

(1)y<3时的最大n值;

(2)与

(1)的n值对应的y值。

考虑

程序:

clc;

clearall;

y=0;

n=0;

while(y<=3)

n=n+1;

y=y+1/(2*n-1);

end

y=y-1/(2*n-1);

n=n-1;

disp(['y<3时的最大的n=',num2str(n)]);

disp(['y=',num2str(y)]);

结果:

y<3时的最大的n=56

y=2.9944

 

5.考虑一下迭代公式

,其中,a,b为常数。

(1)编写程序求迭代结果,迭代的终止条件为

,迭代初值

,迭代次数不超过500次。

(2)如果迭代过程收敛于r,那么r的准确值是

,当(a,b)的值取(1,1)、(8,3)、(10,0.1)时,分别对迭代结果和准确值进行比较。

程序:

clc;

clearall;

a=input('请输入正数a:

');

b=input('请输入正数b:

');

n=0;%迭代次数

x=1.0;%初值

xl=1.0;

while(n<=499)

x=a/(b+x);

n=n+1;

h=abs(x-xl);

ifh<=10^(-5)

o=1;

break;

end

xl=x;

end

disp(['x=',num2str(x)]);

disp(['n=',num2str(n)]);

m=(-b+sqrt(b^2+4*a))/2

结果:

请输入正数a:

123

请输入正数b:

134

x=0.91171

n=3

m=

0.9117

实验三图形绘制

一、实验目的

1.加深认识二维、三维绘图函数plot,plot3,mesh,surf;

2.要求熟练掌握以上绘图函数的用法、简单图形标注、简单颜色设定等。

二、实验设备

1.方正电脑

2.MATLAB软件

三、实验内容

1.绘制下列曲线

(1)

程序:

x=-100:

0.01:

100;

y=x-x.^3/(3*2*1);

plot(y)

结果:

(2)

程序:

x=-10:

0.01:

10;

y=(1/2*pi)*exp(-x/2);

plot(y);

结果:

(3)

程序:

t=0:

0.01:

10*pi;

x=8*sin(t);

y=(8*cos(t))/(sqrt

(2));

plot(x,y)

结果:

(4)

程序:

t=0:

0.01:

10*pi;

x=t.*sin(t);

y=t.*cos(t);

plot(x,y)

2.已知

,完成下列操作:

(1)在同一坐标系下用不同的颜色和线形绘制两条曲线,给曲线添加文字说明;

程序:

x1=-pi/2:

0.01:

pi/2;

y1=2*x1-0.5;

t=0:

0.01:

pi;

x2=sin(3*t).*cos(t);

y2=sin(3*t).*sin(t);

plot(x1,y1,'b:

',x2,y2,'m');

text(1.0,1.5,'y=2x-0.5');

text(0.5,-0.5,'x=sin(3t)cos(t)')

text(0.5,-1,'y=sin(3t)sin(t)')

结果:

 

(2)以子图形式,分别用条形图和散点图绘制两条曲线,并为各子图添加函数标题。

程序:

subplot(2,2,[13]);

x1=-1:

0.01:

1;

y1=2*x1-0.5;

bar(x1,y1);

gridon;

title('条形图,y=2x-0.5')

subplot(2,2,4);

t=0:

0.01:

pi;

x2=sin(3*t).*cos(t);

y2=sin(3*t).*sin(t);

scatter(x2,y2);

title('散点图,x=sin(3t)cos(t),y=sin(3t)sin(t)')

gridon;

结果:

3.设

,在同一窗口采用子图的形式绘制条形图、阶梯图、杆图和对数坐标图。

程序:

t=-pi:

0.01:

pi;

y=1./(1+exp(-t));

subplot(2,2,1);

bar(t,y);

title('条形图,y=1/(1+exp(-t)),[-pi,pi]');

subplot(2,2,2);

stairs(t,y)

title('阶梯图,y=1/(1+exp(-t)),[-pi,pi]');

subplot(2,2,3);

stem(t,y);

title('杆图,y=1/(1+exp(-t)),[-pi,pi]');

subplot(2,2,4);

loglog(t,y);

title('对数坐标图,y=1/(1+exp(-t)),[-pi,pi]');

结果:

 

4.绘制下列极坐标图

(1)

程序:

theta=-10*pi:

0.01:

10*pi;

rho=5*theta+4;

polar(theta,rho);

结果:

(2)

程序:

a=1;

fai=0:

0.01:

2*pi;

r=a*(1+cos(fai));

polar(fai,r)

结果:

5.应用MATLAB三维曲线和图形绘制语句,绘制下列函数的图形:

(1)

程序:

t=0:

0.01:

2*pi;

x=exp(-t/20).*cos(t);

y=exp(-t/20).*sin(t);

z=t;

plot3(x,y,z);

gridon

(2)

程序:

x=-3:

0.01:

3;

y=-3:

0.01:

3;

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);

plot3(x,y,z);

gridon;

结果:

 

实验四线性代数中的数值运算

一、实验目的

1.通过实验能让学生加深认识冒号、逗号、分号及字母大小写在MATLAB中的区别;

2.能够对数值矩阵进行简单操作;

3.熟悉Matlab的矩阵元素运算;

4.能够熟练掌握MATLAB的数值运算功能。

二、实验设备

1.方正电脑

2.MATLAB软件

三、实验内容

1.试产生5阶帕斯卡矩阵P和5阶希尔伯特矩阵H,且求其行列式Dp,Dh以及它们的条件数Kp,Kh,判断哪个矩阵的性能更好些?

为什么?

程序:

P=pascal(5)

H=hilb(5)

Dp=det(P)

Dh=det(H)

Kp=cond(P)

Kh=cond(H)

ifabs(Kp-1)

disp('因为P矩阵的条件数比H矩阵的条件数更接近1,所以P矩阵的性能要好于H矩阵')

else

disp('因为H矩阵的条件数比P矩阵的条件数更接近1,所以H矩阵的性能要好于P矩阵')

end

结果:

P=

11111

12345

1361015

14102035

15153570

 

H=

1.00000.50000.33330.25000.2000

0.50000.33330.25000.20000.1667

0.33330.25000.20000.16670.1429

0.25000.20000.16670.14290.1250

0.20000.16670.14290.12500.1111

 

Dp=

1

 

Dh=

3.7493e-012

 

Kp=

8.5175e+003

 

Kh=

4.7661e+005

因为P矩阵的条件数比H矩阵的条件数更接近1,所以P矩阵的性能要好于H矩阵

2.求下列矩阵的主对角元素、上三角阵、下三角阵、秩、范数、条件数和迹:

(1)

(2)

程序:

a=[1-1223;0933;7-502;23683];

b=[3pi/245;32-76sqrt(37);5724.5*10^(-4);exp

(2)097];

Da=diag(a)

Aupa=triu(a)

Adowna=tril(a)

ra=rank(a)

nva=norm(a)

kaa=cond(a)

taa=trace(a)

Db=diag(b)

Aupb=triu(b)

Adownb=tril(b)

rb=rank(b)

nvb=norm(b)

kab=cond(b)

tab=trace(b)

结果:

Da=

1

9

0

3

 

Aupa=

1-1223

0933

0002

0003

 

Adowna=

1000

0900

7-500

23683

 

ra=

4

 

nva=

26.0873

 

kaa=

13.3595

 

taa=

13

 

Db=

3.0000

-76.0000

0.0005

 

Aupb=

3.00001.570845.0000

0-76.00006.0828

000.0005

000

 

Adownb=

3.000000

32.0000-76.00000

5.000072.00000.0005

7.3891097.0000

 

rb=

3

 

nvb=

109.8229

 

kab=

4.4350

 

tab=

-72.9995

3.求矩阵A的特征值和对应的特征向量,并验证其数学意义。

程序:

a=[3110;-4-10;4-8-2];

[V,D]=eig(a)

结果:

V=

00.0043-0.9811

0-0.13720.1231

1.00000.9905-0.1493

 

D=

-2.000000

0-0.87450

0030.8745

验证其数学意义:

a*V

ans=

0-0.0038-30.2907

00.12003

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2