View Single Post
  #3   Report Post  
MrShorty
 
Posts: n/a
Default


Suspending judgement on why you want to do it this way:

Sub mysub()
Set rng=desired range
With rng
For x=1 to 10
y=-10.1
Do
y=y+.1
f=x+y
loop until abs(f)<1e-6
'I often prefer to test for almost 0 rather than exactly equal to 0
because of rounding error when decimal fractions are converted to
binary in the IEEE system
.cells(x,1).value=x
.cells(x,2).value=y
next x
end with
end sub

check the syntax, I wrote that quickly. Debugged, it should do exactly
what you've asked for, no less, and no more.

I'm guessing this is just a test case for future, more complex
problems. If this is true, you might consider looking into different
numerical algorithms for solving f. A Newton-Raphson algorithm will be
more certain of finding a solution, and will find it more effeciently
than the algorithm we've used here. We also haven't dealt with cases
(like x-y^2=0) where there is more than one possible y value for each x
value. Bernard's approach using Solver in a worksheet will work well
for most other equations, though it won't have a way of determining
when multiple solutions exist.


--
MrShorty
------------------------------------------------------------------------
MrShorty's Profile: http://www.excelforum.com/member.php...o&userid=22181
View this thread: http://www.excelforum.com/showthread...hreadid=471538