Function out of proportion/wrong while in matlab?

Hi, I'm trying to use a function I made using graphing calculators, but when i type it in and plot in in matlab, it's not the same line.
syms x
y2 = 0.0000772436429838*x^3+0.0146583319491*x^2 -0.184551271403*x+4.99872818128;
fplot(y2)
When It should look something more like this according to both geogebra and desmos graphic calculators (Screenshot attached)

1 件のコメント

Moisés Abel
Moisés Abel 2023 年 9 月 5 日
Thanks to everyone who answered so quickly, you were all of great help!

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

 採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 9 月 5 日
編集済み: Dyuman Joshi 2023 年 9 月 5 日

1 投票

You have to define the x-range over which you want to plot the function.
The default range is [-5,5] - Refer to the documentation of fplot for more information.
syms x
y2 = 0.0000772436429838*x^3+0.0146583319491*x^2 -0.184551271403*x+4.99872818128;
%Calling fplot with a specific range for x values
fplot(y2,[-250 100])
%Modifying to make the plot look similar to the screenshot
%Changing x and y limits
xlim([-250 250])
ylim([-100 200])
%Add lines to appear as the axes
xline(0)
yline(0)

3 件のコメント

Voss
Voss 2023 年 9 月 5 日
編集済み: Voss 2023 年 9 月 5 日
An alternative to using xline and yline to plot the x- and y-axis lines is setting the XAxisLocation and YAxisLocation properties of the axes to 'origin', which also puts the x- and y-ticks along the axis lines.
syms x
y2 = 0.0000772436429838*x^3+0.0146583319491*x^2 -0.184551271403*x+4.99872818128;
%Calling fplot with a specific range for x values
fplot(y2,[-250 100])
%Modifying to make the plot look similar to the screenshot
%Changing x and y limits
xlim([-250 250])
ylim([-100 200])
%Setting up X- and Y-Axis
set(gca(),'XAxisLocation','origin','YAxisLocation','origin')
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 5 日
Yes, Spot on.
Though, you should change the comment above the set() call, @Voss.
Voss
Voss 2023 年 9 月 5 日
Right! Done.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

リリース

R2022b

タグ

質問済み:

2023 年 9 月 5 日

コメント済み:

2023 年 9 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by