What şs wrong ?

2 Ansichten (letzte 30 Tage)
Furkan
Furkan am 23 Jan. 2024
Kommentiert: Furkan am 23 Jan. 2024
% Mechanism parameters
AB = [0.09, 0.15, 0.22, 0.16]; % Link lengths AB (m)
BC = [0.40, 0.67, 1.00, 0.70]; % Link lengths BC (m)
CE = [0.25, 0.45, 0.65, 0.50]; % Link lengths CE (m)
CD = [0.12, 0.22, 0.35, 0.25]; % Link lengths CD (m)
EF = [0.21, 0.32, 0.60, 0.48]; % Link lengths EF (m)
a = [0.22, 0.33, 0.55, 0.90]; % Link lengths a (m)
b = [0.35, 0.60, 0.40, 0.60]; % Link lengths b (m)
C = [0.40, 0.65, 1.20, 0.70]; % Link lengths C (m)
n = [60, 135, 240]; % Angular speeds (rpm)
rpm_to_rad_per_sec = 2*pi/60; % Conversion factor from RPM to rad/s
% Input link's angular position values
input_angles = linspace(0, 2*pi, 100); % Assuming 100 points for a full rotation
% Initialize arrays to store results
angular_displacement = zeros(length(input_angles), length(AB));
angular_velocity = zeros(length(input_angles), length(AB));
angular_acceleration = zeros(length(input_angles), length(AB));
linear_displacement = zeros(length(input_angles), length(AB));
linear_velocity = zeros(length(input_angles), length(AB));
linear_acceleration = zeros(length(input_angles), length(AB));
% Numerical solution
for i = 1:length(input_angles)
% Calculate kinematics for the given input angle
for j = 1:length(AB)
% Angular displacement
angular_displacement(i, j) = acos((AB(j)^2 + BC(j)^2 - CE(j)^2) / (2 * AB(j) * BC(j)));
% Angular velocity (derivative of angular displacement)
angular_velocity(i, j) = -AB(j) * sin(angular_displacement(i, j)) * n(j) * rpm_to_rad_per_sec;
% Angular acceleration (derivative of angular velocity)
angular_acceleration(i, j) = -AB(j) * cos(angular_displacement(i, j)) * n(j)^2 * rpm_to_rad_per_sec^2;
% Linear displacement
linear_displacement(i, j) = AB(j) * sin(angular_displacement(i, j));
% Linear velocity (derivative of linear displacement)
linear_velocity(i, j) = AB(j) * cos(angular_displacement(i, j)) * angular_velocity(i, j);
% Linear acceleration (derivative of linear velocity)
linear_acceleration(i, j) = -AB(j) * sin(angular_displacement(i, j)) * angular_velocity(i, j)^2 ...
+ AB(j) * cos(angular_displacement(i, j)) * angular_acceleration(i, j);
end
end
% Plotting
figure;
% Plot Angular Displacement
subplot(3, 2, 1);
plot(input_angles, rad2deg(angular_displacement));
title('Angular Displacement (degrees)');
% Plot Angular Velocity
subplot(3, 2, 2);
plot(input_angles, rad2deg(angular_velocity));
title('Angular Velocity (degrees/s)');
% Plot Angular Acceleration
subplot(3, 2, 3);
plot(input_angles, rad2deg(angular_acceleration));
title('Angular Acceleration (degrees/s^2)');
% Plot Linear Displacement
subplot(3, 2, 4);
plot(input_angles, linear_displacement);
title('Linear Displacement (m)');
% Plot Linear Velocity
subplot(3, 2, 5);
plot(input_angles, linear_velocity);
title('Linear Velocity (m/s)');
% Plot Linear Acceleration
subplot(3, 2, 6);
plot(input_angles, linear_acceleration);
title('Linear Acceleration (m/s^2)');

Antworten (1)

Rishi
Rishi am 23 Jan. 2024
Hi Furkan,
I understand from your query that you want to know the mistake in the provided code.
The array 'n' is defined as [60, 135, 240] in the following line:
n = [60, 135, 240]; % Angular speeds (rpm)
The error occurs in the following line, when the value of 'j' becomes 4. During this iteration, the code tries to acces the value of 'n(4)', which is wrong and hence, gives the following error:
% Angular velocity (derivative of angular displacement)
angular_velocity(i, j) = -AB(j) * sin(angular_displacement(i, j)) * n(j) * rpm_to_rad_per_sec;
Index exceeds the number of array elements. Index must not exceed 3.
To get rid of the error, you can define the array 'n' with 4 elements. For e.g, you can redefine 'n' as follows:
n = [60, 135, 240, 350]; % Angular speeds (rpm) (350 is a random value, replace it with the one that suits your case)
Hope this helps!
  4 Kommentare
Rishi
Rishi am 23 Jan. 2024
The error occurs in the following line of code:
% Acceleration analysis
fa = [-AB*cos(thQ(k))((w1(k))^2) - BC*cos(th2(k))((w2(k))^2) - CD*cos(th3(k))*((w3(k))^2) - AB*sin(thQ(k))*acc1(k); ...
AB*cos(thQ(k))acc1(k) - BC*sin(th2(k))((w2(k))^2) - CD*sin(th3(k))((w3(k))^2) - AB*sin(thQ(k))((w1(k))^2)];
I am assuming you want to multiply the terms within the parantheses. To do so, you need to include the asterisk ('*') sign between the terms.
Here is the line after correction:
% Acceleration analysis
fa =[-AB*cos(thQ(k))*((w1(k))^2) - BC*cos(th2(k))*((w2(k))^2) - CD*cos(th3(k))*((w3(k))^2) - AB*sin(thQ(k))*acc1(k); AB*cos(thQ(k))*acc1(k) - BC*sin(th2(k))*((w2(k))^2) - CD*sin(th3(k))*((w3(k))^2) - AB*sin(thQ(k))*((w1(k))^2)];
Hope this helps!
Furkan
Furkan am 23 Jan. 2024
I'm sorry to bother you, but I'm trying to find a solution for this mechanism. Please help me. If you want, I would like to reach you via e-mail.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R12.1

Community Treasure Hunt

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

Start Hunting!

Translated by