Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2455

while loop - numerics

From Anna Kaladze <anna.kaladze@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject while loop - numerics
Date 2011-05-18 11:17 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <ir09se$23j$1@smc.vnet.net> (permalink)

Show all headers | View raw


Hi all,



I am new in loop writing in Mathematica, so your help on the following
seemingly simple problem would be appreciated.  I have the following
commands:

-------------------------------------------------

tol=1/100;



DM=9;



yguess=0.5;



x=yguess^2

0.25



yfeedback=x*yguess

0.125



Error=Abs[yfeedback-yguess]

0.375
-------------------------------------------
Without doing any equations solving/substitutions or any algebraic
manipulations, or utilizing Table commands, I need to have a while loop
command applied to the above code, such that for a given yguess value
entered (now it is set to 0.5 for the first iteration), Mathematica would
calculate yfeedback and the Error, every time updating yguess with the
following rule: yguess = the last calculated value of yguess*(1+last
calculated value of Error/DM), until Error in the last iteration is less or
equal tol. And then report what that yguess value is.

For yguess = 0.5, we obviously get after 1st iteration that yfeedback=0.125
and a large resulting Error value 0.375. So, the yguess needs to be updated
as 0.5*(1+0.375/DM), and that would become 0.520833. Now in the second
iteration yguess takes the value of 0.520833, and then the resulting Error
would become 0.379548, and then the updated yguess would become
0.520833*(1+0.379548/DM)= 0.542798 and so on until the stopping criteria is
achieved. (Somewhere when the program calculates yguess close to unity the
program should stop obviously). The question is how to write such a code.

Thanks in advance.

Anna

Back to comp.soft-sys.math.mathematica | Previous | NextNext in thread | Find similar | Unroll thread


Thread

while loop - numerics Anna Kaladze <anna.kaladze@gmail.com> - 2011-05-18 11:17 +0000
  Re: while loop - numerics Peter Pein <petsie@dordos.net> - 2011-05-19 11:43 +0000

csiph-web