Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Mathematical Arrays and Operations in VBA 2

Status
Not open for further replies.

Goska

Programmer
Jun 21, 2001
74
US
I am starting a new program and trying to decide what platform to write it in. The Engineer in me is developing this program and there is alot of matrix algebra going on. My available options are MathCAD, VBA, and FORTRAN.

I am using 4x4 matrices and 4 term vectors for everything. I know I can do this in MathCad (Simliar to Maple) but I am not aware of how to throw a GUI in this. Mathcad also has issues with running large loops to increment motions of an input body.

I can write my own subs() in VBA to do all of the matrix algebra, but I am wondering about VBA and its accuracies and decimal precision with arrays. My input motion runs in increments of .0001 degrees which is .0000017453 radians, and I am assuming that VBA runs off radians like Excel. I need to hold mathematical precision at high numbers of decimal places (8 or more) as I am writing this code to catch spikes in the motion that relate to high forces which will result in a wheel of my race car flying off.

Is anyone aware of the best way to handle large quantities of arrays/matrices with high decimal precison?

I have a feeling that I am going to end up back in FORTRAN for this one, but I am looking for some advide before I start the code.

Also, if anyone has a sub() for a simultaneous equation solver (20 equations, 20 unknowns, solve them all) I would appreciate it. I don't feel like rewriting my old FORTRAN one if I don't have to.


 
I think I may be asking this question in the wrong place. If you know of a message board similar to Tek-Tips for Engineers/Mathematicians, please pass this website on.
 
Straight from VBA help files (also applicable to VB)

Trigonometric functions return radians, stored in a double.

Doubles are accurate down to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 for positive values. I think this will accomodate you. ;-)

The fastest way to handle them would be assembly, but that's not a very reasonable solution. Visual Basic can certainly DO what you have specified, with precision and accuracy, but there is an issue with the speed. If this is run time critical (something about wheels departing from vehicles?) then you'd probably need C/C++ (or FORTRAN, but I'm not at all familiar with it).

The VB & controls would probably make for the easiest GUI development, and the slowest execution speed. Pick your poison.
 
Speed is not important, as this is a design tool I am developing and already have others that I have purchased that I expect to run as an overnight thing and see the results in the morning. This is not an onboard thing.

The spikes are refer to are basically instantaneous displacements in the range of motion where there is a very high load in certain components where mechanical failure due to fatigue/shock loading become critical. And I could just use bigger bolts and bearings, but that gets expensive and heavy quickly. My bolts range from $1-$30 US per piece, plus nuts and washers.

As far as the arrays, I have not had any luck in finding information on 2D arrays, like the following 4x4:

_____________________
| 10 30 2 9 |
| .5 6 8 11 |
| 3 5 8 12 |
| 0 0 0 1 |
_____________________

I have only been able to find Help files for vector style Arrays, ie
_____
| 1 |
| 0 |
| 3 |
| 5 |
_____

Any idea where I can find Help on the 2D (4x4) arrays?
 
I'm not sure I understand what you're looking for, but

Dim pdblArray(4, 4) as Double

will give you 4x4 matrices of doubles.
 
That is exactly what I am looking for. Now I just have to find the simulataneous solver or rewrite my old one, and I am set.

If I get lucky, I'll have this program running in the next 6 months. It's already too late for this season, and I'm hoping I get it rolling in time to design/fab next year's car when it comes time for the overhaul.

Thanks.
 
Goska,

Ms. Access and / or VB are really quite good overall for your app. I would suggest that you look at doing the matrix operations as SQL operations on recordsets. the twenty simultaneous equations thing is probably not available 'straight out of the box', but VB hassan ENORMOUS number of third party add-ins and I would search a bit before re-writting. It HAS to be somewhat complex. If you do end up re-writting it, You should consider the use of a re-cursive routine. It 'could' save a HUGE ammount of code. Of course this is assuming that you would be using the simple substution approach.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
MichaelRed,

Is SQL set up for doing matrix algebra well? I have never attempted to code with it, and since I am an Engineer, I try to avoid learning new lanuages unless I have to. I cannot keep up with all of the code, since I spend more of my time setting up the math to do all of it than I do writing code. Basically, I view computer coding as a way of doing something repeatedly in large loops so I don't have to do it by hand. As far as the simultaneous solver, yes, it is very complicated. I wrote my own for FORTRAN. But I can do it by hand, so I can do it in code. What is a recursive routine? Mind explaining that one? It might make life easier on me.
 
SQL is not really 'set up' for anything. It is one of those deceptively simplistic languages. It has only about 100 'KeyWords' and really has the BASIC functionality of dealing with ordered sets of data. Since 'ordered sets of data' - in this instance can be viewed as arrays (e.g. columns and rows) with only a little logic relating to the various transforms, SQL could be used to simply define the set of operations and then 'run' much like a FORTRAN subroutine. The advantage to using the SQL approach is that the db engine is OPTIMIZED beyond anthing the average programmer is likely to achieve - for most operations.

Recursive functions are routines that call themselves repeatedly. They need to have some to STOP, and only ever do the same thing, often the result of one iteration is used as the input to the next, however the iteritive inputs at least need to have some variation based on the porgress of the problem. The following is one of the "Calssic" simplistic examples:

Code:
Public Function basFact(NumIn As Integer) As Double

    If (NumIn = 0) Then
        basFact = 1         'This acts as the "Stopper"
     Else
        'This is the self-reference - calls itself
        'The argument here is a FUNCTION of the Input
        basFact = basFact(NumIn - 1) * NumIn
    End If

End Function

Of course, your example would be MUCH more complex, but I can almost see the soloution of the simultaneous equation being reduced to the systematic set of replacement expressions through this mechanisim.

Since each of the simultaneous equations would be a set of coefficients, variables, operators and exponents with a additional fields for the results, these elements could be placed in a record in a table (Array). Twenty equations presumes no more than twenty variables, each requiring four fields, a table of 80 (or so) fields and twenty rows serves to completly state the overall problem in the form of a table. A routine to "solve" a given equation in terms of one variable Could then - perhaps be set up to go through the set of equations/variables and substitute the equation soloution of the variable and replace it in the remaining equations with the soloution. This could be done RECURSIVELY? until the system was resolved.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Actually, a solver for a 20 variable system would only need 21 fields per row, assuming they'll be solved using matrices (I'm not aware of other methods).

