MATLAB和Mathematica、Maple并称为三大数学软件。它在数学类科技应用软件中在数值计算方面首屈一指。MATLAB可以进行矩阵运算、绘制函数和数据、实现算法、创建用户界面、连接其他编程语言的程序等,主要应用于工程计算、控制设计、信号处理与通讯、图像处理、信号检测、金融建模设计与分析等领域。
下面是两个MATLAB程序设计案例:代写MATLAB程序,代做MATLAB作业请联系QQ:800056654
Using Toolbox Path Cache. Type “help toolbox_path_cache” for more info.
To get started, select “MATLAB Help” from the Help menu.
>> A=[1 2 3;2 3 5;3 7 10]
A =
1 2 3
2 3 5
3 7 10
>> det(A)
ans =
0
>> A=[1 2 3;2 3 5;3 7 11]
A =
1 2 3
2 3 5
3 7 11
>> det(A)
ans =
-1
>> inv(A)
ans =
2.0000 1.0000 -1.0000
7.0000 -2.0000 -1.0000
-5.0000 1.0000 1.0000
>> b=[1 2 3]’
b =
1
2
3
>> A\b
ans =
1
0
0
>> A*(A\b)
ans =
1
2
3
>> inv(A)*b
ans =
1
0
0
>> lu(A)
ans =
3.0000 7.0000 11.0000
0.6667 -1.6667 -2.3333
0.3333 0.2000 -0.2000
>> [L U P]=lu(A)
L =
1.0000 0 0
0.6667 1.0000 0
0.3333 0.2000 1.0000
U =
3.0000 7.0000 11.0000
0 -1.6667 -2.3333
0 0 -0.2000
P =
0 0 1
0 1 0
1 0 0
>> P*A
ans =
3 7 11
2 3 5
1 2 3
>> L*U
ans =
3 7 11
2 3 5
1 2 3
>> y=L\(P*b)
y =
3
0
0
>> x=U\y
x =
1
0
0
>> randn(4)
ans =
-0.4326 -1.1465 0.3273 -0.5883
-1.6656 1.1909 0.1746 2.1832
0.1253 1.1892 -0.1867 -0.1364
0.2877 -0.0376 0.7258 0.1139
>> det(randn(4))
ans =
-0.8869
>> randn(4)
ans =
0.8156 1.1908 -1.6041 -0.8051
0.7119 -1.2025 0.2573 0.5287
1.2902 -0.0198 -1.0565 0.2193
0.6686 -0.1567 1.4151 -0.9219
>> diag(A)
ans =
1
3
11
>> diag([1 2 3])
ans =
1 0 0
0 2 0
0 0 3
>> diag(diag(A))
ans =
1 0 0
0 3 0
0 0 11
>> L=tril(A)
L =
1 0 0
2 3 0
3 7 11
>> D=diag(diag(A));
>> L=tril(A)-D
L =
0 0 0
2 0 0
3 7 0
>> U=triu(A)-D
U =
0 2 3
0 0 5
0 0 0
>> D+L+U
ans =
1 2 3
2 3 5
3 7 11
>> L=-L
L =
0 0 0
-2 0 0
-3 -7 0
>> U=-U
U =
0 -2 -3
0 0 -5
0 0 0
>> D-L-U
ans =
1 2 3
2 3 5
3 7 11
>> sum([1 2 3])
ans =
6
>> sum([1 -2 3])
ans =
2
>> abs([1 -2 3])
ans =
1 2 3
>> A(1,1)
ans =
1
>> A(2,2)
ans =
3
>> A(3,3)
ans =
11
>>
2、Electromagnetic wave assignment
clear
q=1;
xm=2.5;
ym=2;
x=linspace(-xm,xm);
y=linspace(-ym,ym);
[X Y]=meshgrid(x,y);
R1=sqrt((X+1).^2+Y.^2);
R2=sqrt((X-1).^2+Y.^2);
U=1./R1-q./R2;
u=1:0.5:4;
legend(num2str(u’));
hold on
plot(-1,0,’o’,’MarkerSize’,12);
plot(1,0,’o’,’MarkerSize’,12);
[Ex Ey]=gradient(-U,x(2)-x(1),y(2)-y(1));
dth1=20;
th1=(dth1:dth1:180-dth1)*pi/180;
r0=0.1;
x1=r0*cos(th1)-1;
y1=r0*sin(th1);
streamline(X,Y,Ex,Ey,x1,y1);
streamline(X,-Y,Ex,-Ey,x1,-y1);
dth2=dth1/q;
th2=(180-dth2:-dth2:dth2)*pi/180;
x2=r0*cos(th2)+1;
y2=r0*sin(th2);
streamline(X,Y,-Ex,-Ey,x2,-y2);
streamline(X,Y,-Ex,-Ey,x2,y2);
axis equal tight
上一篇