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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Translate the entire conversation x

Mathcad Returns Error When Attempting To Use A Vector Input For A Piecewise Function

NickSaia
2-Explorer

Mathcad Returns Error When Attempting To Use A Vector Input For A Piecewise Function

Hi,

 

I'm using a range variable and multiple functions to plot the capacity and demand of a beam system to check for failure.  This works well and as I intend.

 

NickSaia_0-1754504093363.png

NickSaia_1-1754504113277.png

 

The problem arises when I want to find the specific utilization of the member along it's length.  To do this, I wanted to create a vector containing the input lengths instead of a range variable, so that I can perform math on the functions and output a vector.  This way I will have a vector of the members utilization along its length and won't have to manually check separate inputs.

 

NickSaia_2-1754504375167.png

 

As shown in the image above, the vector "v" works as an input into function "V(v)" but not in the function "Va(v)".  Is this because "Va(v)" is a piecewise function?  Is there a way to evaluate this function using vectors?

 

If there is a trick to getting vectors as inputs to functions, or simply a better way entirely to accomplish the task of creating a single vector with the utilizations as I described, I would greatly appreciate the assistance.

 

Please see attached worksheet. The utilization checks are on page 4 of the worksheet.

I am using Mathcad Prime version 10.0.1.0.

 

Thank you,

Nick

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:NickSaia)

Fortunately there is an easy solution to your problem.

Your function are written for a single scalar argument x.

If you instead provide a vector as argument it may work well, but also can fail or return wrong results. Multiplications may be taken as vector scalar product and if you use comparison operators like in your function Va (eg. ..x<L/2) the function will fail as you cannot compare a vector x with a scalar L/2.

 

Solution is to use vectorization whenever you provide a vector as argument instead of a scalar and want the function to be applied element by element.

Werner_E_0-1754510090296.png

I feel its good style and you are on the save side if you use vectorization always when you call a scalar function with a vector argument, no matter if Prime would apply automatic vectorization (as in function V) or not (as in function Va).

Werner_E_1-1754510291436.png

Prime 10 sheet attached

 

 

View solution in original post

1 REPLY 1
Werner_E
25-Diamond I
(To:NickSaia)

Fortunately there is an easy solution to your problem.

Your function are written for a single scalar argument x.

If you instead provide a vector as argument it may work well, but also can fail or return wrong results. Multiplications may be taken as vector scalar product and if you use comparison operators like in your function Va (eg. ..x<L/2) the function will fail as you cannot compare a vector x with a scalar L/2.

 

Solution is to use vectorization whenever you provide a vector as argument instead of a scalar and want the function to be applied element by element.

Werner_E_0-1754510090296.png

I feel its good style and you are on the save side if you use vectorization always when you call a scalar function with a vector argument, no matter if Prime would apply automatic vectorization (as in function V) or not (as in function Va).

Werner_E_1-1754510291436.png

Prime 10 sheet attached

 

 

Announcements

Top Tags