matlab
1.
clc;
clear all;
A=magic(4)
A = {magic(5),'Good luck';100,1:10}
B=[{magic(5)},{'Good luck'};{100},{1:10}]
C={10}
C(4,4)={20}
isequal(A,B)
whos
k=cell(2,2)
a(1,1)={[1 3 6;4 7 9;2 5 8]};
a(1,2)={'Hello'};
a(2,1)={(0:0.2:pi)};
a(2,2)={52};
L=[a,k]
M=[a;k]
2.
P=[1,-22,5,700];
r=roots(P)
3.
syms x
A=5*x^2-9*x-100;
solve(A)
4.
t=-pi:0.1:pi;
y=sin(t);
z=cos(t);
figure(1),plot(t,y,'Linewidth',2)
hold on
plot(t,z,'ro')
xlabel('t')
ylabel('y')
title('正弦与余弦函数')
legend('sin','cos')
hold off
5.
x=0:0.1:8;y=5*x.^3;
subplot(2,2,1);plot(x,y)
title('线性坐标图')
subplot(2,2,2);semilogx(x,y,'r-.')
title('半对数坐标图x')
subplot(2,2,3);semilogy(x,y,'g-')
title('半对数坐标图y')
subplot(2,2,4);loglog(x,y,'c--')
title('双对数坐标图')
6.
n=0:5;
y=2*n;
m=length(n);
for i=1:m
z(i)=y(m-i+1); %翻转值
end
nz=-n; %翻转值的坐标
nd=2; %y向右移动2位
nyz=1:nd;
ny=[n n(end)+nyz]; %y移位后其自变量的值
yd=[zeros(1,nd),y];
figure(1),
subplot(131),stem(n,y)
xlabel('n')
title('y')
subplot(132),stem(nz,z)
xlabel('n')
title('y的翻转值')
subplot(133),stem(ny,yd)
xlabel('n')
title('y右移2位')