how to fix 'Error using * Inner matrix dimensions must agree.' help please

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 commentaire

You don't have to insert blank lines in your code to make it readable. Simply select it and then push the "{ } Code" button.

Connectez-vous pour commenter.

Réponses (2)

Guillaume
Guillaume le 8 Mai 2018
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
James Tursa le 8 Mai 2018
Modifié(e) : James Tursa le 8 Mai 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)? ';

Catégories

En savoir plus sur Operators and Elementary Operations dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by