Using a array in a equation that has a variable being isolated.
Ältere Kommentare anzeigen
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 Kommentare
John D'Errico
am 2 Sep. 2017
Are there two solutions to that quadratic equation? Solve will give them both to you.
John McClarin
am 2 Sep. 2017
Antworten (2)
Star Strider
am 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 Kommentare
John McClarin
am 1 Sep. 2017
Star Strider
am 2 Sep. 2017
It worked when I ran it or I’d not have posted the code.
John McClarin
am 2 Sep. 2017
Star Strider
am 2 Sep. 2017
Did my Answer solve your problem?
Image Analyst
am 1 Sep. 2017
0 Stimmen
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 Kommentare
John McClarin
am 2 Sep. 2017
Image Analyst
am 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
am 2 Sep. 2017
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!