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
James Tursa
2018년 5월 8일
You don't have to insert blank lines in your code to make it readable. Simply select it and then push the "{ } Code" button.
답변 (2개)
Guillaume
2018년 5월 8일
0 개 추천
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
2018년 5월 8일
편집: James Tursa
2018년 5월 8일
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)? ';
카테고리
도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!