NestWhile and FindRoot[Integrate]
- To: mathgroup at smc.vnet.net
- Subject: [mg42398] NestWhile and FindRoot[Integrate]
- From: "Mukhtar Bekkali" <mbekkali at hotmail.com>
- Date: Fri, 4 Jul 2003 01:33:15 -0400 (EDT)
- Organization: Iowa State University
- Sender: owner-wri-mathgroup at wolfram.com
I have two questions: I have function f(x,t), where 0<x<1 and trying to find the value of x which sets Integrate[f(x,t)g(t),{t,0,1}]=0 for some p.d.f. g(t). So, I programmed FindRoot[Integrate[f(x,t)g(t),{t,0,1}]==0,{x,0.5}], however, this head-on approach works only for simple functions f(x,t) and g(t). It seems that Mathematica is trying to integrate first symbolically and then solve it. Is there other way to attach the problem? Another question relates to loops (totally unrelated to the above problem). I am trying to find a maximum of function q(y) using Newton's method (I want to do it manually for my own reasons and do not want to use any built-in functions). Newton's method essentially substitutes different values of y into q(y), but in its special way, and then checks if this is the maximum. So my code is as follows (for some specific functions q(y) and parameter z): y0=0; m=D[q(y),y]/D[q(y),{y,2}] y1=y0-m/.y->y0; NestWhile[{y0=y1,y1=y0-m/.y->y0},{y0,y1},Abs[(q(y)/.y->y1)-(q(y)/.y->y0)]>z] However, instead of updating y0 and y1 with the old values of y0 and y1 (i.e. set y0new=y1old and y1new=y0new-m/.y->y0new) it returns the initial values of y0 and y1 and that's it. I thought I can use While instead: y0=0; m=D[q(y),y]/D[q(y),{y,2}] y1=y0-m/.y->y0; While[Abs[(q(y)/.y->y1)-(q(y)/.y->y0)]>z,{y0=y1,y1=y0-m/.y->y0}] but this time nothing is returned at all. Essentially, I messed up something with updating of values y0 and y1 but cannot figure out what. Thanks.