|
-
Jul 1st, 2006, 03:05 AM
#1
Thread Starter
Lively Member
Re: Coding math with VB6
Thank you, I would like to have a look at the code if you don't mind.
A follow up: In the program I'm writing I'm having the computer do a numerical integration of the type of function listed above. My method right now is to do a simple Riemann sum using a For Next loop. I find I can get better accuracy by using more segments so that for instance I could have the loop run 2.1 billion times and sum up the tiny areas. This takes 33 minutes to do an integration that I can do in my head in 30 sec. Is there a faster mechanism for running the same kind of Riemann sum the same number of times but in much less time?
Thanks - Eric
-
Jul 2nd, 2006, 02:08 AM
#2
Addicted Member
Re: Coding math with VB6
Ahh i see what you are doing, I can't guarantee it will be fast, because parsing a expression real time is slow. Usually you would need an engine to convert the function into machine code (i.e. compile real time once) and then just use the function over and over again.
I'll post the evaluator, but it may be above your level of coding to understand:
I'll just outline what you need to do:
You need the following modules added to your project:
MPostfixEvaluator.bas
MAssemblyThunks.bas
When you want to Calculate Something:
Dim tRPN(0 To 49) As RPN_EXPRESSION_ITEM
Dim sInput As String
Dim lCount as Long
Dim rAnswer as Double
sInput = "2 + 2"
lCount = ConvertToPostfixRPN(sInput, tRPN)
rAnswer = EvaluateRPNExpressionDouble(tRPN, lCount)
txtAnswer.Text = rAnswer
Before you get carried away, you can't use sInput = "x + 2", because I haven't programmed in support for variables.
Note: This will certainly be slower than your current method, and I believe, Reimann's numerical integration is slow anyway .....so maybe look at the
Simpon's Rule
Cheers.
Last edited by Raedwulf; Jul 4th, 2006 at 02:40 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|