0% ont trouvé ce document utile (0 vote)
28 vues4 pages

Examen MATLAB : Méthodes Numériques

Mathlab

Transféré par

alassane coulibaly
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
28 vues4 pages

Examen MATLAB : Méthodes Numériques

Mathlab

Transféré par

alassane coulibaly
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd

EXAMEN MATLAB

Travaux pratique 1

//1. Déclarons la fonction f(x)


x=[-10:0.001:10]
deff ('y=f(x)','y=x.^2-2')
figure
plot(x,f)
xgrid
a=0 ;b=3 ;
while abs(a-b)>0.01
c=(a+b)/2:k=k+1
if f(a)×f(b)<0
b=c ; c=(a+b)/2
else a=c ; c=(a+b)/2
end
end
sol=c
nb=k
k a b C f(a) f(b) f(c) Ɛ
1 0 3 1.5 - + + 0.01
2 0 1.5 0.75 - + - 0.01
3 0.75 1.5 1.125 - + - 0.01
4 0.125 1.5 1.3125 - + - 0.01
//2. Méthode des points fixes
//les formes possibles de la fonctions g(x)
x=[0:3]
deff('y=fx','y=x.*^2-2')
g(x)=x-f(x)
eps=0.001
a=0
b=3
for k=k+1
end
(a+b)/2
while err>eps
x1=g(a)
x2=g(b)

//3. Méthode de newton


function [sol, info, niter]=newtonp (f, fprise, itmax, epsilon, xzero)
niter=0 //init du compteur d'itération
xzero=0 //init du premier point
info=0 //init info=0= pas de convergence
while niter<itmax
x1=x-(x.^2-2)/2.*x
if abs(f(x))<epsilon
info=1
break
end

p. 1
end
sol=x
endfunction
deff ('y=hsf(x)','y=x.^2-2')
deff('y=hsfprise(x)','y=2.*x')
[s i n]=newton1(f,2.*x,10,1.e-3,1)
sqrt(2)

Travaux pratique 2
1. //donnons l'écriture matricielle de s
A=[3,-2,1;2,1,1;4,-3,2]
B=[2;7;4]
// calculons X=inv(A)*B
X=inv(A)*B
2. //Méthode cramer
det(A)
C=[2,-2,1;7,1,1;4,-3,2]
det(C)
D=[3,2,1;2,7,1;4,4,2]
det(D)
E=[3,-2,2;2,1,7;4,-3,4]
det(E)
X=det(C)/det(A)
Y=det(D)/det(A)s
Z=det(E)/det(A)
3. //Méthode de gausse
function x=gaussepremier(A, B)
//récupération des taille Aet B
[n m]=size(A)
[p q]=size(B)
//test si les matrice A est bien carrée
if n~=m then
error('erreur: matrice A non carrée')
if p~=q then
error('erreur: B doit être un vecteur colonne')
if p~=n then
error('erreur: matrice A et B doivent avoir le même nombre de ligne')
end
A(:n+1)=B
//boucle sur la colonne
for j=1-n
//boucle sur les lignes qui sont sous la diagonale
for i=j+1:n
//test pour vérifier que le pivot est bien non nul
if abs(A(j,j))<0
error('erreur: pivot nul')
end
A(i,:)=A(i,:)-A(i,j)/A(j,j)*A(j,:)
end

p. 2
endfunction
4. //La matrice de JACOBI. Pour résoudre Ax=B
//A= H-S-F
//H:diag; S : triangle inf: F: triangle sup
A=[4,-2,1;2,4,1;4,-3,8]
B=[2;7;4]

function [sol, iter, info]=myjacobi(A, B, nmaxit, tol)


//vérification :aucun terme de la diagonal de A n'est nul
if~and(diag(A))then
error('erreur :présence d un zéro sur la diagonale de A')
end
//décomposition de A =D E-F
D=diag(diag(A))
E=-triu(A)+D
F=-tril(A)+D
//initialisation sol=B
iter=0//aucun itération
info=0//pas convergent
//boucle itérative de résolution
for k=1:nmaxit
sol=inv(D)*((E+F)*sol+B)
if max(abs(A*sol-B))<tol
info=1
niter =k
break
end
end
[sol,niter,info]= myjacobi(A,B,100,0.01)
Endfunction
//méthode gausseidel
A=[4,-2,1;2,4,1;4,-3,8]
B=[2;7;4]
function [X]=mgausseidl(A, B, n, X0)
D=diag(diag(A))
E=D-triu(A)
F=D-tril(A)
del=inv(D-E)
g=del*F;
c=del*B
for i=1:n
x=g*X+c;
end
endfunction

//Résoudre S par la Méthode CRAMER


tic
A=[3,-2,1;2,1,1;4,-3,2]
B=[2;7;4]
det (A)

