clear all
close all
clc

syms Ax Ay FN A X F Bx By Dx Dy q
syms R C L

A=atan(R*sin(q)/(C+R*cos(q)));
X=R*sin(q)/sin(A);

K=[1 0        0         0 0 0 -sin(A) 0;
   0 1        0         0 0 0  cos(A) 0;
   0 0        0         0 0 0       X 0;
   0 0        1         0 0 0  sin(A) 0;
   0 0        0         1 0 0 -cos(A) 0;
   0 0       -1         0 1 0       0 0;
   0 0        0        -1 0 1       0 0;
   0 0 R*sin(q) -R*cos(q) 0 0       0 1];

f=[0; F; F*L*cos(A); 0; 0; 0; 0; 0];

U=K^(-1)*f;
Ax=U(1);
Ay=U(2);
Bx=U(3);
By=U(4);
Dx=U(5);
Dy=U(6);
FN=U(7);
M=U(8);

MFL=simple(subs(M/(F*L)));

C=11;
R=5;
F=10;
L=20;
q=(1:360)*pi/180;

MFLcalc=eval(MFL);
Axcalc=eval(Ax);
Aycalc=eval(Ay);
Bxcalc=eval(Bx);
Bycalc=eval(By);
Dxcalc=eval(Dx);
Dycalc=eval(Dy);

%%
figure(1)
plot(q*180/pi,MFLcalc)
grid on
xlabel('q (^o)')  
ylabel('M/FL')
title('Posição do elo de saida')
%%
figure(2)
subplot(2,3,1)
plot(q*180/pi,Axcalc)
grid on
xlabel('q (^o)')  
ylabel('Ax (N)')
subplot(2,3,2)
plot(q*180/pi,Bxcalc)
grid on
xlabel('q (^o)')  
ylabel('Bx (N)')
subplot(2,3,3)
plot(q*180/pi,Dxcalc)
grid on
xlabel('q (^o)')  
ylabel('Dx (N)')

subplot(2,3,4)
plot(q*180/pi,Aycalc)
grid on
xlabel('q (^o)')  
ylabel('Ay (N)')
subplot(2,3,5)
plot(q*180/pi,Bycalc)
grid on
xlabel('q (^o)')  
ylabel('By (N)')
subplot(2,3,6)
plot(q*180/pi,Dycalc)
grid on
xlabel('q (^o)')  
ylabel('Dy (N)')
