function [dxdt] = Function(t,x,Aa,Ab,V0B,l1,s,F_LVDT,m_T,vs,delta,toll_v,c1,Fc1,Fs,c2,Fc2,time,cd_ISO,b,bS,Rg,Ts,Pa,V,Ps,coeff,V0A)

global a


V_mod=interp1(time,V,t);

if V_mod>5 
    gB=0;
    A_eqmanS=abs((-4.929e-07)*(10-V_mod)+2.372e-06); 
    cond=A_eqmanS<0;
    A_eqmanS(cond)=0;
    cond=x(1)/Pa<=bS; %subsonico
    gA(cond)=-cd_ISO*sqrt(293/Ts)*0.686/sqrt(Rg*Ts)*x(1)*A_eqmanS*sqrt(1-((x(1)/Pa-bS)/(1-bS))^2); 
    cond=x(1)/Pa>bS; %sonico
    gA(cond)=-cd_ISO*sqrt(293/Ts)*0.686/sqrt(Rg*Ts)*x(1)*A_eqmanS; 
       
elseif V_mod==5 
    gA=0;
    gB=0;

else
    gB=0;
    A_eqman=abs((-3.953e-07)*V_mod+1.913e-06);
    cond=A_eqman<0;
    A_eqman(cond)=0;
    cond=x(1)/Ps>=b; %subsonico
    gA(cond)=cd_ISO*sqrt(293/Ts)*0.686/sqrt(Rg*Ts)*Ps*A_eqman*sqrt(1-((x(1)/Ps-b)/(1-b))^2);
    cond=x(1)/Ps<b; %sonico
    gA(cond)=cd_ISO*sqrt(293/Ts)*0.686/sqrt(Rg*Ts)*Ps*A_eqman;
      

end

GA=gA*coeff;
GB=gB*coeff*0;

Fp=(x(1)-Pa)*Aa-(x(2)-Pa)*Ab;
v=x(4);
%1)Caso di velocità nulla
if abs(v)-toll_v<=0  
cond=abs(Fp-F_LVDT)<Fs;
Ff(cond)=Fp-F_LVDT; 
cond=abs(Fp-F_LVDT)>=Fs;
Ff(cond)=Fs*sign(Fp-F_LVDT);

else
%2a) Velocità crescenti
cond=a>=0;
Ff(cond)=c1*v+(Fc1+(Fs-Fc1)*exp(-(abs(v)./vs).^delta)).*sign(v);
%2a) Velocità decrescenti
cond=a<0;  
Ff(cond)=c2*v+Fc2*sign(v);

end
F_att=(Ff);

dxdt(1,1)=(Rg*Ts*GA)/(V0A+Aa*(l1+x(3)))-(x(1)*Aa*x(4))/(V0A+Aa*(l1+x(3)));
dxdt(2,1) =Ab*x(2)/(V0B+Ab*(s-l1-x(3)))*x(4);
dxdt(3,1) =x(4);
dxdt(4,1) =1/m_T*(Fp-F_att-F_LVDT);

a=dxdt(4,1);

end