salut à tous,
j'ai besoin d'une aide urgente SVP, je veut résoudre l'équation suivante sous MATLAB par 3 méthodes (Bissection, Newton, et Point fixe):
f(x)= exp(x-3)+4.
merci d'avance.
salut à tous,
j'ai besoin d'une aide urgente SVP, je veut résoudre l'équation suivante sous MATLAB par 3 méthodes (Bissection, Newton, et Point fixe):
f(x)= exp(x-3)+4.
merci d'avance.
méthode de la bissection (Tu as de la chance j'avais déjà programmer cette fonction)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 function [ r ] = bisection( f, a, b, N, eps_step, eps_abs ) % Check that that neither end-point is a root % and if f(a) and f(b) have the same sign, throw an exception. if ( f(a) == 0 ) r = a; return; elseif ( f(b) == 0 ) r = b; return; elseif ( f(a) * f(b) > 0 ) error( 'f(a) and f(b) do not have opposite signs' ); end % We will iterate N times and if a root was not % found after N iterations, an exception will be thrown. for k = 1:N % Find the mid-point c = (a + b)/2; % Check if we found a root or whether or not % we should continue with: % [a, c] if f(a) and f(c) have opposite signs, or % [c, b] if f(c) and f(b) have opposite signs. if ( f(c) == 0 ) r = c; return; elseif ( f(c)*f(a) < 0 ) b = c; else a = c; end % If |b - a| < eps_step, check whether or not % |f(a)| < |f(b)| and |f(a)| < eps_abs and return 'a', or % |f(b)| < eps_abs and return 'b'. if ( b - a < eps_step ) if ( abs( f(a) ) < abs( f(b) ) && abs( f(a) ) < eps_abs ) r = a; return; elseif ( abs( f(b) ) < eps_abs ) r = b; return; end end end error( 'the method did not converge' ); end
Ensuite pour la méthode de Newton, il faut que tu transforme ta fonction en suite. f(x) devient f(xn).
Tu dois résoudre le système suivant :
x0 = ce que tu cherches
x(n+1)=xn-f(xn)/f'(xn)
tu devrais essayer quelque chose comme ça
A toi de trouver les bornes m et n
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 e=1e-10; for i=m:n x(i+1)=x(i)-f(x(i))/diff(f(x(i))); if abs(x(i+1)-x(i))<=e %condition d'arret xp=x(i); fprintf('xp=%f\n',x(i)); return; end end
Pour finir tu pourrais utiliser quelque chose de ce genre là pour la méthode du point fixe.
avec converged une fonction qui définie le convergence
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 function x1 = FPI(f,x1,tol) % FPI(f,x0) Iterations du point fixe % if nargin == 2 tol = 1e-8; end it = 0; itmax = 100; x0 = realmax ; while ~converged (x0,x1,tol) x0 = x1; x1 = feval(f,x0); it = it + 1; if it > itmax error('Maxit in FPI'); end end
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 function res = converged(y0,y1,tol) res = all(abs(y1-y0)./(abs(y0)+1) < tol); end
Merci énormément Beltharion pour t'à réponse, je vais essayer avec Newton et le Point fixe.
un grand merci encore une fois...
Partager