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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Calculate multiple values using the same equation

cfelice
4-Participant

Calculate multiple values using the same equation

I have a simple equation but want to use different input values and calculate the results without repeating the equation.  How do you do this?

 

I am using MathCAD Prime 9.0

ACCEPTED SOLUTION

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


@cfelice wrote:

I have a simple equation but want to use different input values and calculate the results without repeating the equation.  How do you do this?

You simply turn the calculation/equation into a function of the input values.

 

For example

Instead of

Werner_E_0-1702748307574.png

You define a function and use it with different input values

Werner_E_1-1702748332360.png

 

View solution in original post

4 REPLIES 4
Werner_E
25-Diamond I
(To:cfelice)


@cfelice wrote:

I have a simple equation but want to use different input values and calculate the results without repeating the equation.  How do you do this?

You simply turn the calculation/equation into a function of the input values.

 

For example

Instead of

Werner_E_0-1702748307574.png

You define a function and use it with different input values

Werner_E_1-1702748332360.png

 

cfelice
4-Participant
(To:Werner_E)

I also found that using a X by 1 matrix will also work.

 

cfelice_0-1703160043396.png

 

Werner_E
25-Diamond I
(To:cfelice)


@cfelice wrote:

I also found that using a X by 1 matrix will also work.

 

cfelice_0-1703160043396.png

 

 


This method is a bit limiting compared to a functional approach, but if thats what you need - why not.

But use it carefully - depending on the calculations used the method may fail.

This works:

Werner_E_1-1703181169422.png

But written this way the result is not what you may expect.

Werner_E_2-1703181243981.png

Reason is that x*x is calculated as vector dot product.

You can fix it by applying vectorization - which is advisable to use always when you want a calculation written for a single scalar should be applied elementwise at the elements of a vector.

Werner_E_3-1703181418119.png

 

The first example (using x^2) worked because Prime applies automatic implicit vectorization if an operation (like squaring) is not defined for vectors.

cfelice
4-Participant
(To:Werner_E)

Caution noted - thank you.

Announcements

Top Tags