Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Local or global variables in programs?

Status
Not open for further replies.

ChrMeissner

Mechanical
Jan 31, 2005
21
Hi!

I wrote some big programs to describe the dynamical behavior of cars using matrices with submatrices, that means one entry of the matrix is another matrix (e.g. shown in the result as A=([3,1] [3,3] [12,4]). So far this way. I also take references to functions defined in other files using MathCAD 2001.

The mainprogram has NO inputvariables (all values are defined in the program itself), references subroutines and give back a matrix, including the actual position and velocity of the car in vectorial notation.

When I let calculate this program more then one time, the result changes from time to time (not only the values but also the dimension of the submatrices) even NO extern variable hast changed.

May it be, that matrices in programs are intern allocated by pointers (as I know from C++)? May it be, that the variables (especially matrices) aren't realy LOCAL (that means if yo change them in a procedure, a variable with the same name outside this procedure wouldn't be changed)? How can I inhibit this (recalculate the whole worksheet doesn't work)?

Here an example for swaping the order of vectors:
uTWTw64x.gif


I know, this is a quite hard question, but has anybody an idea?

Christian M. (TU-Chemnitz, Germany)
 
Replies continue below

Recommended for you

I can't recreate your problem. When I enter the same thing, I get the same X result (your first result) in both instances. P does not change. The only way I can get your second result is to redefine P:=X explicitly before and after the second procedure.

I am using Version 11.2a. Maybe a bug in Version 2001? Are there any service packs for Version 2001?
 
Thanks for trying to help me. Meanwhile I found an general option which particulary solved the problem: in the german verion under the menu "Rechnen -> Optionen -> Rechenoptionen -> Berechnung -> Geschwindigkeitsoptimierung -> Rückwärtskompatibilität", in english versions it should be something like "calculate -> options -> calculation -> speed optimization -> backwards compatible". When I changed that, the result is correct.

BUT then I can't mix submatrices with various dimensions (e.g. A={[3,1] [7,4] [2,9]}). Now I wrote all submatrices in one very big matrix {200,70} and it works quite well although the procedure looks terrible.

Maybe we will get the new MathCAD-12 version so service packs are no longer needed.

I just tried to mix submatrices with various dimensions in a little test program and it works! Hmmm, maybe the mistake in the main program is another one.
Thanks for helping,
Christian M. (TU-Chemnitz, Germany)
 
Don't count on the last bit v12 already has one service pack with another imminent

TTFN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor