實(shí)驗(yàn)一 MATLAB運(yùn)算基礎(chǔ)
%第一題
%(1)
z1=2*sin(85*pi/180)/(1+exp(2))
%(2)
x=[2,1+2i;-0.45,5];
z2=0.5*log(x+sqrt(1+x.^2))
%(3)
a=-3.0:0.1:3.0;
z3=(exp(0.3*a)-exp(-0.3*a))/2.*sin(a+0.3)+log((0.3+a)/2)
%(4)
t=0:0.5:2.5;
z4=t.^2.*(t>=0&t<1)+(t.^2-1).*(t>=1&t<2)+(t.^2-2*t+1).*(t>=2&t<3)
%第二題
A=[12?34?-4;34?7?87;3?65?7];
B=[1?3?-1;2?0?3;3?-2?7];
A+6*B
A-B+eye(size(A))
A*B
A.*B
A^3
A.^3
A/B
B\A
[A,B]
[A([1,3],:);B^2]
%第三題
A=[1?2?3?4?5;6?7?8?9?10;11?12?13?14?15;16?17?18?19?20;21?22?23?24?25]
B=[3?0?16;17?-6?9;0?23?-4;9?7?0;4?13?11]
C=A*B
F=size(C)
D=C(F(1)-2:F(1),F(2)-1:F(2))
whos
%第四題
%(1):
A=100:999;
B=rem(A,21);
C=length(find(B==0))
%(2):
A='lsdhKSDLKklsdkl';
k=find(A>='A'&A<='Z');
A(k)=[]
實(shí)驗(yàn)二 MATLAB矩陣分析與處理
第一題
E=eye(3);
R=rand(3,2);
O=zeros(2,3);
S=diag([2,3]);
A=[E,R;O,S];
A^2
B=[E,(R+R*S);O,S^2]
第二題
H=hilb(5)
P=pascal(5)
Hh=det(H)
Hp=det(P)
Th=cond(H)
Tp=cond(P)
%第三題:
A=fix(10*rand(5))
H=det(A)
Trace=trace(A)
Rank=rank(A)
Norm=norm(A)
%第四題:
A=[-29,6,18;20,5,12;-8,8,5]
[V,D]=eig(A)
%數(shù)學(xué)意義略
%第五題方法一:
%(1):
A=[1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6];
b=[0.95,0.67,0.52]';
x=inv(A)*b
(2):
B=[0.95,0.67,0.53]';
x=inv(A)*B
%(3):
cond(A)
%第五題方法二:
A=hilb(4)
A(:,1)=[]
A(4,:)=[]
B=[0.95,0.67,0.52]';
X=inv(A)*B
B1=[0.95,0.67,0.53]';
X1=inv(A)*B1
N=cond(B)
N1=cond(B1)
Na=cond(A)??%矩陣A為病態(tài)矩陣
%第六題
A=[1,4,9;16,25,36;49,64,81]
B=sqrtm(A)
C=sqrt(A)??%sqrtm函數(shù)是以矩陣為單位進(jìn)行計(jì)算,sqrt函數(shù)是以矩陣中的元素進(jìn)行計(jì)算