cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Meaningful Error Messages

Efried
1-Newbie

Meaningful Error Messages

Hello,

allow me to explore if Mathcad V15 will bring me some relief in cosntrast to V14 M020.

I'm struggling with a 4p long code (programm). It had started to claim that units were different that they should be. After killing the (correct) expression and replacing it by "1", the complete code turned red....

So I'm searching for an imprveenet of the situation, which might be caused by sheer size of the program or list of variables and functions handed over?

Attached the version I started from and got deeper into trouble...

thanks

52 REPLIES 52
RichardJ
19-Tanzanite
(To:Efried)

1) the return vector is corrected as you may see so all variables have "J" as unit

The unit checking thinks otherwise. It says most of them have units of time, but a couple have units of Joules (actually, the ones you multiplied by J).. Note that I added a 1 to the end of the vector, so that the other entries have to match a dimensionless quantity. It's possible for the static unit checking to be wrong about the actual return units, because it can't know what units you will use when you pass arguments to the program, but I think the mismatch is a real problem. If they are al supposed to be the same then there must be a problem somehwere else in the program.

2) if you don't remove the unit W but exchange TOL by 0 in the P.antr_m[nn]<-TOL W the same healing of the programm occurs (after removing the return block)

3) there is another comparison of P.antr_m[nn] some lines before using 0 W

That's a quirk of Mathcad. A quirk that I personally consider a bug. If it sees a zero, it ignores the units. You can easily see this if you just type

0 * kg <Ctrl>= 0 * s =

and you will get the answer "1". IMHO, 0 kg is not equal to 0 s.

MikeArmstrong
5-Regular Member
(To:RichardJ)

0 * kg <Ctrl>= 0 * s =

and you will get the answer "1". IMHO, 0 kg is not equal to 0 s.

I can't believe that result. How can that not be a bug?


Does Mathcad ignore the units because the numerical value is zero?


Mike

Does Mathcad ignore the units because the numerical value is zero?

That's exactly why it does it. When Mathcad sees 0*anything, it doesn't bother to check what "anything" is, and just returns 0. I was told, many years ago, that this was because 0*anything is always 0, and so not calculating "anything" (which could be a complicated expression), saves time. I wouldn't argue about the time savings, but 0*anything is not always 0. The example above is only one nasty side effect. Consider this function (name chosen quite deliberately!)

BS(x):=x/x

evaluate that for x=0, and you get the answer 0, which is wrong (it is of course undefined).

BS(x):x/x

BS(0) in Mathcad Prime 1.0 gives no result with the correct error message that "The expression is divided by zero. It cannot be computed."

I also get no result in Mathcad 15, with the error message "Divide by zero."

What version were you using?

And for your other example:

0*kg Ctrl = 0*sec does give 1 or true in Mathcad 15.

However in Mathcad Prime 1.0, the result is 0 or false.

unit-error.png

Mona

RichardJ
19-Tanzanite
(To:mzeftel)

I also get no result in Mathcad 15, with the error message "Divide by zero."

What version were you using?

M005 [MC15_M005_20101002].

I'll install the latest version and see if it makes any difference.

Efried
1-Newbie
(To:mzeftel)

Mona we wer speaking about program blocks most of the time and pretty sure that the unit handling and error messages is odd in the block! Mathcad is a perfect tool for pencil and paper type calculations though and no need to improve because of trial and error possibilities...

But in programm blocks this is very cumbersome if they are bigger.

thanks

BTW: please think about an automatic cosumentation tool providing a data dictionary in program blocks at least

mzeftel
1-Newbie
(To:Efried)

Gerfried,

I'm not a programmer, so can you provide more details about what you want for an automatic cosumentation tool providing a data dictionary in program blocks. That's not something I'm familiar with. I can then log it as a feature suggestion.

Thanks,

Mona

Efried
1-Newbie
(To:mzeftel)

Pseudocode for the xmcd file (actually XML)would be I guess:

extract all <ml:id> elements within the <ml:function> element

sort them

remove doublettes

As add on comments attached to the tags should be included .

thanks for asking

regards

Gerfried

RichardJ
19-Tanzanite
(To:mzeftel)

BS(x):x/x

BS(0) in Mathcad Prime 1.0 gives no result with the correct error message that "The expression is divided by zero. It cannot be computed."

