*Matrix dimensions must agree error*

조회 수: 1 (최근 30일)
Adriaan Breytenbach
Adriaan Breytenbach 2020년 11월 23일
댓글: Alan Stevens 2020년 11월 23일
I am relatively new to Matlab and is working on a problem but keep getting this error. Please help! I attached the matlab file, but is also posting a screenshot.

채택된 답변

Alan Stevens
Alan Stevens 2020년 11월 23일
Look up .* (i.e. dot*), ./ and .^ for element by element actions. Replace the later part of your code by
x=linspace(0.5,1);
Vx=V1*cos(x);
Vy=V1*sin(x);
%===========
%Calculations
%===========
y1=(L4./(V1*cos(x))); % ./ not just /
y2=((-g/2)*(L4./(V1*cos(x)).^2)+V1*sin(x).*(L4./(V1*cos(x)))+L3); % ./, .^ and .* y2?
y3=Vb*(L4./(V1*cos(x)))+L1; % ./
plot(x,y1,x,y2,x,y3),grid
xlabel('x'),ylabel('y')
legend('y1','y2','y3')

추가 답변 (1개)

Mohamad
Mohamad 2020년 11월 23일
Hi , I made the required corrections in the code , now it is working , I also plot y1 and y3 .
%==============================
% Computer based assigment - dynamics
%==============================
% Question 1
%Given
L1=14;
L2=25;
L3=2;
L4=100;
Vb=6;
V1=40;
g=9.81;
x=linspace(0.5,1);
Vx=V1*cos(x);
Vy=V1*sin(x);
%===========
%Calculations
%===========
y1=(L4./(V1*cos(x)));
y3=(-0.5*g*(L4./(Vx).^2)+Vy.*(L4./(Vx))+L3);
y3=Vb*(L4./(Vx))+L1;
subplot(211) ; plot(x,y1) ; grid
subplot(212) ; plot(x,y3) ; grid
  댓글 수: 1
Alan Stevens
Alan Stevens 2020년 11월 23일
Note that you have two expressions for y3.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by