Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Static variables in M15

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-05-2014
10:44 AM

03-05-2014
10:44 AM

In MathCAD 15 programming are static variable available? That is if one subroutine is called from another programmed section can a variable in the subroutine be marked such that it remembers its value from the last time the subroutine was called?

I know this is probably a re-occurring question but the last answer could find was in 2006.

Thanks. Martin

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-05-2014
11:15 AM

03-05-2014
11:15 AM

21 REPLIES 21

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-05-2014
11:15 AM

03-05-2014
11:15 AM

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-05-2014
11:22 AM

03-05-2014
11:22 AM

Re: Static variables in M15

Thanks Werner for your prompt reply. Static variables would make life so much easier.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-05-2014
03:54 PM

03-05-2014
03:54 PM

Re: Static variables in M15

Maybe this will do what you need.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-06-2014
05:07 AM

03-06-2014
05:07 AM

Re: Static variables in M15

Richard. Hi!

Great method and will work well for me.

Thanks

Martin

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-07-2014
08:17 AM

03-07-2014
08:17 AM

Re: Static variables in M15

I don't know whether this works in Prime, but it works in M13 and M14 (haven't tested M15).

There is an undocumented feature of local function that we can make use of to act as a global memory. If an array is defined before a local function definition, then that function can manipulate the array and store values that get retained between successive calls to the function. This capability is particularly useful for generating sequences, such as the Fibonacci sequence or random number generators such as the Mersenne Twister.

The Fibonacci functions given below allow the user to generate successive Fibonacci numbers simply by calling the function setfib and retrieve the current list using the function getfib.

Stuart

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-07-2014
10:35 AM

03-07-2014
10:35 AM

Re: Static variables in M15

I never heard of that undocumented feature but it sounds great.

The picture you inserted is not showing up.

Am I right that the return "value" of that kind of program must be one or a set of fuctions? So if I want to rewrite an existing function to accomodate that kind of global/static variable, I would have to wrap it and make it a local function of the outer wrap?

I am not sure if we are supposed to understand what exactly is going here. I am still wondering about the effect that deleting the factor 1 in the local get() function has. Either any subsequent call of set() has no effect (which seems not to be the case given the return value of set) or set() and get() are playing with different "global" vectors, or ???

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-07-2014
10:58 AM

03-07-2014
10:58 AM

Re: Static variables in M15

Stuart! Long time no see. I guess you didn't get washed away in the floods then

Neat trick. I can confirm it works in MC15 too.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-07-2014
11:17 AM

03-07-2014
11:17 AM

Re: Static variables in M15

Neat trick. I can confirm it works in MC15 too.

And it even works in Prime 3, too. Just did the conversion.

No clue how it works and whats about the 1*v

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-10-2014
02:09 PM

03-10-2014
02:09 PM

Re: Static variables in M15

Hi Richard, Werner,

