"où $\\ddot{\\alpha}(t)$ désigne la dérivée seconde de l'angle $\\alpha$ par rapport au temps $t$. \n",
"\n",
"On prend ici comme variable d'état qui décrit le système $x(t)=(x_1(t),x_2(t))=(\\alpha(t), \\dot{\\alpha}(t))$. Le système différentiel du premier ordre que l'on obtient s'écrit alors\n",
où $\ddot{\alpha}(t)$ désigne la dérivée seconde de l'angle $\alpha$ par rapport au temps $t$.
On prend ici comme variable d'état qui décrit le système $x(t)=(x_1(t),x_2(t))=(\alpha(t), \dot{\alpha}(t))$. Le système différentiel du premier ordre que l'on obtient s'écrit alors
$$
\left\{\begin{array}{l}
\dot{x}_1(t) = x_2(t)\\
\dot{x}_2(t) = -\frac{g}{l}\sin(x_1(t))-kx_2(t)\\
x_1(0) = x_{0,1}=\alpha_0\\
x_2(0) = x_{0,2}=\dot{\alpha}_0
\end{array}\right.
$$
### Cas où la fonction second membre renvoie xpoint
%% Cell type:code id: tags:
``` julia
function pendule(x,p,t)
# second member of the IVP
# x : state
# real(2)
# p : parameter vector
# t : time, variable not use here
# real
# Output
# xpoint : vector of velocity
# same as x
g=p[1];l=p[2];k=p[3]
xpoint=similar(x)
xpoint[1]=x[2]
xpoint[2]=-(g/l)*sin(x[1])-k*x[2]
returnxpoint
end
```
%% Cell type:code id: tags:
``` julia
# Main
#
g=9.81;l=10;k=0;
p=[g,l,k]# constantes
theta0=pi/3
t0=0.
tf=3*pi*sqrt(l/g)*(1+theta0^2/16+theta0^4/3072)# 2*approximation de la période
tspan=(t0,tf)# instant initial et terminal
x0=[theta0,0]# état initial
prob=ODEProblem(pendule,x0,tspan,p)# défini le problème en Julia
sol=solve(prob)# réalise l'intégration numérique
plot(sol,label=["x_1(t)""x_2(t)"])
```
%% Cell type:markdown id: tags:
### Cas où xpoint est le premier argument modifié de la fonction second membre
%% Cell type:code id: tags:
``` julia
function pendule1!(xpoint,x,p,t)
# second member of the IVP
# x : state
# real(2)
# p : parameter vector
# t : time, variable not use here
# real
# Output
# xpoint : vector of velocity
# same as x
g=p[1];l=p[2];k=p[3]
xpoint=similar(x)
xpoint[1]=x[2]
xpoint[2]=-(g/l)*sin(x[1])-k*x[2]
returnnothing
end
```
%% Cell type:code id: tags:
``` julia
# Main
#
g=9.81;l=10;k=0;
p=[g,l,k]# constantes
theta0=pi/3
t0=0.
tf=3*pi*sqrt(l/g)*(1+theta0^2/16+theta0^4/3072)# 2*approximation de la période
tspan=(t0,tf)# instant initial et terminal
x0=[theta0,0]# état initial
prob=ODEProblem(pendule1!,x0,tspan,p)# défini le problème en Julia
sol=solve(prob)# réalise l'intégration numérique
plot(sol,label=["x_1(t)""x_2(t)"])
```
%% Cell type:markdown id: tags:
L'instruction `xpoint = similar(x)`**crée une variable locale xpoint** et on a perdu le paramètre formel `xpoint`.
%% Cell type:code id: tags:
``` julia
function pendule2!(xpoint,x,p,t)
# second member of the IVP
# x : state
# real(2)
# p : parameter vector
# t : time, variable not use here
# real
# Output
# xpoint : vector of velocity
# same as x
g=p[1];l=p[2];k=p[3]
xpoint[1]=x[2]
xpoint[2]=-(g/l)*sin(x[1])-k*x[2]
returnnothing
end
```
%% Cell type:code id: tags:
``` julia
# Main
#
g=9.81;l=10;k=0.;
p=[g,l,k]# constantes
theta0=pi/3
t0=0.
tf=3*pi*sqrt(l/g)*(1+theta0^2/16+theta0^4/3072)# 2*approximation de la période
tspan=(t0,tf)# instant initial et terminal
x0=[theta0,0]# état initial
prob=ODEProblem(pendule2!,x0,tspan,p)# défini le problème en Julia
sol=solve(prob)# réalise l'intégration numérique
plot(sol,label=["x_1(t)""x_2(t)"])
```
%% Cell type:markdown id: tags:
## Diagrammes de phases
%% Cell type:code id: tags:
``` julia
# Main
#
g=9.81;l=10;k=0.;# si k = 0.15 donc on a un amortissement
p=[glk]
plot()
fortheta0in0:(2*pi)/10:2*pi
theta0_princ=theta0
tf=3*pi*sqrt(l/g)*(1+theta0_princ^2/16+theta0_princ^4/3072)# 2*approximation of the period