How to plot polynomial function correctly?

From the given cooeficient polynomial functions how to draw an graph in matlab
P(x) = a_0+a_1x+a_2x^2. Whose graph passes through the points (1, 4), (4,73) and (5, 18). Also plot the function using MATLAB command (having proper title, x and y axis notation).

1 Kommentar

Steven Lord
Steven Lord am 31 Aug. 2022
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 31 Aug. 2022

0 Stimmen

polyfit() and polyval() and plot()

7 Kommentare

Fozle Rabbi
Fozle Rabbi am 31 Aug. 2022
can you help me with the code
Walter Roberson
Walter Roberson am 31 Aug. 2022
Look at the documentation for each of the functions. They have examples.
Fozle Rabbi
Fozle Rabbi am 31 Aug. 2022
Yes I am looking it and trying to understanding. Thanks a lot for helping me
Walter Roberson
Walter Roberson am 31 Aug. 2022
You can ask specific questions. The code takes a very small number of lines, the labels and so on are more than half of the work.
Fozle Rabbi
Fozle Rabbi am 1 Sep. 2022
What will be the value x and y. I can't understand this part
Walter Roberson
Walter Roberson am 1 Sep. 2022
You need to choose the x values to plot over.
You will use the given points to figure out what the coefficients are for the polynomial.Then, y will be the polynomial evaluated at your chosen x locations.
syms x [3 1]
syms y [3 1]
vand = [ones(3,1), x, x.^2];
a0123 = simplify(vand \ y, 'steps', 20)
a0123 = 
sample_x = sort(randperm(10,3).');
sample_y = randi(100, 3, 1);
[sample_x, sample_y]
ans = 3×2
1 92 4 60 6 57
A0123 = simplify(subs(a0123, [x; y], [sample_x;sample_y]), 'steps', 20)
A0123 = 
X = -1:11;
Y = polyval(double(fliplr(A0123.')), X)
Y = 1×13
131.6667 110.0000 92.0000 77.6667 67.0000 60.0000 56.6667 57.0000 61.0000 68.6667 80.0000 95.0000 113.6667
plot(X, Y); hold on
scatter(sample_x, sample_y, 'r*'); hold off

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by