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 Comment

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

Sign in to comment.

Answers (2)

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.
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)? ';

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Asked:

on 8 May 2018

Edited:

on 8 May 2018

Community Treasure Hunt

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

Start Hunting!