How do I plot this function?

1 view (last 30 days)
Nico Degabriele
Nico Degabriele on 14 May 2022
Answered: ali temsah on 14 May 2022
I was asked to plot a graph of the function f(x)=y=0.25x^6-2x^5-3x^4+64x^3-212x^2+288x+2 between the interval [-20 20]for which I used the following code:
x=[-20:0.5:20]
x = 1×81
-20.0000 -19.5000 -19.0000 -18.5000 -18.0000 -17.5000 -17.0000 -16.5000 -16.0000 -15.5000 -15.0000 -14.5000 -14.0000 -13.5000 -13.0000 -12.5000 -12.0000 -11.5000 -11.0000 -10.5000 -10.0000 -9.5000 -9.0000 -8.5000 -8.0000 -7.5000 -7.0000 -6.5000 -6.0000 -5.5000
y=(0.25*(x.^6))-(2*(x.^5))-(3*(x.^4))+(64*(x.^3))-(212*(x.^2))+(288*x)+2
y = 1×81
1.0e+07 * 2.1317 1.8390 1.5802 1.3522 1.1520 0.9769 0.8243 0.6918 0.5774 0.4789 0.3947 0.3229 0.2622 0.2111 0.1683 0.1329 0.1037 0.0799 0.0607 0.0453 0.0332 0.0237 0.0165 0.0110 0.0070 0.0041 0.0021 0.0008 0.0000 -0.0004
plot(x,y)
However, the resultant graph did not match the one I created on a basic graph plotter. What could I be doing wrong please? Thanks in advance
  2 Comments
Torsten
Torsten on 14 May 2022
Edited: Torsten on 14 May 2022
However, the resultant graph did not match the one I created on a basic graph plotter. What could I be doing wrong please?
Maybe your basic graph plotter is wrong.
At least the code
x = -20:0.5:20;
y = 0.25*x.^6 - 2*x.^5 - 3*x.^4 + 64*x.^3 - 212*x.^2 + 288*x + 2
plot(x,y)
is correct.
Nico Degabriele
Nico Degabriele on 14 May 2022
Ok thanks then! I just wanted to make sure I was on the right track

Sign in to comment.

Answers (1)

ali temsah
ali temsah on 14 May 2022
you could plot it like this
x = -20:0.5:20;
coeffents=[0.25 -2 -3 64 -212 288 2];
y=polyval(coeffents,x);
plot(x,y)
grid on

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!