Matlab计算学习笔记
1.矩阵运算操作
生成行与列的操作:
A=[1 2 3 4] ; %生成行
A=[1;2;3;4]; %生成列
2.从键盘中输入数据
a=input('please input a : ' )
please input a : 6
a =
6
3.设置输入输出格式
4.绘图
>> y1=x1.^2;
>> x2=0:0.5:10;
>> y2=2*x2+3;
>> plot(x1,y1,x2,y2)
function ex0101()
x=0:pi/15:2*pi;
y1=0.5*x.^2;
y2=10*sin(x);
plot(x,y1,'r.-',x,y2'); %画图
grid %网格线
xlabel('variable x') %横坐标
ylabel('x^2 and sin(x)') %纵坐标
title('x^2 and sin(x)'); %标题
text(6.2,-5.5,'sin(x)'); %在坐标6.2和-5.5处标注y2
text(6.2,16,'x^2'); %在坐标6.2和16处标注y1
function ex0102()
x=0:pi/15:2*pi;
y1=0.5*x.^2;
y2=10*sin(x);
y3=exp(x);
y4=cos(x);
subplot(2,2,1); %拆分为2*2个区域分别在各个区域画图
plot(x,y1); %画图
title('0.5x^2');
subplot(2,2,2);
plot(x,y2); %画图
title('0.1*sin(x)');
subplot(2,2,3); %拆分为2*2个区域分别在各个区域画图
plot(x,y3); %画图
title('exp(x)');
subplot(2,2,4);
plot(x,y4); %画图
title('cos(x)');
5.三维图形绘图学习
function ex0103()
t=0:pi/50:6*pi;
xt=exp(-0.1*t).*cos(t);
yt=exp(-0.1*t).*sin(t);
subplot(2,2,1); %拆分为2*2个区域分别在各个区域画图
plot3(xt,yt,t); %画图
grid on
title('xy yt t 的三维图');
subplot(2,2,2);
plot3(xt,yt,t); %画图
grid on
title('在(1,0,0)的三维图');
view([1 0 0]); %观测在 (0,0,1)的三维图
subplot(2,2,3);
plot3(xt,yt,t); %画图
grid on
title('在(0,0,1)的三维图');
view([0 0 1]); %观测在 (0,0,1)的三维图
subplot(2,2,4);
plot3(xt,yt,t); %画图
grid on
title('在(0,-1,0)的三维图');
view([0 -4 0]); %观测在 (0,0,1)的三维图