How to multiply matrices with variables as elements

8 visualizaciones (últimos 30 días)
% v is the velocity of the projectile [1:60]
% theta is the angle of at which it is launched [0:75]
% dx is the distance of x-coordinate of the object from the origin after t seconds
% dy is the distance of x-coordinate of the object from the origin after t seconds
% Matrix 1, M1 = [0, v*cosd(theta); -4.9, v*sind(theta)]
% Matrix 2, M2 = [t^2; t]
% Matrix 3, M3 = [dx; dy]
[0, v*cosd(theta); -4.9, v*sind(theta)]*[t^2; t] = [dx; dy]
The formula above is the equation for travel of a projectile in matrix form.
I was planning on searching for the shortest time possible for an object to travel dx and dy (which I set)
My plan was to multiply the equation by the inverse of M1. And then find the minimum value of t using a min function, then obtaining its v and theta that way.
[t^2; t]=1/(4.9*v*cos(theta))*[v.*sind(theta), -v.*cosd(theta); 4.9, 0]*[dx; dy]
In Matlab it would be closer to
[x; y]=1/(4.9*v*cos(theta))*[v.*sind(theta), -v.*cosd(theta); 4.9, 0]*[dx; dy]
and then finding the min for y.
However the variables caused the matrix to explode into a 2x(way too much) matrix.
> Error using vertcat
> Dimensions of arrays being concatenated are not consistent.
Is there another way of doing this?
Edit :
Disclaimer : If the variables look suspiciously familiar, my school requested that I pick v and theta by hand without caring for time taken
This was just a personal challenge using the work they gave me.
  2 comentarios
Bob Thompson
Bob Thompson el 13 de Sept. de 2019
I am not well versed in these forms of matlab, but I know that symbolic values and function (f(x) math functions, not matlab script fuctions) do exist. I think you would have a better time looking down that route.
I believe you're receiving the error because v and theta are already defined arrays (they have sizes), but do not have the same size for their arrays, so it is difficult to multiply 60x1 elements of v with the 75x1 elements of theta.
Walter Roberson
Walter Roberson el 13 de Sept. de 2019
Caution:
[x; y]=1/(4.9*v*cos(theta))*[v.*sind(theta), -v.*cosd(theta); 4.9, 0]*[dx; dy]
your cos(theta) should be a cosd(theta)
And you would need to assign this to a single varible and extract the parts of the variable afterwards.

Iniciar sesión para comentar.

Respuesta aceptada

Naveen Venkata Krishnan
Naveen Venkata Krishnan el 9 de Oct. de 2019
Hello,
Based on the problem description you are trying to minimize the time taken to reach a particular set point ( cost function ) where Velocity(v) and Theta(θ) are the optimization variables . Assuming the vectors [1:60] and [0:75] denotes the Range of optimization variables ( v and θ), in that case
v-lower bound : 1;
v-upper bound :60;
θ-lowerbound : 0;
θ-upper bound : 75;
This can solved as an optimization problem using fmincon solver.
cost function :
where here x,y are dx,dy in your case.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by