forum.alglib.net

ALGLIB forum
It is currently Mon Dec 30, 2024 4:59 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: odesolver
PostPosted: Fri Jun 11, 2010 7:44 pm 
Offline

Joined: Fri Jun 11, 2010 7:41 pm
Posts: 2
Can U please tell me how to run odesolver in VBA from Excel?

Thanks!


Top
 Profile  
 
 Post subject: Re: odesolver
PostPosted: Sun Jun 13, 2010 11:55 am 
Offline

Joined: Sun May 16, 2010 11:42 pm
Posts: 63
The basics are in the code below; I'll post more details and some examples on my blog in the next few days:

Code:
' Dimension an array for the results
ReDim YA2(0 To M - 1, 0 To N - 1)

' Set up the "State" object to transfer data between the AlgLib code and your code to evealuate the differential equations
' See AlgLib code comments or manual for more details
Call ODESolverRKCK(YA(), N, XA2, M, Eps, Step, State)

' Loop through ODESolver and evaluation of DE until all steps have converged
Rtn = True
Do While Rtn = True
Rtn = ODESolverIteration(State)
' Either hard code evaluation of the Diff Equn(s) or call a VBA function with the name specefied in FuncName as shown below
State.DY = Application.Run(FuncName, State.X, State.Y, CoeffA)
Loop

' Extract the results array from the State function
Call ODESolverResults(State, M, XA2, YA2, Rep)
ODE = YA2


A typical simple function to evaluate the Dif Equn is shown below:

Code:
Function ODEFunc1(X As Double, Y As Variant, CoeffA As Variant) As Variant
Dim ResA(0 To 0) As Double
ResA(0) = CoeffA(1, 1) * Y(0)
ODEFunc1 = ResA
End Function


To call that function insert the line:
FuncName = "ODEFunc1"

Note that Y, CoeffA and the function return value are dimensioned as variants because they may contain 1 or more values.

_________________
Doug Jenkins
http://newtonexcelbach.wordpress.com/


Top
 Profile  
 
 Post subject: Re: odesolver
PostPosted: Sun Jun 13, 2010 12:19 pm 
Offline

Joined: Fri Jun 11, 2010 7:41 pm
Posts: 2
Thanks!

By the way, nice blog.


Top
 Profile  
 
 Post subject: Re: odesolver
PostPosted: Fri Jun 18, 2010 3:02 am 
Offline

Joined: Sun May 16, 2010 11:42 pm
Posts: 63
I have now posted details of running the AlgLib ODE solver routine via an Excel UDF here:

http://newtonexcelbach.wordpress.com/20 ... ith-excel/

The post includes a link to a download file, including all the necessary code and the five examples shown.

_________________
Doug Jenkins
http://newtonexcelbach.wordpress.com/


Top
 Profile  
 
 Post subject: Re: odesolver
PostPosted: Wed Jun 30, 2010 8:46 am 
Offline

Joined: Wed Jun 30, 2010 8:39 am
Posts: 2
Hi,

Great code!

Can I solve systems of differential equations with this code?

I have a system with 9 differential equations that I solve usually with matlab (ode45), but I would love to solve it with an excel base software.

Is it possible?

Best regards

MF


Top
 Profile  
 
 Post subject: Re: odesolver
PostPosted: Wed Jun 30, 2010 10:11 am 
Offline

Joined: Sun May 16, 2010 11:42 pm
Posts: 63
Marco - I imagine that it is possible, but I'd have to look into it and I don't have time at the moment.

Maybe Sergey can give some guidance!

_________________
Doug Jenkins
http://newtonexcelbach.wordpress.com/


Top
 Profile  
 
 Post subject: Re: odesolver
PostPosted: Thu Jul 01, 2010 8:11 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
marcof wrote:
Can I solve systems of differential equations with this code?
I have a system with 9 differential equations that I solve usually with matlab (ode45), but I would love to solve it with an excel base software.

If you talk about something like

Code:
dy0/dx = f0(y0, ..., y8, x)
dy1/dx = f1(y0, ..., y8, x)
...
dy8/dx = f8(y0, ..., y8, x)


then - yes, you can do it. ODESolverState structure has Y and DY fields which are vectors. You can read y0..y8 and x from State.Y[0:8] and State.X and write f0...f8 to State.DY[0:8] every time you return from ODESolverIteration function.


Top
 Profile  
 
 Post subject: Re: odesolver
PostPosted: Wed Jul 07, 2010 5:45 pm 
Offline

Joined: Wed Jun 30, 2010 8:39 am
Posts: 2
Brilliant!

Many thanks for your code. I will use it for sure in the near future!!

MF


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group