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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

example function returning different units.xmcd

ptc-4094973
1-Visitor

example function returning different units.xmcd

This is a Mathcad 15 example of a function returning multiple values with different units.

4 REPLIES 4
Werner_E
25-Diamond I
(To:ptc-4094973)

Interesting approach.

You can achieve a similar effect using symbolic evaluation:

1.png

RichardJ
19-Tanzanite
(To:ptc-4094973)

The symbolic evaluation of a program may fail though, whereas I think Christian's approach will always work. It's interesting that the second element of the matrix picks up on the local assignment in the program. You can also make the second element a program, and it sees all the local assignments in the program that is in the first element.

Werner_E
25-Diamond I
(To:ptc-4094973)

Yes, I, too, can imagine the symbolic eval method to fail now and then.

Christians approach is very interesting and may open new possibilities.

I am still not sure if the behaviour really is as it should be - the question being what a local assignment is local to. On the other hand we had often used a simple local variable assigment (= 1 line "program") in an element of a vector and used the assigned variable in the next vector element. Seems to be the same mechanism.

Interestingly the return statement is not allowed, throwing a "bad_pattern" error:

1.png

RichardJ
19-Tanzanite
(To:ptc-4094973)

In MC11 you can do this:

vector+assignment.png

In MC12 they broke that by making the assignments parallel, rather than sequential. So in MC13 and later they gave us a compatibility mode (that defaults to MC11) that unbroke it . It seems that when the assignments are in a vector the local program assignments are seen as in scope for all the subsequent assignments in other elements of the vector, but I doubt this was by conscious design. It could be a very useful oversight though. It appears to also work in Prime.

Announcements

Top Tags