Recursion is definitely the ticket. The base case will be found when all the rows are in row echelon form. As you go back up the activation records you'll get zeroes in the rows above, resulting in reduced row echelon form and a solved system.

Good explanations of recursion aren't hard to find, and the best part is that it is almost always defined and described as mathematic induction, and recursive algorithms are always proven that way. It's probably the easiest new concept for an engineer to pick up.
 
Thanks for your advice guys. Recursion is just a new word for something that I have done for awhile. My only formal training in coding was enough to get me through the syntax, and I've developed all of my own bizarre methods on my own.

I think I am going to use VBA for this one. Run time is not important. I can start running this before I go to bed and see the numbers in the morning. This is going to be a massive program, kind of the be-all end-all of vehicle kinematics for my application, which means no significant aero forces, no banked turns, and no constant radius turns. And I have some good software for this available, but the problem is that I have to enter my points, run the program, see the results, then change my initial points to get what I want. What I am hoping to do with this one is give it a base set of points and ranges in space for these points, and have the program try incremental values in said ranges, then reject the ones that are obviously bad.

Plus, if I do it with VBA, then I don't have to write the Excel syntax into a file from FORTRAN, and I will get my graphs easily.

And as far as the actual sizes of the matrices, I am learning a new method that a freind reccomended. It is a pain to learn, but supposedly it makes all of the operations much easier to do. It is called something like homogeneous substitution with respect to a variety of points on certain bodies, and since few of my suspension linkages only have 2 ends, I think this is the way to go.

Suposedly the simultaneous solver is also easier in this method, but I want something to fall back on if I have to.

Thanks again.
 
Well, I found the right forum for me. There is a conterpart to Tek-Tips called Eng-Tips.com

Still browsing the new found site, and I'm finding all kinds of good things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top