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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! 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

1 ACCEPTED SOLUTION

Accepted Solutions


@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


@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

 


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

Top Tags