p. 3
C=[2,-2,1;7,1,1;4,-3,2]
det(C)
D=[3,2,1;2,7,1;4,4,2]
det(D)
E=[3,-2,2;2,1,7;4,-3,4]
det(E)
X=det(C)/det(A)
Y=det(D)/det(A)
Z=det(E)/det(A)
S=[X,Y,Z]
toc
Conclusion
La méthode cramer est la plus rapide que les méthodes gauss gaussiedel et Jacobi

Travaux pratique 3
1. //Traçons la courbe de résistance en fonction de la température
X=[15.11,14.04,9.28,6.44,4.44,2.9]
Y=[15,20,30,40,50,60]
xlabel('axe des abscisse résistance')
ylabel('axe des ordonnées température')
figure
plot(X,Y,"Y")
xgrid
legend
2. //polynôme de façon analytique
3. //la méthode de Lagrange
y=[15.11,14.04,9.28,6.44,4.44,2.9]
x=[15,20,30,40,50,60]
x=poly(0,'x')
L0=(x-20)*(x-30)*(x-40)*(x-50)*(x-60)/(15-20)*(15-30)*(15-40)*(15-50)*(15-60)
L1=(x-15)*(x-30)*(x-40)*(x-50)*(x-60)/(20-15)*(20-30)*(20-40)*(20-50)*(20-60)
L2=(x-15)*(x-20)*(x-40)*(x-50)*(x-60)/(30-15)*(30-20)*(30-40)*(30-50)*(30-60)
L3=(x-15)*(x-20)*(x-30)*(x-50)*(x-60)/(40-15)*(40-20)*(40-30)*(40-50)*(40-60)
L4=(x-15)*(x-20)*(x-30)*(x-40)*(x-60)/(50-15)*(50-20)*(50-30)*(50-40)*(50-60)
L5=(x-15)*(x-20)*(x-30)*(x-40)*(x-50)/(60-15)*(60-20)*(60-30)*(60-40)*(60-50)
P=('15.11*L0+14.04*L1+9.28*L2+6.44*L3+4.44*L4+2.9*L5')
D’après la courbe la résistance de la température de 37°C est égale à 7.5.

p. 4

Common questions

Alimenté par l’IA

In Gauss-Seidel, each variable is updated in an iterative loop using previously computed values, making it more efficient. It ensures convergence by partially using earlier updates to reduce computation errors. MATLAB initializes matrices D, E, and F, and updates using these matrices to iteratively minimize the residual of Ax=B .

Determinant calculations in Cramer's Rule are used to express each variable uniquely by replacing the corresponding column in matrix A with vector B. This technique leverages the property of determinants to handle adjustments across the matrix, which facilitates direct computation of variable values assuming a non-zero determinant of A .

Cramer's Rule involves calculating determinants of matrices to find each variable, where each matrix replaces one column of the main coefficient matrix with the constant vector. The efficiency tends to be lower in terms of computation compared to iterative methods like Gauss-Seidel and Jacobi, as it explicitly requires finding determinants, which can be computationally expensive. However, the conclusion drawn in the document highlights its speed for certain equations .

Newton's Method aids in finding roots by iteratively refining an estimate of the root, using tangents of the function. In the given MATLAB example, it is initialized by setting 'niter=0', 'xzero=0', and 'info=0'. The iteration continues until the change is below a specified epsilon, indicating convergence .

The Lagrange interpolation uses polynomials L0, L1, ..., L5, constructed by considering all data points except the desired point. Each polynomial is calculated using the differences between x values and solved iteratively. MATLAB calculates the interpolation by substituting into these polynomials and then combining them using corresponding y values .

The MATLAB code for Gaussian elimination checks if matrix A is square (n=m), if B is a column vector, and if both A and B have the same number of rows. It also checks for non-zero pivot elements to avoid division by zero errors .

The initial vector provides a starting point that significantly affects the convergence speed and accuracy of iterative methods. A poor initial guess can lead to divergence. In the given examples, it is directly retrieved from the vector B or assumed zeros. The vector's proximity to the true solution influences iteration count and convergence success .

The Bisection Method is implemented by iteratively narrowing down an interval [a, b] where the root lies. The key components of the method in MATLAB include initializing the interval, computing the midpoint c=(a+b)/2, checking the signs of the function at the endpoints and the midpoint, and updating a or b based on the sign change until the interval is sufficiently small (abs(a-b)>0.01).

The Jacobi Method iteratively updates each component of the solution vector using decomposed matrices D, E, and F from A=H-S-F. Convergence requires that the diagonal entries of A are non-zero and the matrix is diagonally dominant. The solution is updated in each iteration until the residual meets the tolerance level .

The resistive curve plots how resistance changes with temperature, indicating temperature sensitivity and material behavior under thermal conditions. In MATLAB, this is implemented by plotting resistance (X) against temperature (Y) using 'xlabel', 'ylabel', and 'plot' functions to visually understand and quantify these properties .

Vous aimerez peut-être aussi