How to plot trajectory curve given x and y points as well as minima and maxima of the polynomial?

18 views (last 30 days)
I've spent hours trying to figure out how to do this in matlab, which is frusturating considering it was so easy to find the solution by hand:
The three position (horizontal, vertical) points (0,80), (120,0), (140,5) were given in the word problem; this data was used to create three equations using the polynomial template shown in equation one. Since the point (0,80) is the maximum of the slope and (120,0) is the minimum, the derivative of the height function at these tangent points is zero; this adds two more equations to the system. With a total of five equations, the resulting solution to the system is a fourth degree polynomial. The coefficients of this polynomial were calculated using matricies.
edit:
Here's what I've got so far
Capture1.PNG
How do I set the derivative to zero for the min and max points in my plot?

Answers (2)

KSSV
KSSV on 16 Dec 2019
syms a b c d e ;
eqns = [e == 80 ;
207360000*a+1728000*b+1440*c+120*d+e == 0 ;
384160000*a+2744000*b+19600*c+140*d+e == 5 ;
d == 0 ;
6912000*a+43200*b+240*c+d==0] ;
S = solve(eqns,[a,b,c,d,e]) ;
S.a
S.b
S.c
S.d
S.e
  1 Comment
Newslin Heiller
Newslin Heiller on 16 Dec 2019
I'm trying to do something more like this (Horner's Method for Evaluating Polynomials):
x0=[0 120 140];
y0=[80 0 5];
xs=linspace(0,1,150)
n=length(x0)-1;
ylim([0 100]);
pp_pchip=pchip(x0,y0);
coeffs_deriv = zeros(n,3);
for k = 1:n
c = pp_pchip.coefs(k,:);
coeffs_deriv(k,:) = polyder(c);
end
pp_deriv = mkpp(x0,coeffs_deriv);
clf;
ys_deriv = ppval(pp_deriv,xs);
ydata_deriv = ppval(pp_deriv,x0);
plot(xs,ys_deriv,'g','linewidth',2);
hold on;
plot(x0,ydata_deriv,'k.','markersize',30);
title('First derivative (pchip)','fontsize',18);

Sign in to comment.


Image Analyst
Image Analyst on 16 Dec 2019
If you have x and y (hx), you can get the coefficients with polyfit like this
coefficients = polyfit(x, hx, 4);
Now you can get separate coefficients if you want to:
a = coefficients(1);
b = coefficients(2);
c = coefficients(3);
d = coefficients(4);
e = coefficients(5);
These are the same a, b, c, and d in both the h(x) and h'(x) equations, obviously.
  4 Comments

Sign in to comment.

Categories

Find more on Polynomials 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!