Using a array in a equation that has a variable being isolated.
Mostrar comentarios más antiguos
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 comentarios
John D'Errico
el 2 de Sept. de 2017
Are there two solutions to that quadratic equation? Solve will give them both to you.
John McClarin
el 2 de Sept. de 2017
Respuestas (2)
Star Strider
el 1 de Sept. de 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 comentarios
John McClarin
el 1 de Sept. de 2017
Star Strider
el 2 de Sept. de 2017
It worked when I ran it or I’d not have posted the code.
John McClarin
el 2 de Sept. de 2017
Star Strider
el 2 de Sept. de 2017
Did my Answer solve your problem?
Image Analyst
el 1 de Sept. de 2017
0 votos
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 comentarios
John McClarin
el 2 de Sept. de 2017
Image Analyst
el 2 de Sept. de 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
el 2 de Sept. de 2017
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!