资源描述
实验一
2.(2)矩阵基本运算
M文件:
A=[1 2 3;4 5 6;7 8 9]
B=[9 8 7;6 5 4;3 2 1]
D=A-B
E=A.*B
F=A*B
G=A./B
H=A/B
U=A\B
W=A.^B
运行结果:
A =
1 2 3
4 5 6
7 8 9
B =
9 8 7
6 5 4
3 2 1
D =
-8 -6 -4
-2 0 2
4 6 8
E =
9 16 21
24 25 24
21 16 9
F =
30 24 18
84 69 54
138 114 90
G =
0.1111 0.2500 0.4286
0.6667 1.0000 1.5000
2.3333 4.0000 9.0000
Warning: Matrix is singular to working precision.
> In zhenlong_1_2_2 at 7
H =
NaN NaN NaN
NaN NaN NaN
NaN -Inf Inf
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.541976e-018.
> In zhenlong_1_2_2 at 8
U =
-27 -26 -17
42 41 24
-16 -16 -8
W =
1 256 2187
4096 3125 1296
343 64 9
>>
3.(1)分别用for和while循环结构以及非循环语句编写程序,
求出
k=∑2i=1+2+22+23+…+262+263
M文件:
%for循环
k=0;
for i=0:63
k=k+2.^i;
end
k
%while循环
k=0;
i=0;
while (i<=63)
k=k+2^i;
i=i+1;
end
k
%非循环
i=0:63 ;
x=2.^i;
y=ones(length(x),1);
k=x*y
运行结果:
k =
1.8447e+019
k =
1.8447e+019
k =
1.8447e+019
>>
实验二
1.(2)表示并绘制连续时间信号波形
F(t)=cos(t/2)((t)-(t-4))
M文件:
%向量表示法
t=-2:0.01:6;
t1=0;
u1=stepfun(t,t1);
t2=4;
u2=stepfun(t,t2);
g=u1-u2;
f=cos(pi*t/2).*g;
figure(1);
plot(t,f)
axis([-2,6,-1.5,1.5])
%符号表示法
syms t;
f=sym(cos(pi*t/2)*(Heaviside(t)-Heaviside(t-4)));
figure(2);
ezplot(f,[-2,6])
运行结果:
2.(1)表示并绘制离散时间信号图像
f(k)=(-1/2)kε(k)
M文件:
k=0:1:10;
fk=(-1/2).^k;
stem(k,fk)
axis([-2,12,-1,1.2])
运行结果:
3.(4)已知波形绘制f(1/2t+1)的波形
M文件
syms t;
f=sym('2*Heaviside(t)-Heaviside(t-1)-Heaviside(t-2)');
subplot(2,1,1)
ezplot(f,[-3,3])
grid
f4=subs(f,'1/2*t+1')
subplot(2,1,2)
ezplot(f4,[-3,3])
grid
实验三:
1. 已知信号
f1(t)=ε(t+)-ε(t)
f2(t)=ε(t)-ε(t-1)
求卷积
g(t)=f1(t)*f2(t)
M文件:
t1=-1:0.01:0;
f1=ones(size(t1));
t2=0:0.01:1;
f2=ones(size(t2));
g=conv(f1,f2);
t=-1:0.01:1;
subplot(3,1,1)
plot(t1,f1)
grid
subplot(3,1,2)
plot(t2,f2)
grid
subplot(3,1,3)
plot(t,g)
grid
运行结果:
展开阅读全文