Message Boards Message Boards

0
|
9908 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

[?] Use NestWhile using a function with 2 arguments one sets parameters?

Posted 7 years ago

I want to use

gf[x_, y_] := 
 Module[{x1, x2, xtst, fnw, f1, xnw}, xtst = Total[x]/2;fnw = 
   LAcr[xtst, 1/12., LAI, LBI, AF, a, b, c, d, 
    400000.,a, y];
  f1 = LAcr[x[[1]], 1/12., LAI, LBI, AF, a, b, c, d, 
    400000., a, y]];
  Return[If[Sign[fnw] == Sign[f1], {xtst, x[[2]]}, {x[[1]], xtst}]];]
as the input to 
NestWhile[
   gf, {500., 50000.}, #[[2]] - #[[1]] > 0.0001 &]

where the return parameters are {xlowerfinal,xupperfinal} are the final values of { #[[1]],#[[2]]} and the value of y is to be supplied before entering NestWhile by using the Table function to introduce a list of y values. Can one convert a a 2 variable (here x, y) function into a 1 variable function of x by automatically introducing the y values using Table? Or is there some way of making ListWhile know which variable (x) to use?

POSTED BY: Robert Curl
4 Replies

I apologize for not following the rules. The code for my actual problem using the hints by Bill Simpson follows. Unfortunately I seem to not be able to think of a simple example.

This is the solution to the problem I posted earlier today using the code for the actual problem. 
The functions and input paramaters are defined in another notebook.
gf\[Beta][{x_, \[Beta]_}] := 
 Module[{x1, x2, xtst, fnw, f1, xnw}, xtst = Total[x]/2; 
  fnw = LAcr[xtst, 1/12., LAI, LBI, AF, a, b, c, d, 
    400000., \[Alpha]0, \[Beta]]; 
  f1 = LAcr[x[[1]], 1/12., LAI, LBI, AF, a, b, c, d, 
    400000., \[Alpha]0, \[Beta]]; 
  Return[If[Sign[fnw] == Sign[f1], {xtst, x[[2]]}, {x[[1]], xtst}]];]
  f1 = LAcr[x[[1]], 1/12., LAI, LBI, AF, a, b, c, d, 
    400000., \[Alpha]0, \[Beta]]; 
  Return[If[Sign[fnw] == Sign[f1], {xtst, x[[2]]}, {x[[1]], xtst}]];]`
f[x_] := gf\[Beta][{x, .6}]
t works slightly differently from previously.  What used to work, doesn't.
In[27]:= NestWhile[f, {500., 50000.}, test &]

Out[27]= {500., 50000.}
However, if I add a large integer it does.
In[28]:= NestWhile[f, {500., 50000.}, test &, 100]

Out[28]= {35964.7, 35964.7}
The integer seems to be the number of iterations.`enter code here`
In[29]:= NestWhile[f, {500., 50000.}, test &, 3]

Out[29]= {25250., 37625.}
POSTED BY: Robert Curl
POSTED BY: Robert Curl
Posted 7 years ago
POSTED BY: Bill Simpson
Posted 7 years ago
POSTED BY: Bill Simpson
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