syms l_1 l_2 real
syms phi_0 phi_1 phi_2 real
syms L_0 real

% 添加假设条件，使表达式在实数域
assumeAlso(l_1 > 0);
assumeAlso(l_2 > 0);
assumeAlso(L_0 > 0);

%雅可比矩阵
j11 = -l_1*sin(phi_1);
j12 = -l_2*sin(phi_2);
j21 =  l_1*cos(phi_1);
j22 =  l_2*cos(phi_2);

J_0 = [j11 j12; 
       j21 j22]

%

R = [cos(phi_0-pi/2) -sin(phi_0-pi/2);
     sin(phi_0-pi/2)  cos(phi_0-pi/2)]
M = [0 -1/L_0;
     1     0]
J_T = simplify(J_0.'*R*M)
J = J_T.'

%

% 下面尝试直接解雅可比矩阵
syms l_1 l_2 real
syms phi_0 phi_1 phi_2 real
syms L_0 real

x_c = l_1*cos(phi_1) + l_2*cos(phi_2);
y_c = l_1*sin(phi_1) + l_2*sin(phi_2);
L_0 = sqrt(x_c*x_c + y_c*y_c);
phi_0 = atan2(y_c,x_c);

q = [L_0;phi_0];
x = [phi_1;phi_2];
J_ = jacobian(q,x);
J = simplify(J_)

%

% 下面尝试用传统力学求解T1 T2
syms phi0 phi1 phi2
syms L0 l1 l2
syms theta
syms T1 T2
syms F0 Tp

theta = acos((l2*l2+L0*L0-l1*l1)/(2*l2*L0));

T2 = -F0*l2*sin(theta)
T1 = Tp+T2

T = [T1;T2]


% 奇怪的算法
% theta = pi-phi0+phi2;
% 
% % 定义方程
% %eq1 = T2/l2 * sin(theta) == T1/L0;
% eq1 = T2/l2 * cos(theta) == F0;
% eq2 = T1/L0 + T2/l2 * sin(theta) == Tp;
% 
% % 求解方程组
% sol = solve([eq1, eq2], [T1, T2]);
% 
% % 显示解
% T1_sol = sol.T1
% T2_sol = sol.T2
% T = [T1_sol;T2_sol]