×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Local or global variables in programs?

Local or global variables in programs?

Local or global variables in programs?

(OP)
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:


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

Christian M. (TU-Chemnitz, Germany)

RE: Local or global variables in programs?

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?

RE: Local or global variables in programs?

(OP)
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)

RE: Local or global variables in programs?

Don't count on the last bit v12 already has one service pack with another imminent

TTFN

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close