LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Increment for or do while loop by 0.001 (not 1)

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to increment within For Next Loop EagleOne Excel Discussion (Misc queries) 1 August 9th 06 04:18 PM
Increment stopvalue inside a For loop Revenger Excel Programming 2 May 26th 06 09:17 AM
Loop .WebTables to increment by 1 al007 Excel Programming 0 February 24th 06 08:02 AM
Increment column in loop RyanVM[_20_] Excel Programming 4 August 24th 04 08:28 PM
Increment through For Next loop hotherps[_7_] Excel Programming 3 April 8th 04 05:40 PM


All times are GMT +1. The time now is 01:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"