Complex numbers in excel

  • Thread starter Thread starter knutso
  • Start date Start date
K

knutso

I do a call to a sub akoef in the code beneath. It works fine in the
non-complex case that I have coded:

first, the call in main program:

'''''''''''''''''''''''''''''''

Call AKOEF(OM, DELT, NAX, G, AKD, a, B)

''''''''''''''''''''''''''''''
here is the called sub - the complex suggestions are in comments:

Sub AKOEF(OM, DELT, NAX, G, AKD, a, B)

i = 1 ' should be -1 for complex
i = Sqr(i) ' should be imsqrt for complex
sa = 0
AKD(NAX) = sa
ARG = Sqr(1 / a) * (-i * OM - 0.5 * OM * (B / a)) * DELT * NAX
s1 = G(NAX) * Exp(ARG) ' exp should be imexp for complex
NA = NAX - 1
For jj = 1 To NA
j = NAX - jj
AKs = AKD(j) * AKD(j)
ARG = Sqr(1 / a) * (i * OM - 0.5 * OM * (B / a)) * DELT * j
s2 = G(j) * Exp(ARG) * (1 - AKS) ' exp should be imexp for complex

sa = 0.5 * (s1 + s2) * DELT + sa
AKD(j) = Exp(-ARG) * sa 'exp should be imexp for complex
s1 = s2
Next jj
End Sub
-----------------------------------------

in FORTRAN the complex case is very simple. I just declare the complex
variables in akoef with a type command like this:

TYPE COMPLEX AKD,AK,AKS,I,CEXP,CSQRT,ARG,S1,S2,SA

I exchange the real function with complex functions. Complex fortran is a
bit different from excel, but the idea is the same.

and the call will return a complex variable AKD.

....so this is no problem..
.... there must be a way to do it simple also in excel. Anyone with experience?
 
Open VBA editor and type COMPLEX in the search box
Look at the method called Complex
You should not try to use
i=-1; i=SQR(i)
best wishes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top