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

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일
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

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')
Yes, Spot on.
Though, you should change the comment above the set() call, @Voss.
Voss
Voss 2023년 9월 5일
Right! Done.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

릴리스

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