Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel Troubles

I have a equation that you can solve only by trial an error, but I wan
excel to do the work for me. The equation is this

1/(X^.5)=2Log(C*X^.5)-.8
Where c is some constant that isant worth mentioning ;)
and the Log is base 10.
Ok I need a macro that will keep trying values untill one side is equa
to the other up to .001 decimal places. I tried making some sort o
random function generator, but it seems like the random function kep
repeating certain values. Any advice/help is appericated.
-Mar

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Excel Troubles

I came up with 3.73250246, ignoring C

"medialint" wrote:

Something like this, though if C isn't worth mentioning then why put it in?

Sub LoopSolve()
Randomize
Dim myRandomNum As Single
Dim YRow As Long
Dim XAdd As Long
Dim CalcDiff As Single
YRow = 2
Worksheets("Sheet1").Cells(1, 1) = "Number"
Worksheets("Sheet1").Cells(1, 2) = "Difference"
Do
myRandomNum = Rnd * 1000
CalcDiff = Abs((1 / (myRandomNum ^ 0.5)) - (2 * Log(myRandomNum ^ 0.5) - 0.8))
Worksheets("Sheet1").Cells(YRow, 1 + XAdd) = myRandomNum
Worksheets("Sheet1").Cells(YRow, 2 + XAdd) = CalcDiff
YRow = YRow + 1
If YRow 65536 Then
YRow = 2
XAdd = XAdd + 2
End If
Loop Until CalcDiff < 0.001
End Sub


"mrmark " wrote:

I have a equation that you can solve only by trial an error, but I want
excel to do the work for me. The equation is this

1/(X^.5)=2Log(C*X^.5)-.8
Where c is some constant that isant worth mentioning ;)
and the Log is base 10.
Ok I need a macro that will keep trying values untill one side is equal
to the other up to .001 decimal places. I tried making some sort of
random function generator, but it seems like the random function kept
repeating certain values. Any advice/help is appericated.
-Mark


---
Message posted from http://www.ExcelForum.com/


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Excel Troubles

Sorry, but the formula needs a slight tweak. The log
functtion in VBA is a natural log function not Log10.
Also the formula will give negative answers so will meet
the <.0001 criteria. Change the routine as follows:

CalcDiff = Abs((1 / (myRandomNum ^ 0.5)) - (2 * (Log
(myRandomNum ^ 0.5)/log(10#)) - 0.8))

and

Loop Until CalcDiff < 0.001 and Calcdiff -.001

All the best

DavidC

-----Original Message-----
I came up with 3.73250246, ignoring C

"medialint" wrote:

Something like this, though if C isn't worth mentioning

then why put it in?

Sub LoopSolve()
Randomize
Dim myRandomNum As Single
Dim YRow As Long
Dim XAdd As Long
Dim CalcDiff As Single
YRow = 2
Worksheets("Sheet1").Cells(1, 1) = "Number"
Worksheets("Sheet1").Cells(1, 2) = "Difference"
Do
myRandomNum = Rnd * 1000
CalcDiff = Abs((1 / (myRandomNum ^ 0.5)) - (2 *

Log(myRandomNum ^ 0.5) - 0.8))
Worksheets("Sheet1").Cells(YRow, 1 + XAdd) =

myRandomNum
Worksheets("Sheet1").Cells(YRow, 2 + XAdd) =

CalcDiff
YRow = YRow + 1
If YRow 65536 Then
YRow = 2
XAdd = XAdd + 2
End If
Loop Until CalcDiff < 0.001
End Sub


"mrmark " wrote:

I have a equation that you can solve only by trial an

error, but I want
excel to do the work for me. The equation is this

1/(X^.5)=2Log(C*X^.5)-.8
Where c is some constant that isant worth

mentioning ;)
and the Log is base 10.
Ok I need a macro that will keep trying values untill

one side is equal
to the other up to .001 decimal places. I tried

making some sort of
random function generator, but it seems like the

random function kept
repeating certain values. Any advice/help is

appericated.
-Mark


---
Message posted from http://www.ExcelForum.com/


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Excel Troubles

Forgot to remind you to add in the constant. So try the
routine from medialint as revised below to fix the natural
log problem and the negative value issue and add in the
constant. I have referenced cell C1 for the constant to
make it easier for the constant to be changed without
going to the routine. Also if you want, add Msgbox
(myrandomnum) after the Loop statement to give you the
answer quickly without having to search for it.


Sub LoopSolve()
Randomize
Dim myRandomNum As Single
Dim YRow As Long
Dim XAdd As Long
Dim CalcDiff As Single
YRow = 2
Worksheets("Sheet1").Cells(1, 1) = "Number"
Worksheets("Sheet1").Cells(1, 2) = "Difference"
con = ActiveSheet.Range("C1").Value

Do
myRandomNum = Rnd * 100
CalcDiff = Abs(1 / (myRandomNum ^ 0.5)) - (2 *
con * (Log(myRandomNum ^ 0.5) / Log(10#)) - 0.8)
Worksheets("Sheet1").Cells(YRow, 1 + XAdd) =
myRandomNum
Worksheets("Sheet1").Cells(YRow, 2 + XAdd) =
CalcDiff
YRow = YRow + 1
If YRow 65536 Then
YRow = 2
XAdd = XAdd + 2
End If
Loop Until CalcDiff < 0.001 And CalcDiff -0.001

End Sub

Best of luck

DavidC
-----Original Message-----
I have a equation that you can solve only by trial an

error, but I want
excel to do the work for me. The equation is this

1/(X^.5)=2Log(C*X^.5)-.8
Where c is some constant that isant worth mentioning ;)
and the Log is base 10.
Ok I need a macro that will keep trying values untill one

side is equal
to the other up to .001 decimal places. I tried making

some sort of
random function generator, but it seems like the random

function kept
repeating certain values. Any advice/help is appericated.
-Mark


---
Message posted from http://www.ExcelForum.com/

.

Reply
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
Excel Header - Auto Format troubles Kurtboard Excel Discussion (Misc queries) 1 October 8th 09 10:17 PM
Excel 2007 Formula troubles lmh Excel Worksheet Functions 7 August 13th 09 10:08 PM
Excel troubles Gavin Excel Worksheet Functions 0 June 24th 08 02:16 PM
troubles with the Workbooks.Open method in Excel 97 Amarth Excel Programming 1 June 14th 04 02:02 PM
saving *.xls files but troubles with opening with MS Excel Mimo Excel Programming 0 July 25th 03 03:04 PM


All times are GMT +1. The time now is 11:27 PM.

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

About Us

"It's about Microsoft Excel"