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 comentario

Moisés Abel
Moisés Abel el 5 de Sept. de 2023
Thanks to everyone who answered so quickly, you were all of great help!

Iniciar sesión para comentar.

 Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 5 de Sept. de 2023
Editada: Dyuman Joshi el 5 de Sept. de 2023
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 comentarios

Voss
Voss el 5 de Sept. de 2023
Editada: Voss el 5 de Sept. de 2023
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 el 5 de Sept. de 2023
Yes, Spot on.
Though, you should change the comment above the set() call, @Voss.
Voss
Voss el 5 de Sept. de 2023
Right! Done.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Productos

Versión

R2022b

Etiquetas

Preguntada:

el 5 de Sept. de 2023

Comentada:

el 5 de Sept. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by