东北大学matlab上机作业

更新时间:2023-10-05 07:53:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

《MATLAB语言与应用》上机实验作业

第一部分

1、

在matlab窗口下点击’help’弹出如下窗口,窗口左侧的列表框可以选择各种不同组合的演示内容。

2、

>> A=[1,2,3,4;4,3,2,1;2,3,4,1;3,2,4,1] A =

1 2 3 4 4 3 2 1 2 3 4 1 3 2 4 1 >>

B=[1+4j,2+3j,3+2j,4+1j;4+1j,3+2j,2+3j,1+4j;2+3j,3+2j,4+1j,1+4j;3+2j,2+3j,4+1j,1+4j] B =

1.0000 + 4.0000i 2.0000 + 3.0000i 3.0000 + 2.0000i 4.0000 + 1.0000i

4.0000 + 1.0000i 3.0000 + 2.0000i 2.0000 + 3.0000i 1.0000 + 4.0000i

2.0000 + 3.0000i 3.0000 + 2.0000i 4.0000 + 1.0000i 1.0000 + 4.0000i

3.0000 + 2.0000i 2.0000 + 3.0000i 4.0000 + 1.0000i 1.0000 + 4.0000i

>> A(5,6)=5

A =

1 2 3 4 0 0 4 3 2 1 0 0 2 3 4 1 0 0 3 2 4 0 0 0 3、

>> A=magic(8) A =

64 2 3 9 55 54 17 47 46 40 26 27 32 34 35 41 23 22 49 15 14 8 58 59

>> B=A(2:2:end,:)

1 0 0 0 61 60 12 13 20 21 37 36 29 28 44 45 52 53 5 4 0 5

6 7 51 50 43 42 30 31 38 39 19 18 11 10 62 63 57 16 24 33 25 48 56 1 B =

9 55 54 12 13 51 50 16 40 26 27 37 36 30 31 33 41 23 22 44 45 19 18 48 8 58 59 5 4 62 63 1

4、

>> sum(sym(2).^[0:63])

ans =

18446744073709551615

5、

t=[-1:0.03:-0.25,-0.249:0.007:0.249,0.25:0.4:1];y=sin(1./t);plot(t,y)

10.80.60.40.20-0.2-0.4-0.6-0.8-1-1-0.8-0.6-0.4-0.200.20.40.60.8

t=[-pi:0.05:-1.8,-1.799:0.001:-1.2,-1.2:0.005:1.2,1.201:0.001:1.8,1.81:0.05:pi];y=sin(tan(t))-tan(sin(t));plot(t,y)

3210-1-2-3-4-3-2-101234

1/2*exp(-5*t)-1/2*exp(-3*t)-1/2*t*exp(-3*t)+1/2*t^2*exp(-3*t)]

[ 1/2*t*exp(-3*t)+1/2*exp(-5*t)-1/2*exp(-3*t), 1/2*exp(-3*t)+1/2*exp(-5*t), 1/2*t*exp(-3*t), 1/2*t*exp(-3*t)+1/2*exp(-5*t)-1/2*exp(-3*t)]

[ 1/2*t*exp(-3*t)-1/2*exp(-5*t)+1/2*exp(-3*t), -1/2*exp(-5*t)+1/2*exp(-3*t), exp(-3*t)+1/2*t*exp(-3*t), 1/2*t*exp(-3*t)-1/2*exp(-5*t)+1/2*exp(-3*t)]

[ -1/2*t^2*exp(-3*t), -t*exp(-3*t),

-1/2*t^2*exp(-3*t)-t*exp(-3*t), exp(-3*t)-1/2*t^2*exp(-3*t)] C = [

-1/2*sin(5*t)+1/2*sin(3*t)*t^2-1/2*cos(3*t)*t-1/2*sin(3*t),

-1/2*sin(5*t)+cos(3*t)*t+1/2*sin(3*t), 1/2*cos(3*t)*t+1/2*sin(3*t)*t^2,

-1/2*sin(5*t)+1/2*sin(3*t)+1/2*sin(3*t)*t^2-1/2*cos(3*t)*t]

[ -1/2*sin(5*t)+1/2*cos(3*t)*t+1/2*sin(3*t), -1/2*sin(5*t)-1/2*sin(3*t), 1/2*cos(3*t)*t, -1/2*sin(5*t)+1/2*cos(3*t)*t+1/2*sin(3*t)]

[ 1/2*sin(5*t)+1/2*cos(3*t)*t-1/2*sin(3*t), 1/2*sin(5*t)-1/2*sin(3*t), -sin(3*t)+1/2*cos(3*t)*t, 1/2*sin(5*t)+1/2*cos(3*t)*t-1/2*sin(3*t)]

[ -1/2*sin(3*t)*t^2, -cos(3*t)*t,

-cos(3*t)*t-1/2*sin(3*t)*t^2, -sin(3*t)-1/2*sin(3*t)*t^2] D =

