0% found this document useful (0 votes)
16 views4 pages

Assignment

The document contains MATLAB code for simulating a four-bar linkage mechanism, calculating the angles of the coupler and follower links for various crank positions. It iterates through a specified number of crank angles, solving for the corresponding angles of the other links using vector loop equations. Additionally, it computes and plots the coupler curve based on the calculated positions of the coupler link.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Assignment

The document contains MATLAB code for simulating a four-bar linkage mechanism, calculating the angles of the coupler and follower links for various crank positions. It iterates through a specified number of crank angles, solving for the corresponding angles of the other links using vector loop equations. Additionally, it computes and plots the coupler curve based on the calculated positions of the coupler link.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

clc; clear; close all;

% Given link lengths (in mm)


d = 100; % Fixed link
a = 40; % Crank
b = 120; % Coupler
c = 80; % Follower

% Number of iterations
num_iterations = 10;

theta2_values = linspace(0, 360, num_iterations); % Crank angles in degrees

for iter = 1:num_iterations


theta2 = theta2_values(iter);
theta2_rad = deg2rad(theta2);

% Solve for theta3 and theta4 using vector loop equations


syms theta3 theta4

eq1 = a * cos(theta2_rad) + b * cos(theta3) - c * cos(theta4) - d;


eq2 = a * sin(theta2_rad) + b * sin(theta3) - c * sin(theta4);

sol = vpasolve([eq1, eq2], [theta3, theta4]);

% Convert solutions to degrees


if ~isempty(sol)
theta3_sol = rad2deg(double(sol.theta3));
theta4_sol = rad2deg(double(sol.theta4));
disp(['Iteration ', num2str(iter), ':']);
disp(table(theta3_sol, theta4_sol));
else
disp(['Iteration ', num2str(iter), ': No valid solution found']);
end
end

% Coupler Curve Calculation


num_points = 100; % Number of crank positions
theta2_range = linspace(0, 2*pi, num_points);
coupler_x = zeros(1, num_points);
coupler_y = zeros(1, num_points);

for i = 1:num_points
theta2_rad = theta2_range(i);
sol = vpasolve([
a * cos(theta2_rad) + b * cos(theta3) - c * cos(theta4) - d,
a * sin(theta2_rad) + b * sin(theta3) - c * sin(theta4)], [theta3,
theta4]);
if isempty(sol), continue; end

theta3_val = double(sol.theta3(1));
theta4_val = double(sol.theta4(1));

% Midpoint of coupler link


coupler_x(i) = a * cos(theta2_rad) + (b/2) * cos(theta3_val);
coupler_y(i) = a * sin(theta2_rad) + (b/2) * sin(theta3_val);
end

% Plot the coupler curve


figure;
plot(coupler_x, coupler_y, 'r-', 'LineWidth', 2);
axis equal;
xlabel('X Position (mm)');
ylabel('Y Position (mm)');
title('Coupler Curve for Fourbar Linkage');
grid on;

Iterations: Bx By Cx Cy Xc Yc 40.0000 0 136.6667 71.1024 88.3333 35.5512


