MATLAB作业
1.3-1 1.3-2
输入想x,y的值,将它们互换后输出。 计算分段函数的值。
1.3-3
大小写字母转换
1.3-4
case的用法
1.3-5
输出水仙花数
1.3-6
求[100~200]之间第一个被21整除的数
1.3-7
将华氏温度转化为摄氏度
1.3-8
编写函数求半径为r的圆的周长
1.3-10
无穷级数
1.3-11
生成一个5x10000的 Hilbert长方矩阵,其中第i行第j列元素为h-{i,j}=1/(i+j-1)
Demo1
n = 128; //把128赋值给n
u = linspace(0,pi,n); //产生n个步长为n/pi的矩阵
v = linspace(0,pi,n); //产生n个步长为n/pi的矩阵
u = repmat(u,n,1); // 将矩阵复制n行
v = repmat(v',1,n); //将矩阵复制n列
x = cos(v).*sin(u); //将右边的值一一赋值给x并形成一个矩阵
y = sin(v).*sin(u); //将右边的值一一赋值给y并形成y矩阵
z = cos(u); // 将右边的值赋值给z并形成一个矩阵
f = 1/2*((2*x.^2-y.^2-z.^2) + 2*y.*z.*(y.^2-z.^2) + ...
z.*x.*(x.^2-z.^2) + x.*y.*(y.^2-x.^2)) //;将右边的值经过函数运算后,一一赋值给f,形成矩阵
g = sqrt(3)/2 * ((y.^2-z.^2) + z.*x.*(z.^2-x.^2) + x.*y.*(y.^2-x.^2)) //;同上
h = (x+y+z).*((x+y+z).^3 + 4*(y-x).*(z-y).*(x-z)); //同上
Clf //清除原有的图形
s = surf(f,g,h/10,u, ...
'LineStyle','none', ...
'FaceLighting','gouraud', ...
'FaceColor','interp'); //制作三维空间立体图,线性设置为无,并采用高氏着色法着色
colormap jet; //colormap类型设置为jet
axis off; //axes的样式为off
daspect([1 1 1]); //长宽高之比设置为1
l1 = light; //将light的值赋值给l1
l2 = light; //同上
lightangle(l1,70,-40);//设置光源的方向
lightangle(l2,-30,80);//同上
view(-40,32); //设置二维视角
camzoom(1.5);//输出三维图形
Demo2
Search MATLAB Documentation
This example shows how to do some basic matrix manipulations in MATLAB.
We start by creating a magic square and assigning it to the variable A.A = magic(3)
A =
8 1 6
3 5 7 //创建一个三维矩阵
4 9 2
Here's how to add 2 to each element of A.Note that MATLAB requires no special handling of matrix math.A+2
ans =
10 3 8
5 7 9 //每个元素的值都叫二
6 11 4
The apostrophe symbol denotes the complex conjugate transpose of a matrix.Here's how to take the transpose of A.A'
ans =
8 3 4
1 5 9 矩阵的倒置
6 7 2
The symbol * denotes multiplication of matrices.Let's create a new matrix B and multiply A by B.B = 2*ones(3)
A*B
B =
2 2 2
2 2 2 //计算矩阵A与B的成绩
2 2 2
ans =
30 30 30
30 30 30 A与B相乘
30 30 30
We can also multiply each element of A with its corresponding element of B by using the .* operator.A.*B
ans =
16 2 12
6 10 14 A与B中的元素一一对应相乘
8 18 4
MATLAB has functions for nearly every type of common matrix calculation. For example, we can find the eigenvalues of A using the "eig" command.eig(A)
ans =
15.0000
4.8990
-4.8990
This concludes our brief tour of some MATLAB matrix handling capabilities.
Was this topic helpful?
Acknowledgments
Trademarks
Patents
Terms of Use
© 1994-2012 The MathWorks, Inc.