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 Comment

Thanks to everyone who answered so quickly, you were all of great help!

Sign in to comment.

 Accepted Answer

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 Comments

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.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!