[ 1/2*exp(-5*t)*sin(25*exp(-5*t)*t)+1/2*t^2*exp(-3*t)*sin(9*t*exp(-3*t))+t*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))-1/2*exp(-3*t)*sin(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))^2+1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(2*t*exp(-3*t)-12*t^2*exp(-3*t)+9*t^3*ex

p(-3*t))-1/2*t*exp(-3*t)*sin(9*t*exp(-3*t))-1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))+1/2*exp(-3*t)*sin(9*t*exp(-3*t)

), 1/2*exp(-5*t)*sin(25*exp(-5*t)*t)+t*exp(-3*t)*sin(9*t*exp(-3*t))+exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))-1/2*exp(-3*t)

*sin(9*t*exp(-3*t)), 1/2*t*exp(-3*t)*sin(9*t*exp(-3*t))+1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))+1/2*t^2*exp(-3*t)*sin(9*t*exp(-3*t))+t*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))-1/2*exp(-3*t)*sin(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))^2+1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(2*t*exp(-3*t)-12*t^2*exp(-3*t)+9*t^3*exp(-3*t)),

1/2*exp(-5*t)*sin(25*exp(-5*t)*t)-1/2*exp(-3*t)*sin(9*t*exp(-3*t))+1/2*t^2*exp(-3*t)*sin(9*t*exp(-3*t))+t*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))-1/2*exp(-3*t)*sin(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))^2+1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(2*t*exp(-3*t)-12*t^2*exp(-3*t)+9*t^3*exp(-3*t))-1/2*t*exp(-3*t)*sin(9*t*exp(-3*t))-1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))] [

1/2*exp(-5*t)*sin(25*exp(-5*t)*t)+1/2*t*exp(-3*t)*sin(9*t*exp(-3*t))+1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))-1/2*e

xp(-3*t)*sin(9*t*exp(-3*t)),

1/2*exp(-5*t)*sin(25*exp(-5*t)*t)+1/2*exp(-3*t)*sin(9*t*exp(-3*t)), 1/2*t*exp(-3*t)*sin(9*t*exp(-3*t))+1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(-

6*t*exp(-3*t)+9*t^2*exp(-3*t)), 1/2*exp(-5*t)*sin(25*exp(-5*t)*t)+1/2*t*exp(-3*t)*sin(9*t*exp(-3*t))+1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))-1/2*exp(-3*t)*sin(9*t*exp(-3*t))]

[

-1/2*exp(-5*t)*sin(25*exp(-5*t)*t)+1/2*t*exp(-3*t)*sin(9*t*exp(-3*t))+1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))+1/2

*exp(-3*t)*sin(9*t*exp(-3*t)), -1/2*exp(-5*t)*sin(25*exp(-5*t)*t)+1/2*exp(-3*t)*sin(9*t*exp(-3*t)), exp(-3*t)*sin(9*t*exp(-3*t))+1/2*t*exp(-3*t)*sin(9*t*exp(-3*t))+1/2*ex

p(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t)), -1/2*exp(-5*t)*sin(25*exp(-5*t)*t)+1/2*t*exp(-3*t)*sin(9*t*exp(-3*t))+1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))+1/2*exp(-3*t)*sin(9*t*exp(-3*t))]

[

-1/2*t^2*exp(-3*t)*sin(9*t*exp(-3*t))-t*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))+1/2*exp(-3*t)*sin(9*t*exp(-3*t))*(-6*t

*exp(-3*t)+9*t^2*exp(-3*t))^2-1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(2*t*e

xp(-3*t)-12*t^2*exp(-3*t)+9*t^3*exp(-3*t)), -t*exp(-3*t)*sin(9*t*exp(-3*t))-exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(

-3*t)+9*t^2*exp(-3*t)), -t*exp(-3*t)*sin(9*t*exp(-3*t))-exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))-1/2*t^2*exp(-3*t)*sin(9*t*exp(-3*t))-t*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))+1/2*exp(-3*t)*sin(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))^2-1/2*exp(-3*t)*cos(

9*t*exp(-3*t))*(2*t*exp(-3*t)-12*t^2*exp(-3*t)+9*t^3*exp(-3*t)), exp(-3*t)*sin(9*t*exp(-3*t))-1/2*t^2*exp(-3*t)*sin(9*t*exp(-3*t))-t*exp(-3*t)*cos(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))+1/2*exp(-3*t)*sin(9*t*exp(-3*t))*(-6*t*exp(-3*t)+9*t^2*exp(-3*t))^2-1/2*exp(-3*t)*cos(9*t*exp(-3*t))*(2*t*exp(-3*t)-12*t^2*exp(-3*t)+9*t^3*exp(-3*t))]

第二部分

1、

(1)syms t alpha;f=sin(alpha*t)/t;F=laplace(f) F =

atan(alpha/s)

(2)syms t alpha;f=t^5*sin(alpha*t);F=laplace(f)

-1.0283

