Message Boards Message Boards

0
|
4115 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

The Newton's method in the mean of Interval

I have to write the Newton's method  in the point which is the mean of Interval. and in 'While' loop  it could be while the function(point)>eps.
 point = Mean[inter];
 step[f_,inter_] := Module[{p:=Mean@First@(List @@ inter)},
 IntervalIntersection[inter, p - (f[p])/(f'[p])]]
   newton[f_, inter0_, eps_] := Module[{iter = 0},
   Print["X1 = ", N@Mean@First@(List @@
   NestWhile[(++iter; step[f, #]) &, inter0,
      Abs[f[p]] > eps & ])];
      Print["iter=", iter];
      Print[ "loop counts: ", iter, ". ", inter,"; p=",p=Mean@First@(List @@ inter), "; f[p]=",f[p],"; f'[p]=",f'[p]]];
f[x_] := x*x - 8*x + 7;
inter := Interval[{5,9}];
newton[f, inter, 0.00001];
I tried to do it, but it doesn't work correctly.  Please, help me!
POSTED BY: Julia Ilkiv
3 Replies
Anonymous User
Anonymous User
Posted 10 years ago
Abs[f[p]] > eps &]
Look this. I think you must  verify
Abs[f[p]/f'[p]]> eps &]


Module[{p := Mean@First@(List @@ inter)},
Do you understand that p is local virable for step[] function? You don't able to reach it from newton[] function - I think.


IntervalIntersection[inter, p - (f[p])/(f'[p])]]
IntervalIntersection[] must have arguments from Interval type - what you trying to do?!


NestWhile[(++iter; step[f, #]) &, inter0, Abs[f[p]] > eps &]
If you explain how this function should work and what exactly you want to do - I might help you. I'm not very familiar with these symbols # and & yet.
POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 10 years ago
POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 10 years ago
 Clear["Global`*"]
 (*Newton's Method for solving equation f(x)=0.,I do not understand \
 something like that you want to get?!,
 I'm nubie in Wolfram Mathematica - but experts don't answer you,
 See if code can help you with something. Excuse me for my broken \
 English*)
 
 (*function f(x)*)
 f[x_] := x - E^(-x^2);
(*Interval*)
interval = {0, 2};
(*desired accuracy*)
desAcc = 0.00001`;


(*Initial x - Mean of interval you chose*)
xInitial = Mean[interval];


(*Newton's Method*)
newton[f_, xInitial_, desAcc_] :=
Module[
  {xNext = 0, xNow = xInitial, result = desAcc, iter = 0},
  While[ result >= desAcc,
    iter++;
   
    xNext = N[xNow - (f[xNow]/f'[xNow])];
    result = Abs[xNext - xNow];
   
    If[ result < desAcc,
     Print[
      "Solve of equation f(x)=0 is for x = ",
      xNext, "."];
     Print["With accuracy ",
      desAcc, "."];
     Print["In interval ",
      interval, "."];
     Print["Loop counts: ",
      iter, "."],
     xNow = xNext
     ];
    ];
  ]

(*Newton's Method*)
newton[f, xInitial, desAcc];
POSTED BY: Anonymous User
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract