How can I plot various polynomials along with some coordinate pairs in the same graph?
Mostra commenti meno recenti
For my matlab introductory course we were tasked to plot various coordinate pairs as well as the polynomials passing through those points so we could "draw" a figure on the plot chart. I made a test code in which I took 3 pairs of coordinate points, generated a polynomial passing trought those 3 points, plotted that and then repeated the process with another 3 pairs of coordinated points (Im doing it with 3 pairs of coordinates at a time so i can generate a polynomial per coordinate set):
%coordinate set 1
x = [0.51 1.29 2.36];
y = [0.99 1.61 2.02];
p = polyfit(x,y,2);
lx = 0.51:.1:2.36;
ly = polyval(p,lx);
%coordinate set 2
x1 = [2.36 7.37 12.12];
y1 = [2.02 2.08 2.03];
p1 = polyfit(x1,y1,2);
lx1 = 2.36:.1:12.12;
ly1 = polyval(p1,lx1);
%Plot both polynomials in 1 graph
plot(x,y,'o',lx,ly,'o',x1,y1,'o',lx1,ly1)
grid on
text(2,400,s)
%Generated polynomial display
s = sprintf('y = (%.1f) x^3 + (%.1f) x^2 + (%.1f) x',p(1),p(2),p(3));
s1 = sprintf('y = (%.1f) x^3 + (%.1f) x^2 + (%.1f) x',p1(1),p1(2),p1(3));
disp(s);
disp(s1);
When it plots those elements, the graph appears to go crazy. Im planning to do this with more than 2 coordinate sets. I'm trying to do some sort of cubic spline but without utilizing the spline function.
Thanks in advanced for your suggestions, comments and knowledge.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Line Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