>> subs('exp(-(x+1)^2+pi/2)*sin(5*x+2)',x,x3) ans =

-5.8864e-016 >> x4=fsolve(f,4)

Optimization terminated: first-order optimality is less than options.TolFun. x4 = 4

>> subs('exp(-(x+1)^2+pi/2)*sin(5*x+2)',x,x4) ans =

-5.9134e-013

(2)>> syms x; y1=solve('(x^2+y^2+x*y)*exp(-x^2-y^2-x*y)=0','y')

y1 =

(-1/2+1/2*i*3^(1/2))*x (-1/2-1/2*i*3^(1/2))*x

>> y2=simple(subs('(x^2+y^2+x*y)*exp(-x^2-y^2-x*y)','y',y1)) y2 = 0 0

6、syms x c;y=int((exp(x)-c*x)^2,x,0,1)

y =

-1/2-2*c+1/2*exp(2)+1/3*c^2

>> x=fminsearch('exc6ff',0)

x =

3.0000

>> ezplot(y,[0,5])

-1/2-2 c+1/2 exp(2)+1/3 c232.521.510.5000.511.522.5c33.544.55

由图解法得c=3

7、function y=f1(x)

y=exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1)

function [c,ce]=f2(x); ce=[];

c=[x(1)+x(2);x(1)*x(2)-x(1)-x(2)+1.5;-10-x(1)*x(2)];

>> A=[];B=[];Aeq=[];Beq=[];xm=[-10;-10];xM=[10;10]; >> x0=(xm+xM)/2;

>> ff=optimset;ff.TolX=1e-10;ff.TolFun=1e-20; >> x=fmincon('f1',x0,A,B,Aeq,Beq,xm,xM,'f2',ff) Maximum number of function evaluations exceeded; increase OPTIONS.MaxFunEvals. x =

0.4195 0.4195 >> i=1;x=x0; >> while (1)

[x,a,b]=fmincon('f1',x,A,B,Aeq,Beq,xm,xM,'f2',ff); if b>0,break;end i=i+1; end >> x,i x =

1.1825 -1.7398 i = 5

8、

>> A=[3534,2356,1767,589,528,451,304];B=119567; intlist=ones(7,1);Aeq=[];Beq=[];

xm=zeros(7,1);xM=inf*ones(7,1);x0=zeros(7,1);

ff=optimset;ff.TolFun=1e-6;ff.TolX=1e-6;ff.TolCon=1e-20; ff.MaxSQPIter=1000;settings=[0];

ix=(intlist==1);xm(ix)=ceil(xm(ix));xM(ix)=floor(xM(ix));

[errmsg,f,x]=bnb20('f3',x0,intlist,xm,xM,A,B,Aeq,Beq,f4, settings,ff) if length(errmsg)==0,x=round(x),end x = 32 2

X3’ = x4 x4’ = x5

x5’= -x5-x2-(e-x1)-t 且x(1) = [2;-4;-2; 7; 6]T f=inline(['[x(2);

-x(1)-x(3)-(3*x(2))^2+(x(4))^3+6*x(5)+2*t; ',...

'x(4); x(5); -x(5)-x(2)-exp(-x(1))-t]'],'t','x'); [t1,x1]=ode45(f,[1,0],[2, -4, -2, 7, 6]'); [t2,x2]=ode45(f,[1,2],[2, -4, -2, 7, 6]'); t=[t1(end:-1:1); t2]; x=[x1(end:-1:1,:); x2]; plot(t,x) figure; plot(x(:,1),x(:,3))

121086420-2-4-6-800.20.40.60.811.21.41.61.82

时间曲线

86420-2-4-612345678910

相平面曲线

13、

exp(-3*u)ClockFcn1sIntegratorSubtractD2yD3y1sIntegrator1D2y1sIntegrator2Dy1sIntegrator3y1Out1exp(-5*u)*sin(4*u+pi/3)Fcn15Gain6Gain14Gain22Gain3 >> [t,x,y]=sim('yws',[0,10]);plot(t,x) >> [t,x,y]=sim('yws',[0,10]);plot(t,x)

状态变量曲线

0.250.20.150.10.050-0.05-0.1012345678910

>> figure;plot(t,y)

输出变量曲线

0.10.080.060.040.020-0.02-0.04012345678910

14、(1) t=0:0.2:2;

y=t.^2.*exp(-5*t).*sin(t); plot(t,y,'o')

0.0120.010.0080.0060.0040.002000.20.40.60.811.21.41.61.82

(2)t=0:0.2:2;

y=t.^2.*exp(-5*t).*sin(t); plot(t,y,'o') ezplot('t.^2.*exp(-5*t).*sin(t)',[0,2]); hold on x1=0:0.01:2; y1=interp1(t,y,x1,'spline'); plot(x1,y1)

x 1010-3t2 exp(-5 t) sin(t)8642000.20.40.60.81t1.21.41.61.82

本文来源:https://www.bwwdw.com/article/hkrd.html

Top