东南大学Matlab作业2.docx
- 文档编号:3539739
- 上传时间:2022-11-23
- 格式:DOCX
- 页数:46
- 大小:3.58MB
东南大学Matlab作业2.docx
《东南大学Matlab作业2.docx》由会员分享,可在线阅读,更多相关《东南大学Matlab作业2.docx(46页珍藏版)》请在冰豆网上搜索。
东南大学Matlab作业2
MatlabWorksheet2
PartA(In-classroomexercises)
1.Usingplottodisplaythefollowingvoltagewithappropriatelinetype,titleandlabels.Alsopresentthegraphwithsuitablerangesofaxis.
wheref=50Hz.
(Hint:
timeintervalmustbesmallenough,e.g.0.001seconds.Therefore,t=0:
0.001:
1isappropriate);
Answer:
Home_work_2_A_1.m
%lbsin-class-exercise1_12013/8/21
%functionUsingplottodisplaythefollowingvoltagewithappropriatelinetype,titleandlabels.Alsopresentthegraphwithsuitablerangesofaxis.
%v(t)=220sin(2?
?
ft)
%wheref=50Hz.
%Comment/loop
clearall;
closeall;
t=0:
0.001:
1;
v=220*sin(2*pi*50*t);
plot(t,v,'m','LineWidth',2)
xlabel('t(sec)')
ylabel('v(voltage)')
title('v(t)=220sin(2?
?
ft)')
axis([00.2-260260]);
gridon;
2.Usingplottodisplaythefollowingvoltagewithappropriatelinetype,titleandlabels.Alsopresentthegraphwithsuitablerangesofaxis.
wheref=50Hz.
Inaddition,onthesamegraph,drawtheenvelopeoftheoscillationandaddlegends.
Answer:
home_work_2_A_2.m
%lbsin-class-exercise1_22013/8/21
%functionUsingplottodisplaythefollowingvoltagewithappropriatelinetype,titleandlabels.Alsopresentthegraphwithsuitablerangesofaxis.
%v(t)=220exp(-5t)cos(2?
?
ft)
%wheref=50Hz.
%Inaddition,onthesamegraph,drawtheenvelopeoftheoscillationandaddlegends.
%Comment/loop
clearall;
closeall;
t=0:
0.001:
1;
v=220*exp(-5*t).*sin(2*pi*50*t);
plot(t,v,'m','LineWidth',2);
xlabel('t(sec)')
ylabel('v(voltage)')
title('v(t)=220exp(-5t)cos(2?
?
ft)')
holdon;
v1=220*exp(-5*t);
plot(t,v1,'b','LineWidth',2);
holdon;
plot(t,-v1,'b','LineWidth',2);
holdoff;
legend('theoscillation','theenvelopeoftheoscillation');
axis([01-220220]);
gridon;
3.Usesubplot,drawa2by2arrayofplotsforthefollowingfunctions:
Applyappropriatelinetype,title,labelsandaxisrangesforthegraphs.
Answer:
home_work_2_A_3.m
%lbsin-class-exercise1_32013/8/21
%functionUsesubplot,drawa2by2arrayofplotsforthefollowingfunctions:
%v1=cos(10*pi*t);v2=exp(-5*t).*v1;v3=exp(-10*t).*v1;v4=exp(-20*t).*cos(10*pi*t)
%Applyappropriatelinetype,title,labelsandaxisrangesforthegraphs.
%Comment/loop
t=0:
0.001:
1;
v1=cos(10*pi*t);
v2=exp(-5*t).*v1;
v3=exp(-10*t).*v1;
v4=exp(-20*t).*cos(10*pi*t);
subplot(2,2,1)
plot(t,v1,'k','LineWidth',2)
xlabel('t(sec)')
ylabel('v(voltage)')
title('v(t)=cos(10?
?
t)');
axis([01-11])
subplot(2,2,2)
plot(t,v2,'r','LineWidth',2)
xlabel('t(sec)')
ylabel('v(voltage)')
title('v(t)=exp(-5t)cos(10?
?
t)');
axis([01-11])
subplot(2,2,3)
plot(t,v3,'g','LineWidth',2)
xlabel('t(sec)')
ylabel('v(voltage)')
title('v(t)=exp(-10t)cos(10?
?
t)');
axis([01-11])
subplot(2,2,4)
plot(t,v4,'m','LineWidth',2)
xlabel('t(sec)')
ylabel('v(voltage)')
title('v(t)=exp(-20t)cos(10?
?
t)');
axis([01-11])
4.Useplot3toplot2spiralcurveslikebelowwithappropriatelinewidthandcolour.
Answer:
(1)home_work_2_A_4_1.m
t=0:
0.01:
10;
x=sin(2*pi*t).*exp(0.35*t-1);
y=cos(2*pi*t).*exp(0.35*t-1);
z=0.25*t;
plot3(x,y,z,'g','LineWidth',2);
axis([-1515-151503]);
gridon;
(2)home_work_2_A_4_2.m
t=0:
0.01:
10;
x=1.5*t.*sin(2*pi*t);
y=1.5*t.*cos(2*pi*t);
z=0.2*t;
plot3(x,y,z,'r','LineWidth',3);
axis([-1515-151502]);
gridon;
5.Displaythesurfaceusingmeshandcontourwithasuitableresolution:
Answer:
home_work_2_A_5.m
[x,y]=meshgrid(0:
1:
100,0:
1:
100);
z=exp(-0.005.*((x-50).^2+(y-50).^2));
figure
(1);
mesh(x,y,z),xlabel('x'),ylabel('y'),gridon;
figure
(2);
contour(x,y,z),xlabel('x'),ylabel('y'),gridon;
6.Load2ofyourphotosintoMatlabWorkSpaceusingimread.a)Changebrightnesslocallyorglobally.b)Overlapthemtoproduceanewphoto.c)writeanewphotointoafileusingimwrite.(Note:
lowerversionofMatlabsuchas6.5isnotallowedtodosomedirectimageoperations.)
Answer:
a)home_work_2_A_6_a.m
clearall;
closeall;
A=imread('lbs.jpg');
figure
(1);
subplot(2,2,1);
imshow(A),title('初始图像');
size(A);
subplot(2,2,2);
B=histeq(A(:
:
1));%Enhancecontrastusinghistogramequalization.
imshow(B),title('对比度增大处理');
subplot(2,2,3);
C=imadjust(A,[0.3,0.7],[]);
imshow(C),title('亮度调节处理');
subplot(2,2,4);
D=imfilter(A,2);
imshow(D),title('真彩色增强处理');
b)home_work_2_A_6_b.m
A=imread('lbs.jpg');
B=imread('man.jpg');
[M,N,L]=size(A);
C(1:
M,1:
N,1:
L)=B(1:
M,1:
N,1:
L);
figure
(1);imshow(A);
title('figure1');
figure
(2);imshow(C);
title('figure2');
figure(3);imshow(A+C);
title('figure3');
c)home_work_2_A_6_c.m
A=imread('lbs.jpg');
B=imadjust(A,[0.2,0.6],[]);
imwrite(B,'lbs1.jpg');
imshow('lbs1.jpg');
7.Forlinearsimultaneousequations
theequationcoefficients:
A=[1-143
-545-6
07-89
-13-26];(M=N)
a)FindthedeterminantofA,
b)FindtheinverseofAandcheckformatrixsingularity,
c)IfB=[5;1;-2;3],findtheunknownxintheequation.
Answer:
home_work_2_A_7.m
A=[1-143;
-545-6;
07-89;
-13-26];
disp('a)determinantofA');
det(A)
disp('b)theinverseofAandcheckformatrixsingularity');
inv(A)
cond(A)
B=[5;1;-2;3]
disp('c)thesolutionoftheequation');
x=inv(A)*B
result:
>>home_work_2_A_7
a)determinantofA
ans=
-765.0000
b)theinverseofAandcheckformatrixsingularity
ans=
0.3333-0.00000.3333-0.6667
0.20000.11760.2706-0.3882
0.20000.05880.0353-0.0941
0.0222-0.0392-0.06800.2183
ans=
16.4186
B=
5
1
-2
3
c)thesolutionoftheequation
x=
-1.0000
-0.5882
0.7059
0.8627
8.Forlinearsimultaneousequations,
M>N,theequationcoefficients:
A=[1-143
-545-6
07-89
-13-26
1-253
147-3];
a)FindthedeterminantofA’*A,
b)FindtheinverseofA’*Aandcheckformatrixsingularity,
c)IfB=[5;1;-2;3;4;0],findthesolutionoftheequation.
Answer:
home_work_2_A_8.m
A=[1-143;
-545-6;
07-89;
-13-26;
1-253;
047-3];
disp('a)determinantofA¡¯*A');
det(A'*A)
disp('b)theinverseofA¡¯*Aandcheckformatrixsingularity');
inv(A'*A)
cond(A'*A)
B=[5;1;-2;3;4;0];
disp('c)thesolutionoftheequation');
x=inv(A'*A)*A'*B
result:
>>home_work_2_A_8
a)determinantofA’*A
ans=
2.1051e+07
b)theinverseofA’*Aandcheckformatrixsingularity
ans=
0.08840.0321-0.0013-0.0219
0.03210.02310.0002-0.0099
-0.00130.00020.00850.0053
-0.0219-0.00990.00530.0144
ans=
32.5278
c)thesolutionoftheequation
x=
-0.8903
-0.4898
0.5755
0.7083
9.Dataof10recordsareshownbelow
y=[3.54.33.75.46.67.38.78.89.49.010.012.011.39.913.3],
Usepolyfitwithdifferentorders(from1to3)ofpolynomialstofindacurveofbestfit.Checkthetotaldistancebetweenthefittedcurvezandrecordsdefinedby
.
Answer:
home_work_2_A_9.m
clearall;
closeall;
x=1:
1:
15;
y=[3.54.33.75.46.67.38.78.89.49.010.012.011.39.913.3];
plot(x,y,'ro');
holdon;
p=polyfit(x,y,1);
z=polyval(p,x);
plot(x,z,'bx');
holdon;
disp('一阶拟合误差');
s1=sqrt(sum((z-y).^2))
p=polyfit(x,y,2);
z=polyval(p,x);
plot(x,z,'kx','Linewidth',1.5);
holdon;
disp('二阶拟合误差');
s2=sqrt(sum((z-y).^2))
p=polyfit(x,y,3);
z=polyval(p,x);
plot(x,z,'r--','linewidth',2);
holdoff;
gridon;
legend('point','polyfit1','polyfit2','polyfit3');
disp('三阶拟合误差');
s3=sqrt(sum((z-y).^2))
result:
>>home_work_2_A_9
一阶拟合误差
s1=
3.2807
二阶拟合误差
s2=
3.0399
三阶拟合误差
s3=
3.0398
10.Createasetof20pointsfromacurvebyMatlabcode:
x=1:
20;y=2*exp(-0.3*(x-5).^2)+0.7*exp(-0.2*(x-12).^2);
Theninterpolatethecurveto60pointsusing‘linear’and‘spline’options,respectively.Seethequalityofdifferenttypesofinterpolation.
Answer:
home_work_2_A_10.m
clearall,closeall;
x=1:
20;
y=2*exp(-0.3*(x-5).^2)+0.7*exp(-0.2*(x-12).^2);
plot(x,y,'ro','LineWidth',2);
holdon;
xi=1:
1/3:
20;
yi=interp1(x,y,xi,'linear');
plot(xi,yi,'b*');
holdon;
yi=interp1(x,y,xi,'spline');
plot(xi,yi,'m--');
legend('point','linear','spline')
holdoff;
PartB
1.Usingtheplotandsubplotfunctionscreate4plotsona2by2arrayofsubplots,forthefunctionexp(-t)sin(5t)showingineachplotthefunctioninthecorrespondingintervalsofti.e.(-2,-1),(-1,0),(0,1)and(1,2).
Answer:
home_work_2_B_1.m
t=-2:
0.01:
-1;
v=exp(-t).*sin(5*t);
subplot(2,2,1);plot(t,v,'m','LineWidth',2);
t=-1:
0.01:
0;
subplot(2,2,2);plot(t,v,'b','LineWidth',2);
t=0:
0.01:
1;
subplot(2,2,3);plot(t,v,'r','LineWidth',2);
t=1:
0.01:
2;
subplot(2,2,4);plot(t,v,'k','LineWidth',2);
2.Athreephaseinductionmotorcharacteristicisgivenintermsofmechanicalshaftoutputtorque
(NMNewton-meter)asafunctionofrotationalspeedω(rad/sradianpersecond).Thisisapproximatedby3piece-wiselinearequationsasfollows:
Thismotorisdirectlycoupledtoaload
whichcanberepresentedas
Write2separateMatlabfunctionm-filesinwhich:
a)themotorcharacteristic,b)theloadcharacteristicaredefinedonlyasfunctionsofω.Namethemmotor.mandsysload.m,respectively.
Answer:
a)motor.m
function[Tm]=motor(w)
fori=1:
length(w);
ifw(i)>=0&w(i)<=90*pi
Tm(i)=w(i)/(90*pi)+4.0;
elseifw(i)>=90*pi&w(i)<=110*pi
Tm(i)=95*w(i)/(20*pi)-422.5;
elseif(w(i)>=110*pi&w(i)<=120*pi)
Tm(i)=-10*w(i)/pi+1200;
end
end
end
end
end
result:
>>motor(0)
ans=
4
>>w=0:
12*pi;
>>motor(w)
ans=
Columns1through10
4.00004.00354.00714.01064.01414.01774.02124.02484.02834.0318
Columns11through20
4.03544.03894.04244.04604.04954.05314.05664.06014.06374.0672
Columns21through30
4.07074.07434.07784.08134.08494.08844.0920
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 东南大学 Matlab 作业