Fortunately, I live halfway up a hill (I'm applying for a position with the Duke of York) and the water didn't cause me too many problems. The wind did, though - it's costing me a fortune in replacement fence panels, but not, I'm glad to say, solar panels. Lots of impressive flooding for the area and quite a few closed roads, but none that particularly affected me.

I've been quiet on the Mathcad Front because I haven't touched it much in the past year or so - a minor spot of illness, which also meant that I missed out on the Prime 3 testing putting me well behind the drag curve.

I've just dug out Mathcad again to do some data analysis at work. I'm just hoping that this time I don't have redo everything in Excel "because that's the tool that the engineers understand" ... yes, I know, but I've long ceased to wonder at the iniquities of life or puzzle over why people seem to think that a geological hammer is the ideal tool for inserting and removing watch screws. It took me minutes to get back up to speed on Mathcad and I haven't yet come across any other application that requires so little "refresh" time.

I have no idea how the 'undocumented feature' works either. I'm wildly guessing that multiplying by tricks the compiler into picking up the address of the variable the first time it's compiled.

Cheers,

Stuart

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-10-2014
04:28 PM

03-10-2014
04:28 PM

Re: Static variables in M15

So welcome back, Stuart and thanks for sharing this really interesting undocumented feature. Not sure what the fact that it still works in Prime tells us about Prime's development.

Hope you can convince people that Excel sure is on the end of the list of possible tools for doing engineering calculations - but its the wrong end.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-10-2014
06:38 PM

03-10-2014
06:38 PM

Re: Static variables in M15

(I'm applying for a position with the Duke of York)

But then you would only be halfway up the hill, on average. When you were at the bottom you would get wet, and when you were at the top the wind problems would be even worse. In fact, assuming a linear relationship between height and wind problems, on average the wind problem would be the same as you have now, but on average you would also be damp.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-11-2014
07:47 AM

03-11-2014
07:47 AM

Re: Static variables in M15

Ah hah! There is madness in my plan ... no, cunning in my plan, because on average the wind will evaporate the water! <smug> Of course, the windchill is probably going to be a problem, but ...

I can tell that you've been across the Pond for too long. You've forgotten that there is no relationship between any given UK weather property and any other property, nor is the same property even remotely autocorrelated in time. I've stood in an air traffic control tower, one half of which was encompassed in doom, gloom, cloud down to the ground, heavy rain & zero visibility and the other half was in bright blue sunshine and CAVOK - there was a classic front passing right through the middle of the tower and what amazed me was just how straight and long it was. In fact, thinking about it, my cunning plan has just blown itself away as there is no analytic relationship between water density or wind and height but Murphy's distribution function will ensure that, no matter where I am, I will always get the worst of wind and rain.

Stuart

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-11-2014
05:59 AM

03-11-2014
05:59 AM

Re: Static variables in M15

"because that's the tool that the engineers understand" ...

Thanks everyone: it is an interesting discussion I started. Didn't realise it was going to be so good.

I've been using MathCAD since M2 I think and love the fact that it will calculate the units. That alone makes it so worthwhile as it's an additional check that your formulae are correct. But I reckon there is a lethargy among engineers to spend time on something that may save time tomorrow and so they continue with Excel.

MathCAD used to sell the software at a fantastic discount prior to a new release and that's how I started. Now I have to twist arms to get the company to buy a new version!

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-11-2014
07:59 AM

03-11-2014
07:59 AM

Re: Static variables in M15

I've managed to convince a few engineers, from time to time, that Mathcad is a good choice but it's getting the idea past the Uniformity and Standarization State Police that's often the problem, or programme managers who either can't or won't swing money out of the Effort Budget into the Materiel Budget, even though it saves on overall programme cost and time.

My biggest problem at the moment with Mathcad, however, is that from my perspective it's effectively remained static from a capability point of view and just isn't taking advantage of it's natural interface advantage (eg, improved mathematical notation, integrated drawing tools and libraries, worksheet-level looping and subsheets) or expanded it's functional capability into such things as multidimensional arrays (MDAs very useful for analyzing and viewing data with multiple, highly correlated parmeters (eg, temperature versus 3D position) or dealing with tensors). I can't see it happening either, which is a shame as I'm not sure how it's really going to compete with the likes of Matlab, Maple or Mathematica without the ability to handle MDAs / notation / structure. Sadly, I see it ending up being a niche tool in the hands of a few, just like some other potentially useful software that never really offered enough (in the right places) to become more widespread.

Stuart

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-11-2014
08:29 AM

03-11-2014
08:29 AM

Re: Static variables in M15

Recently, I spent several months trying to persuade one engineer that was using Excel to try SMath, which wouldn't even cost him anything. He kept saying "OK", but didn't even download it. Then one day, about a week ago, he was working on a problem in Excel that was giving him problems (guess what: some of them were unit problems!) so he asked me to do it in Mathcad for him. So I reminded him about SMath, and he finally tried it. The reaction? "Oh my God! This is just the tool I've been looking for for years!". I didn't say anything. Maybe if PTC can advance Prime faster than a group of volunteers is advancing SMath (which is questionable) he might splash the money for Mathcad at some point.

My biggest problem at the moment with Mathcad, however, is that from my perspective it's effectively remained static from a capability point of view

In what way is retrograde motion "static"?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-11-2014
09:28 AM

03-11-2014
09:28 AM

Re: Static variables in M15

Richard Jackson wrote:

Recently, I spent several months trying to persuade one engineer that was using Excel to try SMath, which wouldn't even cost him anything. ...

I haven't looked at SMath for a couple of years, so I've just downloaded it. I'm impressed with the integration of symbolic and numeric maths on the ODE example I looked at, as well as the hover and inspect results.

Maybe if PTC can advance Prime faster than a group of volunteers is advancing SMath (which is questionable) he might splash the money for Mathcad at some point.

My biggest problem at the moment with Mathcad, however, is that from my perspective it's effectively remained static from a capability point of viewIn what way is retrograde motion "static"?

Mummy raised me to be polite.

I guess it could be regarded as static if we regard it as a combination of Mathcad 15 and Prime? Actually, that's slightly unfair as there have been some improvements, but they all seem so peripheral and Prime (IMO) has got some work to do to get it philosophically back on track (*eg, I can't wrap my head around why Prime would even want to drop the original Whiteboard concept and go to a serial page format only, I used to make a lot of use of the extra right hand sheets and have them printed out; some of the "changes" strike me as being aking to taking an old model Ferrari and, instead of equipping it with more modern technology, putting in a carburettor 2.0 litre engine, keeping narrow tyres, doing some body restyling and putting in a cassette player to replace the 8-track*).

Stuart

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-11-2014
09:59 AM

03-11-2014
09:59 AM

Re: Static variables in M15

I haven't looked at SMath for a couple of years, so I've just downloaded it. I'm impressed with the integration of symbolic and numeric maths on the ODE example I looked at, as well as the hover and inspect results.

It's got some nice features. To get some of them you have to install plugins though. For example, the native 2D plots are even more inadequate than those in Prime, but there is a plugin that gives you excellent 2D plotting. There are some other holes too, such as no support for vectorization, no symbolic integrals. But for the price it can't be beat

I can't wrap my head around why Prime would even want to drop the original Whiteboard concept and go to a serial page format only,

You can make it go to the whiteboard format. There are some small icons at the bottom right of the screen.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-11-2014
10:23 AM

03-11-2014
10:23 AM

Re: Static variables in M15

>> whiteboard format

True, You can also use the tab on the page to do that...but the area is unprintable, IIRC, whereas in M15 one can choose to print or not to print...;-)

