绘制在Matlab中不同域上表现不同的函数 [英] Plotting a function which behaves differently over different domains in Matlab
本文介绍了绘制在Matlab中不同域上表现不同的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个定义为
f(x) = x^2; x>0 & x<=1
= x^3; x>1 & x<2
= 2*x; elsewhere
如何在Matlab中的同一张图中绘制它?
How do I plot this in Matlab in the same graph?
推荐答案
我会在没有fplot
的情况下执行此操作:
I would do this without fplot
:
x = 0:0.1:3;
x1 = x(x>0 & x<=1);
x2 = x(x>1 & x<2);
x3 = x(x>2);
y1 = (x1).^2;
y2 = (x2).^3;
y3 = 2*(x3);
plot([x1 x2 x3], [y1 y2 y3])
这篇关于绘制在Matlab中不同域上表现不同的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文