why my iteration prog doesn't work ?

1 vue (au cours des 30 derniers jours)
khalid boureeny
khalid boureeny le 23 Jan 2017
Commenté : Walter Roberson le 25 Jan 2017
% Use NR method f(x)= x^3-5x^2+7x-3
clc
TV=3;
x=(4);
tol=0.0007;
format long
for i=1:5;
fx=(x(i))^3-5*(x(i))^2+7*(x(i))-3;
fxx=3*(x(i))^2-10*(x(i))+7;
x(i+1)=(x(i))-(fx/fxx);
E_T(i)=(abs((TV-x(i+1))/TV))*100;
end
for i=1:5;
e(i)=(x(6))-(x(i));
fx=(x(i))^3-5*(x(i))^2+7*(x(i))-3;
fxx=3*(x(i))^2-10*(x(i))+7;
fxxx=6*(x(i))-10;
e(i+1)=(-fxxx/2*fxx)*(e(i))^2;
end
if abs(TV-(x(i+1)))<tol
disp(' enough to here')
disp(' -----------')
disp(' x(i+1) ')
disp(' -----------')
x;
disp(' -----------')
disp(' T.V ')
disp(' -----------')
E_T;
disp(' -----------')
disp(' E(i+1) ')
disp(' -----------')
e;
disp(' ------------- ')
end
%-----------------------------------------------------------
  7 commentaires
khalid boureeny
khalid boureeny le 25 Jan 2017
Modifié(e) : Walter Roberson le 25 Jan 2017
Hi , Walter Roberson .... I'm deeply grateful for your help ... I still have a problem with decimal digits ...
What if I need more decimal digits in my answer than the default ? for example 50 or 80 digits .
PLEASE , HELP in this one ...
clear all
clc
x=(-0.1);
y=(0);
fprintf(' i x \n')
fprintf(' --- ------------- \n')
for i=1:5;
fx=(x(i))^3-(x(i))^2+2;
fxx=3*(x(i))^2-2*(x(i));
y(i)=x(i)-(fx/fxx);
fy=(y(i))^3-(y(i))^2+2;
fyy=3*(y(i))^2-2*(y(i));
x(i+1)=x(i)+([fy-fx]/fyy);
end
for i=1:length(x)
fprintf('%2i %18.15f\n',i,x(i))
end
THE RESULTS ARE
i x
--- -------------
1 -0.100000000000000
2 -3.119140528362807
3 -1.474069695697443
4 -1.017351956185236
5 -1.000001047082565
6 -1.000000000000000
Walter Roberson
Walter Roberson le 25 Jan 2017
If you need 50 or 80 digits you will need to switch to the Symbolic Toolbox, and display using vpa()
NumDig = 50;
x = sym(-0.1);
y = sym(0);
fprintf(' i x \n')
fprintf(' --- ------------- \n')
for i=1:5;
fx=(x(i))^3-(x(i))^2+2;
fxx=3*(x(i))^2-2*(x(i));
y(i)=x(i)-(fx/fxx);
fy=(y(i))^3-(y(i))^2+2;
fyy=3*(y(i))^2-2*(y(i));
x(i+1)=x(i)+([fy-fx]/fyy);
end
for i=1:length(x)
fprintf('%2i %s\n', i, char(vpa(x(i),NumDig)))
end

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Jan 2017
In your section
if abs(TV-(x(i+1)))<tol
disp(' enough to here')
disp(' -----------')
disp(' x(i+1) ')
disp(' -----------')
x;
disp(' -----------')
disp(' T.V ')
disp(' -----------')
E_T;
disp(' -----------')
disp(' E(i+1) ')
disp(' -----------')
e;
disp(' ------------- ')
end
remove the ';' from the 'x;' and 'E_T;' and 'e;' -- so
if abs(TV-(x(i+1)))<tol
disp(' enough to here')
disp(' -----------')
disp(' x(i+1) ')
disp(' -----------')
x
disp(' -----------')
disp(' T.V ')
disp(' -----------')
E_T
disp(' -----------')
disp(' E(i+1) ')
disp(' -----------')
e
disp(' ------------- ')
end
  2 commentaires
khalid boureeny
khalid boureeny le 23 Jan 2017
Hi, Walter Roberson .... thanks a lot , I will try ... thanks again ...
khalid boureeny
khalid boureeny le 23 Jan 2017
Hi , Walter Roberson .... YOU're a genius ... thanks again ...thanks thanks .

Connectez-vous pour commenter.

Plus de réponses (1)

Lateef Adewale Kareem
Lateef Adewale Kareem le 23 Jan 2017
increase your number of iteration, you will meet the tolerance target
  1 commentaire
khalid boureeny
khalid boureeny le 23 Jan 2017
Thanks , I will try ...

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by