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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

4-Participant

## Using equation with a matrix variable

Hi all,

I am new Mathcad user and stuck in using matrix in an equation.

I have equation X equal to other variables, one of them is Z which is varying in intervals. I put Z in a matrix, as showing the pic.  I want X  outputs in values or matrix, but mathcad show an error.

Is there a way that can form it to get X values based of z values rather than using many separate equations?

1 ACCEPTED SOLUTION

Accepted Solutions
11-Garnet
(To:Raied_Refaei)

Careful... your formulation makes it look like you're squaring the matrix Z rather than its elements.

Define your solution variable as a vector.  Then re-write your formula to solve for each of your solution indexed elements as your formula involving one of the indexed elements of Z.

7 REPLIES 7
11-Garnet
(To:Raied_Refaei)

Careful... your formulation makes it look like you're squaring the matrix Z rather than its elements.

Define your solution variable as a vector.  Then re-write your formula to solve for each of your solution indexed elements as your formula involving one of the indexed elements of Z.

24-Ruby V
(To:Strib)

@Strib wrote:

Careful... your formulation makes it look like you're squaring the matrix Z rather than its elements.

That would be no problem! Because squaring is no valid operation for a vector, Prime automatically applies implicit vectorization.

Actually as written and explained in my answer below, not using vectorization does not throw an error but produces a wrong scalar result.

Just to explain what @Strib  suggested:

Note the vector/matrix index "i" at f and every occurrence of Z.

Sure a way to get the correct result, but definitely not my preferred method (see my answer below) 😉

4-Participant
(To:Strib)

Thank you for help and the time you spent for me.

21-Topaz I
(To:Raied_Refaei)

Hi,

Use the element by element operator Ctrl+Shift+^ to calculate element by element

4-Participant
(To:terryhendicott)

It is very easy to implement and really helpful.

Thank you for help and the time you spent for me.

24-Ruby V
(To:Raied_Refaei)

I see two failures in your picture and I strongly suggest that for future questions you always should also attach your worksheet.

The first failure, as was already pointed out by Terry, is that you need to use the vectorization operator if you want a calculation with a vector done element by element.

The second one I see is that for some reason you have an implicit multiplication between "atan" and the following opening parenthesis "(". This failure is the one which throws the error message.

Actually not using vectorization would not show an error but gives you a wrong scalar result. Reason for this is that you would multiply twice a vector with another vector and of course Prime must use the vector scalar product here (unless otherwise told via the vectorization operator).

IMHO it would be a much better approach to setup all calculation as functions depending on the values you want to vary - in your case thats "Z".

Then you can use this function to either calculate the result for single values of Z

or you can call the very same function with a vector as argument (remember to use vectorization!)

And of course you could also use this function to plot f over Z if you like (as you can see the division by zero which we get for Z=0 is generously ignored when plotting):

Setting up functions is much more versatile then setting up the calculations with vector from the very start.

4-Participant
(To:Werner_E)

I really appreciate this explanation and explaining what mentioned above.

Thank you for time, and the work.

Announcements
Top Tags