Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matrix math -- Application development 3

Status
Not open for further replies.

ePOWEReng

Electrical
Jul 15, 2003
114
Hello,

I am considering taking some calculations that presently performed using MathCAD and creating an application to perform those calculations instead. The calculations involve creating a matrix of complex numbers and performing some matrix math operations to arrive at the solution. The complex matrices will be up to 200x200 in size and matrix inversion will be required. My question is what programming language and development platform would make be the easiest to implement a program like this in? Are there libraries out there for performing complex matrix inversion? I was considering using the microsoft visual platform...

Thanks for your input and suggestions.
 
Replies continue below

Recommended for you

In VBA, you have only arrays, not matrices. There is no such thing as array multiplication. If you want to matrix multiply in vba you have to build a a routine to for it. You could put your vba variable into a range and use excel's mmult... but that is limited to real numbers.

Now there's the question of complex arithmetic. VBA has nothing. It can access excel's functions like imabs, immult. The tricky part you might never have guessed... the vba variables operated on by application.imabs and application.immult will have to be strings. That was surprising to me anyway. But if you inspect a spreadsheet with complex variables, you'll see they are also stored as strings.

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
There are a couple of decent numeric (including matrix math) libraries available for Java. But from what I've seen there are many more for C/C++ and I think maybe even more for Fortran.

So I guess pick your poison. If there is a particular language that you know (or want to learn) other than VBA you can probably find something, even if it is not too complete.
 
Why not just use Matlab? or Octave, or Scilab? the latter two being free.

Unless you intend to sell the application, I don't see the utility or necessity of inventing a routine, debugging, etc., when there are already tools that do the job.

TTFN

FAQ731-376
 
The goal is to have an application that can be run on any PC without installing any other software except the application itself so I don't want to use matlab or similar software. I was hoping to find programming libraries for building matrices, complex numbers and performing matrix math operations so I don't have to develop those from scratch.

I found some libraries from the company below. Does have experience using this or something similar who could provide feedback or review or other recommendations?



Thanks.
 
Matlab has runtime modules that do not require the entire Matlab installation, I think...

TTFN

FAQ731-376
 
What is .NET?

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
ok, I can answer that.

Next question... does it run on anyone's PC. Looks like you have to install something to run .NET programs.

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
If you use the .NET framework components, then the target computer will need .NET of the version you used installed on it.

TTFN

FAQ731-376
 
I think ALGLIB is the resource you are looking for.


Note that all their routines are available in VB as well as various flavours of C and Pascal, and they have routines for complex numbers and all the usual matrix operations.

If it was me I'd do it in Excel VBA and then look at compiling any routines that were resulting in unsatisfactory performance (if any), or compiling the whole thing if security was an issue.



Doug Jenkins
Interactive Design Services
 
That looks very promising Doug. I have been looking for vba matrix tools for awhile.

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
Thanks for the link doug. It looks like they have code for finding the determinant of complex matrix, but I didn't see anything for inversion of a complex matrix. Any ideas where I might find code for that in VBA?

Thanks!
 
I inspected the module matinv and it uses the complex type (defined in ap.bas). I'm pretty sure this can do what you want. There is some setup to do.

For one thing ap.bas has to be available. I cut/pasted it into a module and then I had access to the complex type and associated basic functions.

I'm a little bit confused about matinv. The matinv.bas file has function matinvreport, but no funciton matinv

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
Looks like cmatrixinverse is what you need.

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
You're welcome. But, still seems a challenge to set this thing up.

I copied ap.bas into one module.
I copied matinv.bas into another module.
In a 3rd module I tried to create my own test code:
Code:
Sub test1()

Dim a11 As Complex, a12 As Complex, a21 As Complex, a13 As Complex
Dim A(1 To 2, 1 To 2) As Complex
Dim XX As MatInvReport
A(1, 1).X = 5
A(1, 1).Y = 2
A(1, 2).X = 6
A(1, 2).Y = 2
A(2, 1).X = 3
A(2, 1).Y = 9
A(2, 2).X = 1
A(2, 2).Y = 2

' ainv = CMatrixInverse(A, 2)
' Call CMatrixInverse(A, 2, 0, Z)
Call CMatrixInverse(A, 2, 0, XX)

Stop
End Sub
The result of trying to run this sub is an error message within module CMatrixInverse:
Sub or Function Not defined: CMatrixLU

There is a lot of goodies in this package that I'd like to have, but it also requires some additional setup I think that I can't quite figure out.

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
OK, I figured out that I need trfac.bas loaded into a module also in order to have CMatrixLU. Perhaps there is some way to tell vba where these bas files are so it can find whatever it needs?

Even after I loaded trfac.bas into a module, I still have a problem.
Runtime Error 9 - subscript out of range.

This error is associated with the line
MX = MaxReal(MX, AbsComplex(A(I, J)))
located within module CMatrixPLU of module trfac

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
Electricpete - the arrays need to be base 0.

I see there is a reply to your question on their forum.

I got it to run with no reported errors after installing all the files listed (and turning off option explicit!), but it returns the original matrix!

I'm still looking.

Doug Jenkins
Interactive Design Services
 
D'oh


I was inverting a matrix that had been inverted with the Excel MINVERSE function, so I was getting the original matrix back!

Seems to be working ok with real numbers, I'll have a look at the complex routine now.

Doug Jenkins
Interactive Design Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor