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

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

Using equation with a matrix variable

Raied_Refaei
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?

 

RR_10441126_2-1668733741702.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

7 REPLIES 7

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.

Werner_E
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.

 

@Raied_Refaei 

Just to explain what @Strib  suggested:

Werner_E_4-1668738271334.png

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) 😉

 

Raied_Refaei
4-Participant
(To:Strib)

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

Hi,

 

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

Capture.JPG

 

It is very easy to implement and really helpful. 

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

 

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).

Werner_E_5-1668738643055.png

 

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".

Werner_E_0-1668737136979.png

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

Werner_E_1-1668737224585.png

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

Werner_E_2-1668737287419.png

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):

Werner_E_3-1668737520699.png

 

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

 

 

 

 

Raied_Refaei
4-Participant
(To:Werner_E)

I really appreciate this explanation and explaining what mentioned above.

Thank you for time, and the work.

Top Tags