How to plot a polynomial?

조회 수: 2 (최근 30일)
Sarah Elena Aiko Johnson
Sarah Elena Aiko Johnson 2022년 10월 7일
편집: Sam Chak 2022년 10월 7일
Hi I am trying to plot this polynomial but it keeps graphing as a straight line. Can anyone help?
%% Part 2
% This is the graphing portion of the problem
xi = [0,7];
fend = -2+(6.*xi)-(4.*(xi.^2))+(.5.*(xi.^3));
plot(xi,fend,'r');
xlabel('X');
ylabel('f(x)');
title('Root Find of F(x) = -2+6x-4x^2+0.5x^3');

채택된 답변

Sam Chak
Sam Chak 2022년 10월 7일
Should try like this:
xi = linspace(-2, 8, 101);
fend = - 2 + (6*xi) - 4*(xi.^2) + (0.5*(xi.^3));
plot(xi,fend,'r');
xlabel('X');
ylabel('f(x)');
title('Root Find of F(x) = -2+6x-4x^2+0.5x^3');
  댓글 수: 1
Sam Chak
Sam Chak 2022년 10월 7일
편집: Sam Chak 2022년 10월 7일
xi = [0,7]
xi = 1×2
0 7
fend = -2+(6.*xi)-(4.*(xi.^2))+(.5.*(xi.^3))
fend = 1×2
-2.0000 15.5000
@Sarah Elena Aiko Johnson, the reason is because there only two points in . When they are passed to fend for evaluation, it will also return two points.
And when you attempt to plot (connect a line between two points), it definitely gives a straight line. In my Answer, I created 101 data points between .

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by