matlab怎么画函数图像 MATLAB绘制函数图像方法

1 画图基础

(1)一元一次函数

  1. x=0:0.1:1;

  2. y=x;

  3. plot(x,y); %图像见下图1

(2)一元多次函数

  1. x=0:0.1:1;

  2. y=x.^2;

  3. plot(x,y);    % 图像见图2

2 分段函数图像

  1. x=0:0.1:2;

  2. y=x.*(x>=0&x<=1)+(-(x-1).^2+1).*(x>1&x<=2);

  3. plot(x,y);   %图像见图3

  4. %组合函数y=y1.*(x定义域)+y2.*(x定义域)

3 其他小技巧

(1)多条曲线画在同一个图像里

tip:使用 hold on 函数

  1. t=[0:0.01:1];

  2. q1=120-180*t.^2+120*t.^3;

  3. q2=120-600*t.^3+900*t.^4-360*t.^5;

  4. plot(t,q1);hold on;

  5. plot(t,q2);

  6. %图形见图4

(2)改变图像中线的颜色和线条形式(针对plot函数)

  1. t=[0:0.01:1];

  2. q1=120-180*t.^2+120*t.^3;

  3. q2=120-600*t.^3+900*t.^4-360*t.^5;

  4. plot(t,q1,'r');hold on;

  5. plot(t,q2,'b');

  6. %见图5

通过在plot()函数括号里面增加特性来改变图线,常见的颜色和类型如图6

(3)增加图例

tip:利用l egend 函数

  1. t=[0:0.01:1];

  2. q1=120-180*t.^2+120*t.^3;

  3. q2=120-600*t.^3+900*t.^4-360*t.^5;

  4. plot(t,q1,'r'); hold on;

  5. plot(t,q2,'b');

  6. legend('a)函数图像','b)函数图像') %要按函数的顺序来添加

  7. %见图7