Matlab code wont run. Matrix dimensions must agree error

1 次查看(过去 30 天)
Matrix dimensions must agree.
Error in ME4112_Ex3 (line 27)
v_t = l * omega.*cos(theta);
MATLAB CODE
%Arm Length
l=409;
%Initial Angle
beta = ((18)*(pi/180));
%Time period
T=0.1;
t=0:0.01:1;
theta = (pi/2) + beta*sin((2*t - T)*pi/(2*T));
%Diplacement of Plunger
H_t = l*(sin(theta) - cos(beta));
%Maximum Plunger Displacement
h_max = l*(1 - cos(beta));
%Velocity of Plunger
v_t = l * omega.*cos(theta);
%Acceleration of Plunger
a_t = l*((alpha.*cos(theta)) - (omega.^2).*sin(theta));
%Maximum acceleraion of Plunger in mm/s^2
a_max = max(a_t);
%Maximum acceleraion of Plunger in m/s^2
A_max = (a_max*10^-3);
%Angular Velocity of arm AB
omega = (pi*beta/T)*cos((2*t - T)*pi/(2*T));
%Angular Acceleration of arm AB
alpha = -(pi*pi/(T*T))*beta*sin((2*t -T)*pi/(2*T));
fprintf('Maximum displacement of plunger is %4.2f.\n' ,h_max);
fprintf('Maximum acceleration of plunger is %4.2f.\n' ,A_max);
% Reequired Graphs
% Graph 1: Time(s) vs. Angular Velocity (rads/s)
figure(1)
plot(t,omega)
xlabel('Time (s)')
ylabel('Angular Velocity (rad/s)')
% Graph 2: Time(s) vs. Displacement (mm)
figure(2)
plot(t,H_t)
xlabel('Time (s)')
ylabel('Displacement (mm)')
% Graph 3: Time(s) vs. Velocity (m/s)
figure(3)
plot(t,v_t)
xlabel('Time (s)')
ylabel('Velocity (m/s)')
% Graph 4: Time(s) vs. Acceleration (m/s^2)
figure(4)
plot(t,a_t)
xlabel('Time (s)')
ylabel('Acceleration (m/s^2)')

回答(1 个)

Kevin Holly
Kevin Holly 2021-11-24
I did not come across that issue when I defined omega as omega = (pi*beta/T)*cos((2*t - T)*pi/(2*T)); before running that line. You may have a different omega defined in your workspace.
%Arm Length
l=409;
%Initial Angle
beta = ((18)*(pi/180));
%Time period
T=0.1;
t=0:0.01:1;
theta = (pi/2) + beta*sin((2*t - T)*pi/(2*T));
%Angular Velocity of arm AB
omega = (pi*beta/T)*cos((2*t - T)*pi/(2*T));
%Diplacement of Plunger
H_t = l*(sin(theta) - cos(beta));
%Maximum Plunger Displacement
h_max = l*(1 - cos(beta));
%Velocity of Plunger
v_t = l * omega.*cos(theta)
v_t = 1×101
0.0000 367.1813 596.5728 599.6230 372.1168 0.0000 -372.1168 -599.6230 -596.5728 -367.1813 -0.0000 367.1813 596.5728 599.6230 372.1168 -0.0000 -372.1168 -599.6230 -596.5728 -367.1813 -0.0000 367.1813 596.5728 599.6230 372.1168 0.0000 -372.1168 -599.6230 -596.5728 -367.1813

类别

Help CenterFile Exchange 中查找有关 Automated Driving Toolbox 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by