
ajouterDipole[A_,na_,nb_,Y_]:=Module[{P},
    P=A;
    P[[na,na]]=P[[na,na]]+Y;
    P[[na,nb]]=P[[na,nb]]-Y;
    P[[nb,nb]]=P[[nb,nb]]+Y;
    P[[nb,na]]=P[[nb,na]]-Y;
    Return[P];
]

ajouterResistance[A_,na_,nb_,R_]:=ajouterDipole[A,na,nb,1/R];
ajouterCapacite[A_,na_,nb_,C_]:=ajouterDipole[A,na,nb,C*s];
ajouterInductance[A_,na_,nb_,L_]:=ajouterDipole[A,na,nb,1/(L*s)];

ajouterSourceTensionContinue[A_,B_,na_,nb_,U_]:=Module[{P,Q,d,n},
    P=A;
    Q=B;
    d = Dimensions[A];
    n = d[[2]];
    P[[na]]=Table[0,{n}];
    P[[nb]]=Table[0,{n}];
    P[[na,na]]=1;
    P[[na,nb]]=-1;
    P[[nb,nb]]=-1;
    P[[nb,na]]=1;
    Q[[nb]]=-U;
    Return[{P,Q}];
]

ajouterSourceTensionSTCT[A_,B_,na_,nb_,nx_,ny_,g_]:=Module[{P,Q,d,n},
    P=A;
    Q=B;
    d = Dimensions[A];
    n = d[[2]];
    P[[na]]=Table[0,{n}];
    P[[nb]]=Table[0,{n}];
    P[[na,na]]=1;
    P[[na,nb]]=-1;
    P[[nb,nb]]=-1;
    P[[nb,na]]=1;
    P[[na,nx]]=-g;
    P[[na,ny]]=g;
    P[[nb,nx]]=-g;
    P[[nb,ny]]=g;
    Q[[nb]]=0;
    Return[{P,Q}];
]

ajouterMasse[A_,B_,n0_]:=Module[{P,Q,d,n},
    P=A;
    Q=B;
    d = Dimensions[A];
    n = d[[2]];
    P[[n0]]=Table[0,{n}];
    P[[n0,n0]]=1;
    Q[[n0]]=0;
    Return[{P,Q}];
]

definirEntree[A_,B_,ne_]:=Module[{P,Q,d,n},
    P=A;
    Q=B;
    d = Dimensions[A];
    n = d[[2]];
    P[[ne]]=Table[0,{n}];
    P[[ne,ne]]=1;
    Q[[ne]]=-1;
    Return[{P,Q}];
]
                
transfert[A_,B_,ns_]:=Module[{v},
    v=LinearSolve[A,-B];
    Return[v[[ns]]];
]
                
bodeGain[h_,lgmin_,lgmax_,Gmin_,Gmax_]:=Module[{},
    Return[Plot[20*Log[10,Abs[h/.{s->I*2*Pi*10^p}]],{p,lgmin,lgmax},PlotRange->{{lgmin,lgmax},{Gmin,Gmax}},AxesLabel->{"log f","GdB"}]];
]
bodePhase[h_,lgmin_,lgmax_]:=Module[{},
    Return[Plot[180/Pi*Arg[h/.{s->I*2*Pi*10^p}],{p,lgmin,lgmax},AxesLabel->{"log f","phi"}]];
]
                
reponseEchelon[h_,tmax_,vmin_,vmax_]:=Module[{r},
    r=InverseLaplaceTransform[h/s,s,t];
    Return[Plot[r/.{t->temps},{temps,0,tmax},PlotRange->{{0,tmax},{vmin,vmax}},AxesLabel->{"t","V"}]];
]
                
reponseImpulsion[h_,tmax_,vmin_,vmax_]:=Module[{r},
    r=InverseLaplaceTransform[h,s,t];
    Return[Plot[r/.{t->temps},{temps,0,tmax},PlotRange->{{0,tmax},{vmin,vmax}},AxesLabel->{"t","V"}]];
]
                