MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
Asked by Lg on 29 Sep 2013

This question was flagged by
Lg

How will I find the maximum height and range of an object when the given are only points? should I start by making a matrix?

*No products are associated with this question.*

Answer by Image Analyst on 29 Sep 2013

Accepted answer

I'd fit a parabola through them using polyfit

coeffs = polyfit(x, y, 2);

Then you can get fitted values

fittedY = polyval(coeffs, xCoordinates);

To get the range and max height you have to know the starting y. Can we assume it's zero? If so, you can find them numerically using find() and max(), respectively. Give it a shot (no pun intended). Come back if you encounter any difficulties.

Image Analyst on 29 Sep 2013

We don't know what he taught you in class. You can plug the x and y values for the three points into the equation Roger gave you and solve for a, b, and c like you did back in high school. Do you know calculus so that you can take the derivative of the equation to get the slope? If so, just set the slope = 0 and solve for x, then plug x into the quadratic to get y (the max height).

Image Analyst on 30 Sep 2013

See if this helps move things along:

% (2, 18) (4, 32) (6,42) x = [2;4;6] y = [18;32;42]

% Create the model for a quadratic. A = [x(1)^2, x(1), 1; x(2)^2, x(2), 1; x(3)^2, x(3), 1];

% Use the standard least squares matrix solution. coeffs = inv(A' * A) * A' * y

% Plot the original data points plot(x,y , 'bo', 'MarkerSize', 10, 'LineWidth', 2); hold on; grid on;

% Make up a continuous curve x3 = 0:1:20 y3 = coeffs(1) * x3 .^ 2 + coeffs(2) * x3 + coeffs(3) plot(x3, y3, 'r-', 'LineWidth', 2); ylim([0,60]);

Answer by Roger Stafford on 29 Sep 2013

If you are not allowed to use 'polyfit', then just solve for coefficients a, b, and c in the equation

y = a*x^2 + b*x + c

The three points will give you three linear equations in the three unknowns a, b, and c. You can either use matlab to solve these or do it by hand. Finally "complete" the square in that expression or else use calculus to find where the derivative is zero, and voila! there are your answers staring you in the face. Good luck!

Image Analyst on 29 Sep 2013

For c to be zero, then if x = 0, y also = 0. At this point we do not know the starting point. You could have shot off the projectile from on top of a building (y=0.5 km) and at x = -2 km from the place specified as the origin. So we shouldn't assume c = 0 at this point. And we don't need to. Just make your equations

y1 = a*x1^2 + b*x1 + c y2 = a*x2^2 + b*x2 + c y3 = a*x3^2 + b*x3 + c

or

Y = X * coeffs (the last column of X is all 1's since it's the coefficient of c). Then just do a matrix division to solve for coeffs. Now you have a, b, and c.

Answer by Youssef KHMOU on 29 Sep 2013

Luzalen,

You are searching for two unknowns , then you need to two variables, points and the angle, you can calculate the angle in first phase of increasing Z,

You can take a look at my submission, it can help :

Show 1 older comment

Youssef KHMOU on 29 Sep 2013

you get the instant **th** when the data is max, next you calculate the initial velocity : **v0=g.th/sin(84)**, then you get the max **h=v0^2 .sin(84) ^2 / 2g**.Next you get the range : **R=4. h /tan(84)**

Youssef KHMOU on 30 Sep 2013

the instant th is when the trajectory reaches maximum, that must be included in your data,

## 2 Comments

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/88579#comment_171429

Luzalen, Is this homework?

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/88579#comment_222978

It was. I apologize for the late reply. I remembered that I was stuck in this question. I will post what I have done first next time to get feedback. I apologize.