## Analyse réelle

Exercice 1

sum(1/i^2,i,1,inf),simpsum;

sum(1/i^2,i,3,inf),simpsum;

Exercice 2

f:1/(exp(x)-1)$

limit(f,x,0);

g:x*f$
limit(g,x,0);

taylor(g,x,0,4);

taylor(f,x,0,3);

Exercice 3

f:a/(x-b)^n;

diff(f,x);

integrate(subst([n=0],f),x);

integrate(subst([n=1],f),x);

assume(n>1)$
integrate(f,x);

g:(2*x-1)/((x-1)*(x-2));

diff(g,x),ratsimp;

integrate(g,x);
%,logcontract;

Exercice 4

I1:integrate(1/(1+x^2),x,-1,1);

I2:integrate((2*x-5)/(x^2-5*x+6),x,-1,1);
%,logcontract;

if numer#false then numer:false else numer:true;

fpprintprec:3$
I1,ev;
I2,ev;

Exercice 5

if numer#false then numer:false else numer:true;

f:sqrt(x);g:x^(3/2);
wxplot2d([f,g],[x,0,1.5]);

wxdraw2d ( filled_func =f , 
    fill_color = green , 
    explicit (g ,x ,0 ,1),
    filled_func = false ,
    explicit (f ,x ,0 ,1) , 
    explicit (g ,x ,0 ,1)  ) ;

solve ( f = g ) ;

integrate (f -g ,x ,0 ,1) ;

Exercice 6

kill(all)$
depends(y,x)$

F(x,y):=-x*y+2*x;

edo:'diff(y,x)=F(x,y);
sol:ode2(edo,y,x);

ic1(sol,x=0,y=1);
solexacte:rhs(%)$

wxplot2d(solexacte,[x,-5,5]);

/* Euler Explicite*/
phi1(x,y,h):=F(x,y)$
/* RK4 */
k1(x,y,h):=F(x,y)$
k2(x,y,h):=F(x+h/2,y+h/2*k1(x,y,h))$
k3(x,y,h):=F(x+h/2,y+h/2*k2(x,y,h))$
k4(x,y,h):=F(x+h,y+h*k3(x,y,h))$
phi4(x,y,h):=1/6*(k1(x,y,h)+2*k2(x,y,h)+2*k3(x,y,h)+k4(x,y,h))$

y:1$
z:1$
x:0$
h:0.5$
liste1:[y]$
liste4:[z]$
listeX:[x]$
while x<5 do(
    y:y+h*phi1(x,y,h),
    z:z+h*phi4(x,z,h),
    x:x+h,
    liste1:endcons(y,liste1),
    liste4:endcons(z,liste4),
    listeX:endcons(x,listeX)
);

remvalue(x,y)$
taille_lignes:1$
couleur_lignes:1/*bleu*/$
taille_points:1$
couleur_points1:2/*rouge*/$
type_points1:1$
couleur_points4:3/*rouge*/$
type_points4:2$
wxplot2d(
    [
        [discrete,listeX,liste1],
        [discrete,listeX,liste4],
        solexacte
    ],
    [x,0,5],[y,1,2.1],
    [style,
        [points,taille_points,couleur_points1,type_points1],
        [points,taille_points,couleur_points4,type_points4],
        [lines,taille_lignes,couleur_lignes]
    ],
    [legend, "EE", "RK4", "exacte"]
);

solexacte;

## Algèbre linéaire

Exercice 7

A:matrix([1,5,-3],[2,11,1],[2,9,-11])$
B:matrix([1,0,-1],[4,-1,-2],[-2,0,1])$
'A=A;
'B=B;

A+B;

A.B;

P1:zeromatrix(3,3)$
for i from 1 thru 3 do(
    for j from 1 thru 3 do(
        P1[i,j]:sum(A[i,k]*B[k,j],k,1,3)
));

P1;

P2:zeromatrix(3,3)$
for i from 1 thru 3 do(
    for j from 1 thru 3 do(
        P2[i,j]:A[i,j]*B[i,j]
));

P2;

A*B;

determinant(A);
iA:invert(A);
iA.A;

determinant(B);
iB:invert(B);
iB.B;

eigenvalues(B);

eigenvectors(B);

determinant(B-λ*ident(3));

s:solve(%,λ);

normaliseInf(v):=block([maxi],
    lmax:lmax(v),
    lmin:lmin(v),
    maxi:if lmax>-lmin then lmax else lmin,
    return(v/maxi)
    )$

normaliseInf([-1,0,3]);

v:[1,0,-3]$
max(lmax(v),-lmin(v));

λ1:part(s[1],2);
nullspace(B-λ1*ident(3));
v1:list_matrix_entries(args(%)[1]);
normaliseInf(v1),fullratsimp,algebraic:true;

λ2:part(s[2],2);
nullspace(B-λ2*ident(3));
v2:list_matrix_entries(args(%)[1]);
normaliseInf(v2),fullratsimp,algebraic:true;

λ3:part(s[3],2);
nullspace(B-λ3*ident(3));
v3:list_matrix_entries(args(%)[1]);
normaliseInf(v3),fullratsimp,algebraic:true;

Exercice 8

s:S0*sin(2*%pi*f0*x)+1/(x^2+1)$
sol:ode2(-'diff(u,x,2)=s,u,x)$
solAnalytique:rhs(bc2(sol,x=0,u=u0,x=l,u=ul));
solAnalytique,logcontract;

S0:100$f0:10$u0:1$ul:2$l:1$

wxplot2d(solAnalytique,[x,0,l]);

FDM(n):=block([A,S,b],
    h:l/(n+1),
    A:zeromatrix(n,n),
    S:zeromatrix(n,1),
    b:zeromatrix(n,1),
    for i from 1 thru n do(
        for j from 1 thru n do(
        A[i,j]:if abs(i-j)=1 then -1 else(
                if i=j then 2 else 0
            )    
        ),
    S[i,1]:ev(h^2*subst([x=i*h],s)),
    b[i,1]:if i=1 then u0 else(
        if i=n then ul else 0)
    ),
    return(list_matrix_entries(invert(A).(S+b)))
)$

n:20$h:l/(n+1)$
U: append([u0],FDM(n),[ul])$
listeX:makelist(i*h,i,0,n+1)$
wxplot2d([
        [discrete,listeX,U],
        solAnalytique
    ],
    [x,0,l],
    [style,
        [points,taille_points,couleur_points1,type_points1],
        [lines,taille_lignes,couleur_lignes]
    ],
    [legend, "FDM","Analytique"]
);