Using a array in a equation that has a variable being isolated.
Show older comments
I've been assigned to use MatLab to make a graph of the height a projectile is released from a ramp vs the distance it travels. As far as i know i have everything required but isolating t as a function of several other functions including the array h. No mater what I do I still get the error message "Matrix dimension must agree". Can anyone help?
clc
%Setting heights and velocity equations
%h=height,g=gravity,v=velocity
%vx=horizontal velocity,vy=vertical velocity
g=9.8;
h=[0.1:0.1:1];
v=sqrt(2*g*h);
vy=v*sind(45);
vx=v*cosd(45);
%defining t
%yp=vertical displacement against time
%h=height
y = ((h+(vy.*t))-(.5.*g.*t.^2) == 0);
t = solve(y,t);
%finding range
%r=range
r=vx.*t;
%Making a graph based of height against range
plot(h,r)
xlabel('height')
ylabel('range')
2 Comments
John D'Errico
on 2 Sep 2017
Are there two solutions to that quadratic equation? Solve will give them both to you.
John McClarin
on 2 Sep 2017
Answers (2)
Star Strider
on 1 Sep 2017
Try this:
g=9.8;
h=[0.1:0.1:1];
v=sqrt(2*g*h);
vy=v*sind(45);
vx=v*cosd(45);
%defining t
%yp=vertical displacement against time
%h=height
for k1 = 1:numel(h)
y = @(t) (h(k1)+(vy.*t))-(.5.*g.*t.^2);
t(k1) = fsolve(y, 1);
end
%finding range
%r=range
r=vx.*t;
%Making a graph based of height against range
plot(h,r)
xlabel('height')
ylabel('range')
4 Comments
John McClarin
on 1 Sep 2017
Star Strider
on 2 Sep 2017
It worked when I ran it or I’d not have posted the code.
John McClarin
on 2 Sep 2017
Star Strider
on 2 Sep 2017
Did my Answer solve your problem?
Image Analyst
on 1 Sep 2017
0 votes
See my projectile demo. It computes and plots just about everything you could want. Here are the plots. Other info is given in message boxes.


Adapt as needed.
3 Comments
John McClarin
on 2 Sep 2017
Image Analyst
on 2 Sep 2017
I don't understand. What is the "a array"? And why is it not a variable? And why is c, which is y0 = the initial height, an array? "a" and "c" in my code are scalars. Post your new code.
John McClarin
on 2 Sep 2017
Categories
Find more on Creating and Concatenating Matrices 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!