I think this is what you asked for
% Function to generate rotation matrix
rot_matrix = @(axis, theta) cos(theta) * eye(3) + ...
sin(theta) * [0, -axis(3), axis(2); axis(3), 0, -axis(1); -axis(2), axis(1), 0] + ...
(1 - cos(theta)) * (axis' * axis);
% Predefined values for theta1 and theta2
theta1_deg = 10; % Replace with desired value
theta2_deg = 10; % Replace with desired value
theta1 = deg2rad(theta1_deg); % Convert to radians
theta2 = deg2rad(theta2_deg); % Convert to radians
% Initial data and vectors
o2 = [0, 0, 0];
ain = [26, 0, 0];
input_axis = [0, 1, 0]; % Axis of rotation for ain (y-axis)
a_rotated = rot_matrix(input_axis, theta1) * (ain' - o2') + o2';
a_final = a_rotated';
cin = [122.95, -20, 0];
c_rotated = rot_matrix(input_axis, theta1) * (cin' - o2') + o2';
naxis = [sin(theta1), 0, cos(theta1)];
syms phi;
c_final_rotated = rot_matrix(naxis, phi) * (c_rotated - a_rotated) + a_rotated;
bin = [29.5, 30, 0];
o4 = [13.5, 30, 0];
output_axis = [0, 1, 0]; % Axis of rotation for bin (y-axis)
b1_rotated = rot_matrix(output_axis, theta2) * (bin' - o4') + o4';
b1_final = b1_rotated';
% Calculate the coupler
coupler = c_final_rotated' - b1_final;
coupler = subs(coupler, conj(phi), phi);
% Show the equation in terms of theta1, theta2, and phi
eq = norm(coupler) - 106;
disp('Equation in terms of theta1, theta2, and phi:');
disp(eq);
% Continue further calculations with substituted values of theta1 and theta2
syms t;
cos_phi = (1 - t^2) / (1 + t^2);
sin_phi = 2 * t / (1 + t^2);
% Substitute parametric forms into coupler components
coupler_parametric = subs(coupler, [cos(phi), sin(phi)], [cos_phi, sin_phi]);
disp('Parametric form of coupler:');
disp(coupler_parametric);
syms targetvalue; % It might be 3.5 ...
normsq = expand(sum(coupler_parametric.^2) - targetvalue^2);
normpoly = simplify(normsq * (t^2 + 1)^2);
vpa(expand(normpoly), 4);
tsolve = solve(normpoly, t, 'maxdegree', 4, 'returnconditions', true);
h = vpa(subs(tsolve.t, targetvalue, 106));
real_solutions = h(imag(h) == 0);
disp('Real roots:');
disp(real_solutions);
angles_rad = 2 * atan(real_solutions);
angles_deg = rad2deg(angles_rad);
disp('Angles in degrees before adjustment:');
disp(angles_deg);
phi = double(angles_rad(1));
c1_position = double(rot_matrix(naxis, phi) * (c_rotated - a_rotated) + a_rotated);
p = (c1_position' - a_final)';
angle = acosd(p(2) / norm(p));
disp('Final angle:');
disp(angle);