文章目录
语法知识
☺♪ 补充知识点: rand randn randi
☺♪5.1 线性图函数plot
☺♪5.2 简易线性图函数
☺♪5.3 散点图
☺♪5.4 极坐标及其与直角坐标图的转换
实例演练
♥♥♥例5-1 随机向量y的线性图
>> y=fix(100*rand(1,8))
y =
67 75 74 39 65 17 70 3
>> plot(y)
>> grid on
>> title('向量y的线性图')
>> xlabel('candy')
>> ylabel('tooth')
注:fix()——取整
♥♥♥例5-2 反正切函数及其微分曲线
>> syms x
>> y=atan(x)
y =
atan(x)
>> y1=diff(y)
y1 =
1/(x^2 + 1)
>> x=-5:0.1:5;
>> y=eval(y);
>> y1 =1./(x.^2 + 1);
>> plot(x,y,'-',x,y1,'*')
>> grid on
>> title('反正切函数及其微分曲线')
>> xlabel(x)
>> xlabel('x')
>> ylabel('y')
♥♥♥例5-3 复合三角函数图
>> x=-pi:pi/10:pi;
>> y=tan(sin(x));
>> z=sin(tan(x));
>> plot(x,y,'--rs','linewidth',2,'markeredgecolor','k','markerfacecolor','y','markersize',10)
>> hold on
>> plot(x,z,'-bo','linewidth',2,'markeredgecolor','k','markerfacecolor','m','markersize',10)
补充:https://blog.csdn.net/jirryzhang/article/details/77374702 Matlab plot绘图颜色详解
♥♥♥例5-4 句柄与set命令
♥♥♥例5-5 功率曲线
>> t=0:pi/50:4*pi;
>> I=sin(t);
>> V=2*sin(t+pi/3);
>> P=I.*V;
>> plot(t,I,'-',t,V,'--',t,P,'*')
>> grid on
♥♥♥例5-7 画椭圆
♥♥♥例5-8 求函数图像
注:两种方法还是有区别的
♥♥♥例5-9 散点图与回归方程
>> A=[1.55,1.58,1.6,1.64,1.66,1.68,1.7,1.73,1.78,1.8,1.82,1.85;60,57,57,65,63,64,70,65,68,76,72,78]
A =
1 至 6 列
1.5500 1.5800 1.6000 1.6400 1.6600 1.6800
60.0000 57.0000 57.0000 65.0000 63.0000 64.0000
7 至 12 列
1.7000 1.7300 1.7800 1.8000 1.8200 1.8500
70.0000 65.0000 68.0000 76.0000 72.0000 78.0000
>> X=A(1,:);
>> Y=A(2,:);
>> plot(X,Y,'*b')
>> hold on
>> polyfit(X,Y,1)
ans =
63.2899 -41.2900
>> x=1.5:0.1:2;
>> y=63.2899*x-41.2900;
>> plot(x,y,'-r');grid on
♥♥♥例5-10 三叶玫瑰线
>> zeta=0:pi/100:6*pi;
>> r=sin(3*zeta);
>> [x,y]=pol2cart(zeta,r);
>> subplot(1,2,1);polar(zeta,r)
>> subplot(1,2,2);plot(x,y);grid on
♥♥♥例5-11 内摆线(直角坐标→极坐标)
>> x=cos(zeta).^3;
>> y=sin(zeta).^3;
>> zeta=0:pi/20:4*pi;
>> [theta,rho]=cart2pol(x,y);
>> polar(theta,rho)
总结思考
今天画了好多图呀~(好麻烦QAQ)(不是,开个玩笑)。发现这本书,可以在之后的应用上当做工具书查阅,太多函数以及格式现在来说肯定没有办法…一一记得非常清楚(今天深刻感受到),所以说应该只能在之后的应用中慢慢熟悉…学到现在,发现我们物理实验后面的数据处理,如果一开始自己就写一段代码,不确定度,最小二乘法回归方程。。。什么什么的,就不用像以前花那么长时间,只要输个数据TAT(but,我的物理实验已经结束了23333)emm今天先完成一半任务,明天继续,fighting!
江宇直表情包三连~↑