I also get no result in Mathcad 15, with the error message "Divide by zero."

What version were you using?

I just installed M005 [MC15_M005_20101105]. I still see BS(0)=0.

It has been this way for a very long time though (at least as far back as MC11, and I think even further than that), so I am not surprised. I am surprised you see something different.

Richard,

This is what I see in Mathcad 15 M005.

divide by zeror.png

I have the default settings, so I'm not sure why you have a different result.

Mona

MikeArmstrong
5-Regular Member
(To:mzeftel)

My error message. Mathcad 15 M005.


Clipboard01.jpg


Mike

RichardJ
19-Tanzanite
(To:mzeftel)

I have the default settings, so I'm not sure why you have a different result.

This is why:

divide by zero.gif

For some reason I have this turned on in my normal template for both MC13 and MC14/15. Probably for backwards compatibility with MC11, which does not have this option, but I don't remember setting it

MikeArmstrong
5-Regular Member
(To:RichardJ)

BS(x):=x/x

evaluate that for x=0, and you get the answer 0, which is wrong (it is of course undefined).

I don't in Mathcad 15 005.


Mike

Hello,

here is the proof that it may work how I intended to handle the units (not only no error in this sheet but it also calculates) - I have included the last program which worked before mathcad went extreme - stalling without storing and then throwing odd errors.

I will go into analysis what the difference in terms of unit handling is between the two version is later.

Thanks for your continuous support

At least we know now that revamping the Mathcad UI is not the most important step in order to make mathcad a productive tool for lengthy simulations.

No, its debugging - and I learned that the author of smath had started doing so - Am I right that he had implemented a debugger for Mathcad? How to get that?

Gerfried

RichardJ
19-Tanzanite
(To:Efried)

No, its debugging - and I learned that the author of smath had started doing so - Am I right that he had implemented a debugger for Mathcad? How to get that?

I haven't heard of it. There have been various debuggers posted to the forums over the years, but I can't think of any that have been posted since Mathcad finally implemented it's own debugger for programs.

I don't see how any user written debugger could help here anyway. The Mathcad program does not execute, so it's not possible to step through it with a debugger. What is needed is for Mathcad to show the complete logic tree for the static unit checking, but there is no way to make it do that.

I would be very happy having a static error check at first. A tool extracting all the variables from the xmcad file (from programs only), kind of parser...

Could be named documentation tool - resulting in a data dictionary. I 2 ich away to check out XSLT possibilities but hope you have/know such a tool..

thanks

regards

RichardJ
19-Tanzanite
(To:Efried)

Sorry, I don't know of such a tool. If you write one please post it here though

Sorry I have other urgent productive work now. But the pseudocode could be:

Use XPath

//ml:id extract all <ml:id> elements

sort them

remove doublettes

One thing I don't know is whether embedding the subscript in the tag will prevent....

<ml:id xml:space="preserve" subscript="ZH">a</ml:id>

The obvious question however is - Why the hell is PTC so inactive in providing such programming support like data dictionary for the professional?

Are they concentrating on simple area calculations for the CAD staff as target group?

I think they are loosing a lot of people to Matlab this way.

regards

Efried
1-Newbie
(To:Efried)

The XPathbuilder dis the first job //ml:id, the manual work followed to compile the XLM data dictionary.

Also units had to be removed to compile the list of variables which makes unit checking difficult - may be this is the source of the problems that the ml:id tag is used both for variables and units.

No error detected so far but realised on vialoation of a rule:

my programm hands over variables with dimensions. I don't know why this has not been a problem for me in the past - it calculates easily- but now it is a problem- may be also because I'm handing over functions to the programm. Is it forbiden to hand over programms to programms?

thanks

regards

RichardJ
19-Tanzanite
(To:Efried)

Is it forbiden to hand over programms to programms?

No, there is no problem doing that.

Thanks for the answer- what about the second question:

Is it allowed to hand over veriable with units to a programm?

If no why it had worked so far?

thanks

MikeArmstrong
5-Regular Member
(To:Efried)

Is it allowed to hand over veriable with units to a programm?

If no why it had worked so far?

It depends what your doing with the variable.

Mike

RichardJ
19-Tanzanite
(To:Efried)

Is it allowed to hand over veriable with units to a programm?

Yes, it's allowed.

Top Tags