how to fix 'Error using * Inner matrix dimensions must agree.' help please
Mostrar comentarios más antiguos
this is what i have written so far
angle='What is the angle of projection?';
x=input(angle);
speed='What is the intial velocity?';
y=input(speed);
g=-9.81;
radians=(pi/180)*angle;
c=cos(radians);
s=sin(radians);
v_x=speed*c
v_y=speed*s
i need to find V_x and V_y but it keeps displaying the message 'Error using * Inner matrix dimensions must agree.'
1 comentario
James Tursa
el 8 de Mayo de 2018
You don't have to insert blank lines in your code to make it readable. Simply select it and then push the "{ } Code" button.
Respuestas (2)
Guillaume
el 8 de Mayo de 2018
0 votos
Usually when you get this error, it's because you meant to use memberwise multiplication, .* instead of matrix multiplication *. The dot makes a huge difference. See Array vs Matrix Operations to learn about it.
James Tursa
el 8 de Mayo de 2018
Editada: James Tursa
el 8 de Mayo de 2018
Your 'angle' and 'speed' variables are strings you use for the input prompts. They are not the user inputs, which are x and y. So you need to use x and y downstream in your code. E.g.,
radians = (pi/180)*x;
c = cos(radians);
s = sin(radians);
v_x = y*c;
v_y = y*s;
P.S. It is always good to include the expected units in the prompt. E.g.,
angle = 'What is the angle of projection (deg)? ';
:
speed = 'What is the initial velocity (m/s)? ';
Categorías
Más información sobre Operators and Elementary Operations 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!