~R~

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-11-2014
10:48 AM

03-11-2014
10:48 AM

Re: Static variables in M15

Yes, I had thought it was unprintable ... which is pretty well what my first thought was when I found out. I find it strange that a company that deals in documentation ("PTC’s end-to-end dynamic publishing solution streamlines how organizations create, manage, and publish technical information.") can miss out such a capability. Or, more to the point of my previous comments on the direction Mathcad isn't taking, not design Mathcad to work from the initial informal, messy concept and playing with variants, through the slicker presentation layout, and onwards to design, validation and publication. They must surely have the requisite mix of skills and technology to do this without breaking a sweat?

Stuart

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-11-2014
08:51 AM

03-11-2014
08:51 AM

Re: Static variables in M15

I agree that it is difficult to see Prime competing in the future with MATLAB | Maple | Mathematica. I find MATLAB very easy to use, very good for quick work, and very good w matrices (of course), with decent IO capability & graphics, but falls short in the units and document areas. Maple and Mathematica are better in the document areas, and far more powerful than MATLAB and Mathcad in many ways, but complicated to use. A recent discussion with the Mathematica folks about units showed just how sad that particular feature is compared to the rest of the tool. I also recently did some trivial work w Christoffel symbols to compare with MATLAB and Mathematica. The setup was simpler in both of them, but the end product was clearer in Mathcad 15. Two of us here tried to convert to Prime, but the converter choked on nearly all but the text in the document, making the conversion too expensive time-wise. I suppose that I could have done it in Prime to begin with, but my experience with Prime is that I get halfway through a large piece of work, only to find that Prime will not do what M15 will do, and I must begin anew in M15...so my habit, regrettably, is simply to begin in M15.

Maple | Mathematica are making great strides in the areas of physics (my area), and Mathematica, at least, has some efficiencies handling programming loops.

Though I prefer M15 in the long run, I keep going back to the MATLAB | Maple | Mathematica pool because they are moving ahead faster than PTC. At the current pace, it will not be long before Maple | Mathematica can replace M15, I think. MATLAB is in a class by itself, and I am not sure that I see its strengths being rolled into either of the other two. Its IO and ease of handling matrices is so far ahead of Mathcad that I can't see any competition at all.

~R~

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-11-2014
09:33 AM

03-11-2014
09:33 AM

Re: Static variables in M15

It's somewhat of a shock to realize that I wrote my first multidimensional array library in Mathcad getting on for a decade ago and had been using Mathcad even further back to integrate with Matlab. A decade to not implement adequate support for MDAs beggars belief. There was such potential for Mathcad to make inroads into the maths app market ... <sigh>

Stuart