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)

 采纳的回答

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.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Mathematics 的更多信息

产品

版本

R2022b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by