实验二Word格式文档下载.docx
《实验二Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《实验二Word格式文档下载.docx(28页珍藏版)》请在冰豆网上搜索。

相加:
d=a+[0,b]'
),pause,d=a+[0,b],pause;
相除:
[q,r]=deconv(c,a)'
),pause,[q,r]=deconv(c,a),pause;
a1=a+1'
),pause,a1=a+1,pause;
'
[q1,r1]=deconv(c,a1)'
),pause,[q1,r1]=deconv(c,a1),pause;
conv(q1,a1)+r1'
),pause,conv(q1,a1)+r1,pause;
多项式求导数:
e=polyder(c)'
),pause,e=polyder(c),pause;
多项式方程求根'
ra=roots(a),rb=roots(b);
rc=roots(c);
[[ra;
rb],rc]'
formatcompact,ra=roots(a),rb=roots(b),rc=roots(c),pause,format
多项式求值:
(polyval)'
线性间隔:
w=linspace(0,10);
),pause,w=linspace(0,10);
A=polyval(a,j*w);
plot(w,abs(A))'
h=plot(w,abs(A));
set(h,'
linewidth'
2),pause
B=polyval(b,j*w);
plot(w,abs(B))'
plot(w,abs(B)),pause
subplot(2,2,1);
plot(w,abs(B./A)),subplot(2,2,3);
plot(w,angle(B./A))'
h=plot(w,abs(B./A));
2)
subplot(2,2,3);
h=plot(w,angle(B./A));
set(h,'
对数等间隔:
w1=logspace(a,b,n)%在10^a到10^b之间按等比分为n份'
w1=logspace(-1,1)'
);
pause,w1=logspace(-1,1);
pause
F=polyval(b,j*w1)./polyval(a,j*w1);
subplot(2,2,2),loglog(w1,abs(F))'
subplot(2,2,2)
loglog(w1,abs(F),'
subplot(2,2,4);
semilogx(w1,angle(F))'
semilogx(w1,angle(F),'
曲线拟合:
原始数据:
x=0:
0.1:
1;
y=[-.447,1.978,3.28,6.16,7.08,7.34,7.66,9.56,9.48,9.30,11.2];
subplot(2,3,1),plot(x,y,'
o'
a1=polyfit(x,y,1);
xi=linspace(0,1);
y1=polyval(a1,xi);
plot(x,y,'
xi,y1,'
b'
),pause'
subplot(2,3,2),plot(x,y,'
a2=polyfit(x,y,2);
y2=polyval(a2,xi);
xi,y2,'
m'
)'
subplot(2,3,3),plot(x,y,'
r'
a3=polyfit(x,y,3);
y3=polyval(a3,xi);
xi,y3,'
subplot(2,3,4),plot(x,y,'
a9=polyfit(x,y,9);
y9=polyval(a9,xi);
xi,y9,'
subplot(2,3,5),plot(x,y,'
a10=polyfit(x,y,10);
y10=polyval(a10,xi);
xi,y10,'
subplot(2,3,6),plot(x,y,'
一维插值:
interp1(x,y,xi,'
method'
z1=interp1(x,y,xi);
xi,z1)'
subplot(1,2,1),plot(x,y,'
xi,z1),pause
z2=interp1(x,y,xi,'
spline'
xi,z2,'
subplot(1,2,2),plot(x,y,'
二维插值:
interp2(x,y,z,xi,yi,'
width=1:
5;
depth=1:
3;
temps=[8281808284;
7963616581;
8484828586];
%disp('
沿深度的中心线的温度分布:
),pause,echoon
%wi=1:
0.2:
d=2;
t1=interp2(width,depth,temps,wi,d);
pause
%t2=interp2(width,depth,temps,wi,d,'
cubic'
plot(wi,t1,'
--'
wi,t2,'
g'
沿宽度和深度二维分布:
),pause,disp('
di=1:
wi=1:
tc=interp2(width,depth,temps,wi,di'
'
subplot(1,1,1)
h=mesh(wi,di,tc),set(h,'
1.5'
h=mesh(wi,di,tc);
1.5),pause
线性微分方程的解:
脉冲响应:
a=[1,5,4,7];
b=[3,0.5,4];
[r,p,k]=residue(b,a)'
[r,p,k]=residue(b,a),pause
t=0:
10;
yi=r
(1)*exp(p
(1)*t)+r
(2)*exp(p
(2)*t)+r(3)*exp(p(3)*t);
plot(t,yi)'
subplot(1,2,1),h=plot(t,yi);
阶跃响应:
a=[1,5,4,7,0];
ys=r
(1)*exp(p
(1)*t)+r
(2)*exp(p
(2)*t)+r(3)*exp(p(3)*t)+r(4);
plot(t,ys)'
subplot(1,2,2),h=plot(t,ys);
在控制工具箱中:
yi=impulse(b,a),及ys=step(b,a)'
echooff,clf
多项式四则运算
a=[2,4,6,8],b=[3,6,9],c=conv(a,b)
a=
2468
b=
369
c=
624609610272
d=a+[0,b]
d=
271217
[q,r]=deconv(c,a)
q=
r=
000000
a1=a+1
a1=
3579
[q1,r1]=deconv(c,a1)
q1=
2.00004.66677.5556
r1=
0007.55567.11114.0000
conv(q1,a1)+r1
ans=
e=polyder(c)
e=
3096180192102
多项式方程求根
rb],rc]
ra=
-1.6506
-0.1747+1.5469i
-0.1747-1.5469i
rb=
-1.0000+1.4142i
-1.0000-1.4142i
rc=
(polyval)
plot(w,abs(A))
plot(w,abs(B))
plot(w,angle(B./A))
w1=logspace(a,b,n)%在10^a到10^b之间按等比分为n份
w1=logspace(-1,1)
subplot(2,2,2),loglog(w1,abs(F))
semilogx(w1,angle(F))
xi,z1)
1.5
[r,p,k]=residue(b,a)
3.2288
-0.1144+0.0730i
-0.1144-0.0730i
p=
-4.4548
-0.2726+1.2235i
-0.2726-1.2235i
k=
[]
plot(t,yi)
-0.7248
0.0767+0.0764i
0.0767-0.0764i
0.5714
0
plot(t,ys)
yi=impulse(b,a),及ys=step(b,a)
3:
三维绘图和屏幕控制
clf
三维曲线'
),echoon
pause,z=0:
4*pi;
x=cos(z);
y=sin(z);
plot3(x,y,z);
shg
pause,x=-8:
pause,subplot(1,2,1),plot(X,Y),
pause,subplot(1,2,2),plot(Y,X),
pause,subplot(1,1,1),R=sqrt(X.^2+Y.*Y);
z=sin(R)./R;
mesh(z)
pause,R=sqrt(X.^2+Y.*Y)+eps;
figure
(1),mesh(z)
pause,R=abs(X)+abs(Y)+eps;
z1=sin(R)./R;
figure
(2),mesh(z1)
pause,text(10,30,1.1,'
R=abs(X)+abs(Y),z=sin(R)./R'
),view(20,0),
pause,disp('
屏幕分割'
坐标设定'
pause,subplot(2,2,1),R=sqrt(X.^2+Y.*Y);
meshc(z)
pause,title('
meshc(z),shadingflat'
),shadingflat
pause,subplot(2,2,2),R=sqrt(X.^2+Y.*Y)+eps;
meshz(z)
meshz(z),shadinginterp'
),shadinginterp
pause,subplot(2,2,3),R=abs(X)+abs(Y)+eps;
surfc(z1)
surfc(z1),shadingflat'
),shadingflat,%colormap(gray)
pause,subplot(2,2,4);
surfl(z1),view(20,0)
surfl(z1),view(20,0)'
4:
直流电路的稳态计算
clear,formatcompact
R1=2;
R2=4;
R3=12;
R4=4;
R5=12;
R6=4;
R7=2;
%为给定元件赋值
%解问题
(1)
display('
解问题
(1)'
a11=R1+R2+R3;
a12=-R3;
a13=0;
%将系数矩阵各元素赋值
a21=-R3;
a22=R3+R4+R5;
a23=-R5;
a31=0;
a32=-R5;
a33=R5+R6+R7;
b1=1;
b2=0;
b3=0;
%输入解
(1)的已知条件
us=input('
us='
%列出系数矩阵A
A=[a11,a12,a13;
a21,a22,a23;
a31,a32,a33]
B=[b1;
0;
0];
I=A\B*us;
%I=[ia;
ib;
ic]
ia=I
(1);
ib=I
(2);
ic=I(3);
%解出所需变量
i3=ia-ib,u4=R4*ib,u7=R7*ic
%利用电路的线性性质及问题
(1)的解
解问题
(2)'
u42=input('
给定u42='
%由问题
(1)得出待求量与us的比例系数
k1=i3/us;
k2=u4/us;
k3=u7/us;
us2=u42/k2,i32=k1/k2*u42,u72=k3/k2*u42%按比例方法求出所需变量
解问题
(1)
us=10
A=
18-120
-1228-12
0-1218
i3=
0.3704
u4=
2.2222
u7=
0.7407
解问题
(2)
给定u42=6
us2=
27.0000
i32=
1.0000
u72=
2
5:
一阶电路开关的暂态计算
%figure
(1),fg521,pause
r1=3;
us=18;
is=3;
r2=12;
r3=6;
C=1;
%给出原始数据
%算出初值ir20及uc0
uc0=-12;
ir20=uc0/r2;
ir30=uc0/r3;
ic0=is-ir20-ir30;
%算出终值ir2f及ucf
ir2f=is*r3/(r2+r3);
ir3f=is*r2/(r2+r3);
ucf=ir2f*r2;
icf=0;
%注意时间数组的设置,在t=0及10附近设两个点
t=[-2,-1,0-eps,0+eps,1:
9,10-eps,10+eps,11:
20];
%找出时间与数组下标的关系,t=10+eps对应下标15
figure
(2),plot(t),grid,pause
%t<
0时的值
uc(1:
3)=-12;
ir2(1:
3)=3;
%求充电时常数
T=r2*r3/(r2+r3)*C;
uc(4:
14)=ucf+(uc0-ucf)*exp(-t(4:
14)/T);
%用三要素法求输出
ir2(4:
14)=ir2f+(ir20-ir2f)*exp(-t(4:
%求t=10+eps时的各初值
uc(15)=uc(14);
ir2(15)=is;
%求uc和ir2在新区间终值ucf2和ir2f
uc