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('正弦與余弦函數(shù)')
legend('sin','cos')
hold off
?
5.
x=0:0.1:8;y=5*x.^3; ????????????????
subplot(2,2,1);plot(x,y) ?????????????????????????????
title('線性坐標(biāo)圖')
subplot(2,2,2);semilogx(x,y,'r-.') ?????????????????
title('半對數(shù)坐標(biāo)圖x')
subplot(2,2,3);semilogy(x,y,'g-') ?????????????????
title('半對數(shù)坐標(biāo)圖y')
subplot(2,2,4);loglog(x,y,'c--') ????????????????
title('雙對數(shù)坐標(biāo)圖')
?
6.
n=0:5;
y=2*n;
m=length(n);
for i=1:m
????z(i)=y(m-i+1); ?????????????%翻轉(zhuǎn)值
end
nz=-n; ???????????????????????%翻轉(zhuǎn)值的坐標(biāo)
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的翻轉(zhuǎn)值')
subplot(133),stem(ny,yd)
xlabel('n')
title('y右移2位')
?
?