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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Translate the entire conversation x

Symbolic solver unit conversion with further substitution

Ivan_Pat
12-Amethyst

Symbolic solver unit conversion with further substitution

Dear PTC Mathcad Community,

I want to ask for clarification on the behaviour of units and symbolic substitution in Mathcad Prime (similar topics have already been raised, but I still haven't found an appropriate answer for my issue).

 So I try to find a symbolic expression for epsilon_c2, which is a parameter of the equation N.

Solver succeeded with the issue, but with incompatible units (see picture)

Ivan_Pat_0-1765875279227.png

So, I have tried to find out the solution in the community, but the advice of @Werner_E  with calculation options didn't resolve the issue (see the picture)

Ivan_Pat_1-1765875431392.png

So my issues are: 

1. How to make the symbolic solving more "seamless" with appropriate units' manipulation in the solutions?

2. Why does Mathcad not see the assigned values of the  epsilon_c2 obtained in the previous solution?

Ivan_Pat_2-1765875677338.png

 

After some time, when the file has been refreshed, some magic happened, and now I can use the roots of epsilon c1 and c2 in a "normal" manner.

Ivan_Pat_1-1765882285970.png

But the next issue is that it doesn't let me substitute the obtained symbolic solution into the following step calculation for the moment M calculation.

Ivan_Pat_0-1765882122108.png

As it can be seen, the factual equation is real, with proper units,

Nevertheless, Mathcad is still not satisfied with...

 

I am still convinced of Mathcad's power, but each time I get stuck with such a misunderstanding of Mathcad logic, I feel broken, exhausted and unable to continue to the next step - automation of my manual solution.

 

Any clarification, examples, or references to documentation would be greatly appreciated.
I am trying to align my workflow with my Mathcad Prime 10.0.0.0 internal logic rather than fight against it.

Thank you very much for your time and support.

 

The file with the manual calculation of M is attached.

 

65 REPLIES 65
Werner_E
25-Diamond I
(To:Ivan_Pat)

It looks like there is an (implicit) multiplication between "Re" and the openeing parentheses "(".  Delete it.

 

BTW, your error handling

Werner_E_0-1766928019565.png

does not work. If something went wrong you store a text string in ec2 and then you still use ec2 in subsequent calculations which will throw an error because ec2 is not a number.

You may try to use NaN instead and see if it works.

The program runs OK if you delete the implicit multiplication between Re and (, but you have to decide if using just the real part of a non-real solution gives you a correct result.

As the solutions for ec2 you choose from stem from an equation of second order with (as I suppose) real coefficients, either both solutions would be non real or none.

Choosing the smallest of both solutions only works if the solutions are real. This would require that you calculate both solutions  and use the minimum (which then also may be negative).

 

One way to avoid the copy and paste of the symbolic solutions you calculated is to turn these calculations into functions.

It does not make much sense that you define 

Werner_E_1-1766928508776.png

because what you actually define that way is the resulting 2x1 vector to the very right which contains a lot of variables but sure not ec2.

I understand that you tried to document that the expression you use for solving is q(...).

 

You could do it that way:

First define q as a function of all variables involved (as none of them is already defined at this stage.

Werner_E_2-1766928694947.png

Then solve this function for ec2 and assign the result (which is a vector with all values for ec2) to a function whose name should be something with ecs (and some name part which distinct this from all the other functions which also would calculate ec2).

Werner_E_3-1766928810768.png

Later you could use this function providing all variables and evaluate it numerically and then examine the vector you get and chose the solution according to rules you have to provide (e.g. take the smallest if both are positive, use the largest if one is negative, return NaN if both are non-real.

I don't know if if makes sense in your workflow but after you defines the variables in front of your program to calculate ec2, only ec1 and F_ seem to be left unknown as F_ is calculated in the program.

You could as example define a new function now

Werner_E_4-1766929194721.png

This function calculates the two values for ec2 and selects one following the logic outlined above. I have no idea if that's the logic you need, though.

You can now use this function in your program instead of the huge expression you copied there.

The function I mentioned can be found in the attached file.

I did not use it in the program because I had no idea where 😉

When you use it you sure have to use ec2 with index i of course.

 

Ivan_Pat
12-Amethyst
(To:Werner_E)

I have an idea to check whether each condition is a real number using my function by defining the minRealRoot function (see the picture), but, to be frank, I'm only on my way to it (((, cause even on this simple sample I do not understand how the condition is to be formulated correctly...

I want to choose only the minimal real root, otherwise to assign, let it be ec2=0.

Why does MathCAD deliberately add an imaginary part to the real root? It seems more complicated than I can imagine.

Ivan_Pat_0-1766942257501.png

 

Werner_E
25-Diamond I
(To:Ivan_Pat)


I want to choose only the minimal real root, otherwise to assign, let it be ec2=0.

I understand that you want to use zero if all values are non-real.

Do you also want to use the minimum of all real values if it is positive? Or do you rather want to use 0 in this case?

 


Why does MathCAD deliberately add an imaginary part to the real root? It seems more complicated than I can imagine.

That's the way the "min" function works:

If the elements are complex, min returns the smallest real part of any value plus i times the smallest imaginary part of any value

See the help: Maxima and Minima of an Array

Ivan_Pat
12-Amethyst
(To:Werner_E)

@Werner_E 


@Werner_E wrote:

I want to choose only the minimal real root, otherwise to assign, let it be ec2=0.

I understand that you want to use zero if all values are non-real.

Do you also want to use the minimum of all real values if it is positive? 

 



I want to assign ec2 the minimum root value if the root  is a real number, otherwise ec2 will be zero.

Werner_E
25-Diamond I
(To:Ivan_Pat)

 


@Ivan_Pat wrote:

@Werner_E 


@Werner_E wrote:

I want to choose only the minimal real root, otherwise to assign, let it be ec2=0.

I understand that you want to use zero if all values are non-real.

Do you also want to use the minimum of all real values if it is positive? 

 



I want to assign ec2 the minimum root value if the root  is a real number, otherwise ec2 will be zero.



OK, so the minimum could be positive as well.

 

Here is a special "Min" function which should do the job.

First all non-reals are replaced by NaN's.

Then we try to delete these NaN's using "filterNaN". This functions fails if either no NaN was found or if all values are NaN's. In this case the vector remains unchanged.

Fortunately "min" returns a zero if the vectors contains only NaN's which is exactly what you want to see if all values are non-real.

Werner_E_2-1766951359300.png

 

Prime 10 sheet attached

 

Ivan_Pat
12-Amethyst
(To:Werner_E)

It seems exactly what I need, Werner!

Thank you very much for your patience.

I'll try it and share my feedback.

 

Announcements

Top Tags