Using a array in a equation that has a variable being isolated.

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

Are there two solutions to that quadratic equation? Solve will give them both to you.
Image Analyst showed my the root() command, so im going to use that. Getting the array to work in the equation is the main problem.

Iniciar sesión para comentar.

Respuestas (2)

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

It doesn't work. the fsolve comes up with no solutions found, and the 'matrix dimensions must agree' warning is still there.
Warning: Trust-region-dogleg algorithm of FSOLVE
cannot handle non-square systems; using
Levenberg-Marquardt algorithm instead.
> In fsolve (line 298)
No solution found.
fsolve stopped because the last step was ineffective. However, the vector of function
values is not near zero, as measured by the default value of the function tolerance.
<stopping criteria details>
Matrix dimensions must agree.
It worked when I ran it or I’d not have posted the code.
Yeah I loaded it up this morning and it worked fine, I don't know what was different yesterday. Maybe the workspace was storing values from my other tries? Im knew and don't know if that could affect it but I had maybe a dozen variables in there from previous attempts.
Did my Answer solve your problem?

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 1 de Sept. de 2017
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

That's a great program, but the problem is still that I have to create a script that can handle a array as a variable (or something similar). Using the root(a,b,c) simplifys things a bit but in this case c is a array, which gets the 'matrix dimensions must agree'.
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.
The other guys loop fixed it (mostly). My bad on the grammar, it should have been an 'array', that was the initial height i released the object from on a ramp and as im writing this i realize the h in my time-to-fall equation should be a constant of the height of the end ramp, where the vy should be the only function of h.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 1 de Sept. de 2017

Comentada:

el 2 de Sept. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by