Skip to main content
Best answer by Werner_E

max is a LOCAL column-vector INSIDE the program! It is then returned in a vector and when the program is invoked and the result assigned a variable the vector is whatever you name that variable.

The reason you get this special result when you try to evaluate max outside of the program is because max and min are also built-in predefined functions of Mathcad. Otherwsie you would get an error as of that variable being unknown.Maybe it would have been less confusing if I named them differently.

See attached for some usage examples.

3 replies

25-Diamond I
March 31, 2013

because the variable b you use in your program is a local variable which has no connection to a variable with the same name in the sheet.

The output of your program has not yet been defined and aould then have to be assigned (a function or a variable), in your case you would have to put a "b:=" in front of the program (after specifying for the program output should be).

JohnDoe1-VisitorAuthor
1-Visitor
March 31, 2013

Ok.

Here I would expect to get a 1 as a value for b. Why do I get two values and why 0.25 and 0.75?

31-03-2013+15-17-03.jpg

25-Diamond I
March 31, 2013

Because a function returns what you state in the return statement. If this is missing it returns the last expression being assigned.

In your example r is in the upper half plane so b gets 1, and the last assignment in that branch is that of the range variable l_Umin.

As a with your r is very small, that range begins with approx 0.25, next one is 0.75 and this is already the last, as the next one would be 1.25 which is already larger than the upper limit l/lamda, which is approx. 1.

I think you will have to reconsider the whole program, as I guess you will need not only b but l_Umin, etc. too for later calculatons.

Please keep in mind that l_Umin are NOT vectors but range variables - a big difference. You might consider making them vectors.

JohnDoe1-VisitorAuthor
1-Visitor
March 31, 2013

I noticed one small problem with this expression:

31-03-2013+19-33-47.jpg

It may happen that a + 0.25 is already above end. In this case there is no minimum. But this line adds 0.25 to "a" in all cases and supposes that a minimum must exist.

How can we consider this special case?

25-Diamond I
March 31, 2013

Our function returns a vector for lUmin and it has to do so in every case. Thats the reason I had to assign the vectors consisting of 0 each if r is null. The same applies to that special case of yours. You have to return a vector for min. It depends on what you intend to do with those vetcors. If its not appropriate that the value is a+0.25 you have to insert an if-condition if a+0.25>end and set the vector to a value of your choice.

It depends on how you would use that vector later. You even don't have to return a vector for min. So you could later check via "if rows(l.Umin)>0" if a vector was returned or a simple number. You can return a text or a vector with a text as an element. It all depends on how you use the result later and which way you will want to check if ther are minima.

JohnDoe1-VisitorAuthor
1-Visitor
April 1, 2013

You see the point in this program is that the difference between a maximum and a minimum is always 0.25.

Now there is the case if arg (r)>0 and a=0.25. The first Umax would be at a=0.25 and we add a+0.25 to get the next Umin. However in this sprcial case there exists also a minimum at zero because also 0.25 from Umax.

This is not considered in the line for Umin. One solution is in this special case of a=0.25 to augment the vector of Umin by the first value 0. Do you know how this works?

JohnDoe1-VisitorAuthor
1-Visitor
April 1, 2013

I tried to eliminate the extra Umin (the automatic one) in an if statement:

01-04-2013+17-04-53.jpg

However I get the error: This function requires at least 5 arguments but is applied to 3.

What argument should I put for the colums? I have only one culumn in my vector Umin.

When trying this:

01-04-2013+17-10-16.jpg

I got the error: You cannot perform an operation on a non existant row or column.

Any idea?

25-Diamond I
April 1, 2013

Just a short notice to let you know that the program I supplied has an error as I had not noticed that shifting for pi (for negative arguments) would change min and max. So the values are wrong (changed) for all r's with negative imaginary part. I'll try to clean up later.

According submatrix: Built-in help shoud help, 2nd and 3rd argument are start row, end row, and the last two are start column, end column. You have to provide all of them, even if its a column vector. A routine "subvector" is on the wishlist for a very long time but so far we have to do with selfwritten routines (like the fine collection of Stuart).