39.9195 2.5370 139.4229 69.6120 89.6712 36.0745 39.6782 5.0637 141.6702 68.2905
90.6742 36.6771 39.2771 7.5700 143.4165 67.1938 91.3468 37.3819
38.7179 10.0459 144.6853 66.3568 91.7016 38.2013 38.0028 12.4813 145.5099
65.7940 91.7564 39.1377 37.1347 14.8665 145.9279 65.5029 91.5313 40.1847
36.1171 17.1918 145.9781 65.4677 91.0476 41.3297 34.9540 19.4479 145.6972
65.6640 90.3256 42.5559 33.6501 21.6256 145.1193 66.0625 89.3847 43.8441
32.2108 23.7163 144.2746 66.6316 88.2427 45.1739 30.6418 25.7115 143.1900
67.3396 86.9159 46.5256 28.9494 27.6032 141.8894 68.1563 85.4194 47.8797
27.1404 29.3837 140.3938 69.0532 83.7671 49.2184 25.2221 31.0459 138.7221
70.0043 81.9721 50.5251 23.2023 32.5830 136.8913 70.9861 80.0468 51.7846
21.0890 33.9890 134.9172 71.9777 78.0031 52.9834 18.8908 35.2581 132.8142
72.9604 75.8525 54.1093 16.6166 36.3853 130.5959 73.9181 73.6063 55.1517
14.2754 37.3659 128.2752 74.8366 71.2753 56.1012 11.8768 38.1961 125.8645
75.7036 68.8707 56.9498 9.4304 38.8725 123.3756 76.5087 66.4030 57.6906 6.9459
39.3923 120.8200 77.2433 63.8830 58.3178 4.4335 39.7535 118.2089 77.9002
61.3212 58.8269 1.9033 39.9547 115.5532 78.4736 58.7282 59.2141 -0.6346 39.9950
112.8634 78.9591 56.1144 59.4770 -3.1700 39.8742 110.1498 79.3535 53.4899
59.6139 -5.6926 39.5929 107.4225 79.6549 50.8650 59.6239 -8.1923 39.1521
104.6912 79.8623 48.2495 59.5072 -10.6590 38.5537 101.9652 79.9759 45.6531
59.2648 -13.0827 37.8000 99.2536 79.9965 43.0855 58.8983
-15.4538 36.8942 96.5651 79.9262 40.5557 58.4102 -17.7627 35.8398 93.9080
79.7677 38.0727 57.8037 -20.0000 34.6410 91.2901 79.5244 35.6450 57.0827
-22.1568 33.3028 88.7188 79.2006 33.2810 56.2517 -24.2244 31.8305 86.2010
78.8009 30.9883 55.3157 -26.1944 30.2300 83.7433 78.3308 28.7744 54.2804
-28.0590 28.5078 81.3515 77.7961 26.6463 53.1519 -29.8106 26.6708 79.0310
77.2030 24.6102 51.9369 -31.4421 24.7264 76.7867 76.5581 22.6723 50.6422
-32.9471 22.6824 74.6227 75.8683 20.8378 49.2753 -34.3193 20.5471 72.5430
75.1406 19.1118 47.8439 -35.5534 18.3291 70.5505 74.3823 17.4985 46.3557
-36.6443 16.0372 68.6479 73.6006 16.0018 44.8189 -37.5877 13.6808 66.8374
72.8027 14.6248 43.2418 -38.3797 11.2693 65.1204 71.9959 13.3703 41.6326
-39.0172 8.8124 63.4981 71.1872 12.2405 39.9998 -39.4976 6.3201 61.9712 70.3833
11.2368 38.3517 -39.8189 3.8022 60.5398 69.5909 10.3604 36.6966 -39.9799 1.2691
59.2038 68.8162 9.6120 35.0427 -39.9799 -1.2691 57.9627 68.0652 8.9914 33.3980
-39.8189 -3.8022 56.8160 67.3434 8.4985 31.7706
-39.0172 -8.8124 54.8012 66.0081 7.8920 28.5978 -38.3797 -11.2693 53.9309
65.4037 7.7756 27.0672 -37.5877 -13.6808 53.1504 64.8469 7.7814 25.5830
-36.6443 -16.0372 52.4584 64.3413 7.9070 24.1520 -35.5534 -18.3291 51.8538
63.8901 8.1502 22.7805 -34.3193 -20.5471 51.3354 63.4961 8.5080 21.4745
-32.9471 -22.6824 50.9025 63.1620 8.9777 20.2398 -31.4421 -24.7264 50.5543
62.8898 9.5561 19.0817 -29.8106 -26.6708 50.2905 62.6815 10.2400 18.0053
-28.0590 -28.5078 50.1110 62.5387 11.0260 17.0155 -26.1944 -30.2300 50.0161
62.4628 11.9108 16.1164 -24.2244 -31.8305 50.0065 62.4552 12.8910 15.3123
-22.1568 -33.3028 50.0833 62.5166 13.9633 14.6069 -20.0000 -34.6410 50.2484
62.6481 15.1242 14.0035 -17.7627 -35.8398 50.5039 62.8501 16.3706 13.5052
-15.4538 -36.8942 50.8526 63.1231 17.6994 13.1145 -13.0827 -37.8000 51.2981
63.4675 19.1077 12.8337 -10.6590 -38.5537 51.8446 63.8832 20.5928 12.6647
-8.1923 -39.1521 52.4971 64.3699 22.1524 12.6089 -5.6926 -39.5929 53.2616
64.9270 23.7845 12.6671 -3.1700 -39.8742 54.1446 65.5537 25.4873 12.8397
-0.6346 -39.9950 55.1540 66.2483 27.2597 13.1267 1.9033 -39.9547 56.2984
67.0087 29.1008 13.5270 4.4335 -39.7535 57.5875 67.8320 31.0105 14.0392 6.9459
-39.3923 59.0322 68.7142 32.9891 14.6609 9.4304 -38.8725 60.6443 69.6500
35.0373 15.3888 11.8768 -38.1961 62.4365 70.6327 37.1567 16.2183 14.2754
-37.3659 64.4226 71.6537 39.3490 17.1439 16.6166 -36.3853 66.6167 72.7018
41.6166 18.1583 18.8908 -35.2581 69.0333 73.7636 43.9621 19.2527 21.0890
-33.9890 71.6867 74.8222 46.3879 20.4166 23.2023 -32.5830 74.5900 75.8573
48.8961 21.6371 25.2221 -31.0459 77.7541 76.8448 51.4881 22.8995 27.1404
-29.3837 81.1867 77.7564 54.1635 24.1864 28.9494 -27.6032 84.8901 78.5601
56.9197 25.4785 30.6418 -25.7115 88.8593 79.2205 59.7505 26.7545 32.2108
-23.7163 93.0798 79.7001 62.6453 27.9919 33.6501 -21.6256 97.5251 79.9617
65.5876 29.1680 34.9540 -19.4479 102.1544 79.9710 68.5542 30.2616 36.1171
-17.1918 106.9111 79.7009 71.5141 31.2546 37.1347 -14.8665 111.7233 79.1364
74.4290 32.1349 38.0028 -12.4813 116.5049 78.2789 77.2539 32.8988 38.7179
-10.0459 121.1603 77.1508 79.9391 33.5524 39.2771 -7.5700 125.5905 75.7966
82.4338 34.1133 39.6782 -5.0637 129.7020 74.2818 84.6901 34.6091 39.9195
-2.5370 133.4142 72.6876 86.6668 35.0753 40.0000 -0.0000 136.6667 71.1024
88.3333 35.5512​

Plot :

You might also like