Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What I am trying to do: increment for loop or do while loop by 0.001
---------------------- My for loop (I don't know how to increment by 0.001, this code just increments by 1): ---------------------- For X = 0 To 10 'For X between 0 and 10 incremented by 0.001 For Y = 0 To 10 'For X between 0 and 10 incremented by 0.001 Fnew = X * Y * Exp(1 - 2 * X) * Sin(Y - X) * (1 - Y ^ 2) 'Given function If Fold <= Fnew Then 'If previous value of function is less than current value of f then... xmax = X 'Store value of X for max value of F ymax = Y 'Store value of y for max value of F Fold = Fnew 'Update the function End If 'End if statement Next 'End inner for loop (Y loop) Next 'End outer for loop (X loop) ---------------------- My do while loop (I tried incrementing by 0.001, but the answer is not what I want): ---------------------- Do While X <= 10 Do While Y <= 10 Fnew = X * Y * Exp(1 - 2 * X) * Sin(Y - X) * (1 - Y ^ 2) 'Given function with new X and Y value If Fold <= Fnew Then 'If previous value of function is less than current value of f then... xmax = X 'Store value of X for max value of F ymax = Y 'Store value of y for max value of F Fold = Fnew 'Update the function End If 'End if statement Y = Y + 0.001 If Y 10 Then Exit Do Loop X = X + 0.001 If X 10 Then Exit Do Loop ---------------------- My Question for the do while loop: why am I not getting an xmax = 0.215 and ymax =10.000? I think this is these are the correct answers. ---------------------- |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to increment within For Next Loop | Excel Discussion (Misc queries) | |||
Increment stopvalue inside a For loop | Excel Programming | |||
Loop .WebTables to increment by 1 | Excel Programming | |||
Increment column in loop | Excel Programming | |||
Increment through For Next loop | Excel Programming |