Using a array in a equation that has a variable being isolated.
Afficher commentaires plus anciens
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 commentaires
John D'Errico
le 2 Sep 2017
Are there two solutions to that quadratic equation? Solve will give them both to you.
John McClarin
le 2 Sep 2017
Réponses (2)
Star Strider
le 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 commentaires
John McClarin
le 1 Sep 2017
Star Strider
le 2 Sep 2017
It worked when I ran it or I’d not have posted the code.
John McClarin
le 2 Sep 2017
Star Strider
le 2 Sep 2017
Did my Answer solve your problem?
Image Analyst
le 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 commentaires
John McClarin
le 2 Sep 2017
Image Analyst
le 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
le 2 Sep 2017
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!