How do I plot a function that consists of a variable depending on x?

For example, after some calculations to solve my problem, I get y=x^3.
How do I plot that function? I tried to do fplot(@(x) y, limits) but it doesn't work...any solution?

回答 (2 件)

Walter Roberson
Walter Roberson 2013 年 1 月 5 日

1 投票

ezplot('x^3', limits)
OR
ezplot(@(x) x.^3, limits)
OR
x = linspace(LowerLimit, UpperLimit, NumberofPoints);
plot(x, x.^3)
Or more generally if you have a symbolic variable y that contains the expression,
f = matlabFunction(y, 'x');
and then
ezplot(f, limits)
or
x = linspace(LowerLimit, UpperLimit, NumberofPoints);
plot(x, f(x))

2 件のコメント

Flávio
Flávio 2013 年 1 月 5 日
Thank you man! It was the matlabFunction that I needed!
Walter Roberson
Walter Roberson 2013 年 1 月 5 日
Accept this Answer ?

サインインしてコメントする。

Jing
Jing 2013 年 1 月 5 日
編集済み: Jing 2013 年 1 月 5 日

0 投票

Hi, It should be like this:
y=@(x) x^3; fplot(y,[-10,10]);
or
fplot(@(x) x^3,[-10,10])
You need to define the function handle.

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

タグ

質問済み:

2013 年 1 月 5 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by