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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

how to put matrics in IF function in mathcad

ptc-4605467
1-Newbie

how to put matrics in IF function in mathcad

Hello Friends,

I am facing a problem for putting a IF function for a matrics

a=(1

2

3

-5

10)

Thats a is in matrics format.

WL=3

if function reqired that

h= if a>WL then WL

else if a<0 then 0

else WL

Now i am not getting the solution due to "a" is in matrics format and WL is a scalar format

and i want "h" also as matrics format.

Expected answer of h=(1

2

3

0

3) But i want to know how to write the programm for that

1 ACCEPTED SOLUTION

Accepted Solutions

Next time please attach a worksheet which shows your attempts and make clear which version of Mathcad your questions relates to.

Find attched two different approaches:

1) a generic function

vecif1.png

2) a more simple and specific approach, avoiding programming and using nested if-functions (you may use Micheals function instead with this appraoch):

vecif2.png

EDITED as you seem to have problems implementing Micheal's approach. Unless explicitely stated that Prime is to be used I assume "real" mathcad (that is version 15 or 14). In that version we don't have "else" or "elsif", so "otherwise" is used instead:

vecif3.png

View solution in original post

7 REPLIES 7

Attaching your worksheet using the advanced editor (see the upper right-hand area of the normal editor) will help people see what you are doing. I strongly suggest you do this.

if function reqired that

h= if a>WL then WL

else if a<0 then 0

else WL

Try

h[i= if a[i>WL then WL

else if a[i<0 then 0

else WL

where [i is the subscript character and i is the indices of the matrix.

Hey Thanks MichaeIh

But that gives me the value of scalar.

Means I am expecting "h" answer also at matrics format like a

Expected answer is

h=

(1

2

3

0

3)

It should work if implemented correctly.

Note that programming loops in Mathcad are aware of variables outside the loop but cannot change them. The answer is passed via the "return" statement, so this might be tricky for the beginner to implement.

Something like this should work:

XX(i)= if a[i>WL then WL

else if a[i<0 then 0

else WL

h[i= XX(i)


Please attach a worksheet for people to look at.

Next time please attach a worksheet which shows your attempts and make clear which version of Mathcad your questions relates to.

Find attched two different approaches:

1) a generic function

vecif1.png

2) a more simple and specific approach, avoiding programming and using nested if-functions (you may use Micheals function instead with this appraoch):

vecif2.png

EDITED as you seem to have problems implementing Micheal's approach. Unless explicitely stated that Prime is to be used I assume "real" mathcad (that is version 15 or 14). In that version we don't have "else" or "elsif", so "otherwise" is used instead:

vecif3.png

I am working on Mathcad Prime 2.0

I am asking the question for very first time thats why i do not know how to attach the file

I am not able to open the attached file still it is so i will try to write the program in mathcad prime.

But the answer you gave is safisfactory.

Thank you for that.

nagraj deshpande schrieb:

I am working on Mathcad Prime 2.0

It shouldn't be that difficult to retype the few lines, but just in case find attached the converted sheet.

I am asking the question for very first time thats why i do not know how to attach the file

As Micheal already wrote - in the upper right corner you have to choose Extended Editor to be able to attach files. Unfortunately thats not default.

I am not able to open the attached file still it is so i will try to write the program in mathcad prime.

Its inapprehensible but Prime cannot open files created with prior versions. You have to convert them first which can be done out of prime but you need to have the current version of Mathcad 15 installed to be able to do so - incredible elaborate and complicated - thats PTCs way of implenting a "more user friendly" interface.

But the answer you gave is safisfactory.

Thank you for that.

You're welcome!

Top Tags