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

Math equation solve issue

J_power
10-Marble

Math equation solve issue

i Mathcad experts,

I have some questions about Mathcad function. I don’t have any useful idea to solve my issues.

I have one equation, and I can draw the curve of this equation.

And then I try to solve the peak value of curve (fig.1) by using the method in EX2.

Jason_power_2-1718286163860.png

Below are my questions.

1.Any method I can solve this equation to get the fn_Y2, please see EX1?

2.How do I use solve function to get the fn_Y2, if I have different inputs Q2 at the same time (please see EX3).  I can do this when I only have one input, please see EX2.

3.If the issue 2 can be solved, and then I would try to input the fn_Y2 to get the peak value . Also I would like to draw the relationship of Q and peak value, please see the fig.2 (this fig is from TI’s datasheet), could you please give me some suggestions.

Untitled.png

ACCEPTED SOLUTION

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

Prime is not able to solve your equation symbolically.

 

But as you had shown yourself it can provide solution(s) if you provide numeric values for the other two variables

Werner_E_0-1718289381025.png

You may also use the "assume" modifier to limit the solution to the only positive, real one

Werner_E_1-1718289438415.png

 

But you are just looking for numeric results (depending on Q and L(ambda), so I would suggest that you use Mathcads numeric methods. Either a solve block with "find" or one of the two ways to use the "root" function.

Here is the latter, assuming the solution is within the range from 10^-10 to 10:

Werner_E_2-1718291661678.png

You can turn this calculation into a function of lambda and Q

Werner_E_3-1718291717960.png

So it can be used to get the result for any of these values

Werner_E_4-1718291767640.png

From here its not difficult to plot either the My function for various Q-values and their peaks

Werner_E_5-1718291850936.png

or the plot you seem to be looking for

Werner_E_6-1718291918994.png

Mathcad 15 sheet attached

 

 

 

 

 

View solution in original post

22 REPLIES 22
Cornel
19-Tanzanite
(To:J_power)

I am not sure why do you want to differentiate with respect to fn_Y2, and not fn_Y.

Its too complicated to solve for fn_Y...also having these 2 as parameters

Cornel_1-1718287407017.png

Cornel_2-1718287414887.png

 

Cornel_0-1718287373921.png

 

But you can do something like this:

Cornel_3-1718287459021.png


as you already did in fact here:

Cornel_0-1718288299767.png

 

Its based on a manual way to do this what you want as you did...

Cornel_2-1718289947122.png

 

Cornel_1-1718289938776.png

Here...someone will need to find a way on how to choose maximum value as we can see for example at Q4 index is 3 and at Q6 index is 5, so index is changing:

Cornel_3-1718290257767.png

 

Cornel_4-1718290296490.png


And then how to iterate Q parameter from 0.1, 0.2,...1, then for each Q value to find the maximum, and then to plot, these in a more automatical way...Maybe one could find how to do it...

Werner_E
25-Diamond I
(To:Cornel)


@Cornel wrote:

I am not sure why do you want to differentiate with respect to fn_Y2, and not fn_Y.


Above that expression he already had defined a value for f.n_Y and so Mathcads symbolics would refuse to solve for this variable. So he had chosen a different name to be used for the variable Mathcad should solve for.

Werner_E
25-Diamond I
(To:J_power)

Prime is not able to solve your equation symbolically.

 

But as you had shown yourself it can provide solution(s) if you provide numeric values for the other two variables

Werner_E_0-1718289381025.png

You may also use the "assume" modifier to limit the solution to the only positive, real one

Werner_E_1-1718289438415.png

 

But you are just looking for numeric results (depending on Q and L(ambda), so I would suggest that you use Mathcads numeric methods. Either a solve block with "find" or one of the two ways to use the "root" function.

Here is the latter, assuming the solution is within the range from 10^-10 to 10:

Werner_E_2-1718291661678.png

You can turn this calculation into a function of lambda and Q

Werner_E_3-1718291717960.png

So it can be used to get the result for any of these values

Werner_E_4-1718291767640.png

From here its not difficult to plot either the My function for various Q-values and their peaks

Werner_E_5-1718291850936.png

or the plot you seem to be looking for

Werner_E_6-1718291918994.png

Mathcad 15 sheet attached

 

 

 

 

 

Cornel
19-Tanzanite
(To:Werner_E)

I converted your Mathcad 15 file to Prime 10 and...I see this. How to solve?

Cornel_0-1718292673603.png

 

Werner_E
25-Diamond I
(To:Cornel)

Yes, Prime is not capable to plot family of curves like Mathcad was able to do.

You would have to do it completely different, create vectors(/matrices and use Primes waterfall plot to get a similar picture.

Fortunately @J_power  is using real Mathcad and not Prime 😉

Cornel
19-Tanzanite
(To:Werner_E)

Hm, if you know how to do this it will be nice. I am interested too on this exercise how can be done using Prime as I am using Prime

Werner_E
25-Diamond I
(To:Cornel)

Look at this thread and the sheet posted there

Solved: Plotting Multivariable Multifunction Summation Fun... - PTC Community

Maybe this can be of help, too

Solved: Add/Remove More plot lines automatically from a ve... - PTC Community

 

If you want to create a specific waterfall plot of a family of curves in Prime and still experience troubles, I would suggest opening a new thread for it.

Cornel
19-Tanzanite
(To:Werner_E)

Apart of this with waterfall plot of a family of curves in Prime, I made above a path suggestion on how this exercise can be solved. There I made a manual approach. Do you think that this approach can be automated somehow?

 

The 2 things needs there:

1. How to choose the maximum value of fn_Y as we can see for example at Q4 index is 3 and at Q6 index is 5, so index is changing of the maximum value.
2. How to iterate Q parameter from 0.1, 0.2,...1, then for each Q value to find the maximum as was made at above point 1, and then to plot My vs Q, these in a more automatical way. 

Or in fact what I suggested here is what is done these 2 above posted threads?

Werner_E
25-Diamond I
(To:Cornel)

@Cornel 

I consider the problem solved by using the numeric root function as shown in my first reply. No need to fumble around with the symbolic solve, I guess. But lets @J_power  decide if he needs more help or if he really needs to use the symbolics - after all its his question and his thread!

 

The links to the two threads I provided in my answer to your question cover the problem you experience with the plot in the converted sheet and have otherwise nothing to do with this thread here! If you really want to duplicate the failing plot in Prime you can study and use the methods demonstrated in those threads. This thread here covers the initial question and deals with Mathcad, not Prime!

Cornel
19-Tanzanite
(To:Werner_E)

Ok, I made this with waterfall plot also in Prime 10 following that first thread you had posted.

Cornel_2-1718351227643.png

 

But I see a thing here: if I try to plot fn_Y from 0 the error with division by 0 arise. I am wondering how you managed to plot from 0 in Mathcad 15?

Prime 10:

Cornel_3-1718351304273.png

Your plot in Mathcad 15:

Cornel_7-1718351527631.png

 

Your f vector in Mathcad 15:

Cornel_4-1718351359381.png


My f vector in Prime:

Cornel_5-1718351374655.png


And we are both using the same :

Cornel_6-1718351407288.png

 

 

Werner_E
25-Diamond I
(To:Cornel)

A 2D plot will happily ignore failing function values and still plot the rest. The creation of a vector/matrix fails if just one of the calculation fails. So simply use

Werner_E_0-1718363413591.png

when you create the matrix, the plot will ignore the NaN's and work OK.

I this specific case you may also replace the NaN by a zero, because that's the correct limit

Werner_E_0-1718364215059.png

That said you may also use

Werner_E_1-1718364340060.png

 

 

 

Thanks for your response.

May I know why you use Vector in M function and F function?

 

Werner_E
25-Diamond I
(To:J_power)


@J_power wrote:

Thanks for your response.

May I know why you use Vector in M function and F function?

 


You are talking about the vectorization used when showing the five peak positions?

Werner_E_0-1718554146718.png

f.nY and M.Y are functions written to receive single scalar arguments. When you want to feed into those function a vector like Q.3 instead and expect that every single element of this vector should be used as function argument and all results the n collected in a vector, then this is exactly what vectorization is made for. Sometimes (depends how your function is defined) its not necessary to apply explicit vectorization because Mathcad would apply (implicit) vectorization automatically. But i won't rely on it and suggest to always use explicit vectorization in such cases.

Here two simply examples. Both function simply square the argument given. They do the very same when used with a simple scalar argument but return different results when called with a vector as argument.

Reason is that f uses multiplication and this is an operation defined for vectors, too (scalar product). Function g uses squaring and this is an operation NOT defined for vectors and instead of throwing an error Mathcad applies implicit vectorization. So using explicit vectorization is a good idea without having to think if its really necessary or if Mathcad would do it on its own.

Werner_E_1-1718554885928.png

 

BTW, the vectorization of M.Y in the plot was senseless and i shouldn't have used it because here I use your range (! not a vector) Q.2 to plot all five curves in one go (something not working in Prime anymore as Cornel also noticed). Vectorization has no effect if no vectors are involved (but it doesn't do any harm either).

 

 

it is more clear to me, thanks.

Werner_E
25-Diamond I
(To:J_power)

I played around and added a 3D plot with the L (lambda), Q an max My values, showing the curve corresponding to L=6.3 in red

Werner_E_0-1718301154560.png

 

I also added a way to use the symbolics to get the necessary fnY-values, but I won't suggest using it:

Werner_E_1-1718301227251.png

 

 

What's the function of this equation?

J_power_0-1718529379364.png

 

 

Werner_E
25-Diamond I
(To:J_power)


@J_power wrote:

What's the function of this equation?

J_power_0-1718529379364.png

 

 


This expression does the very same (or something similar) as the function f.positive in my last reply (posting a worksheet with Lucs approach).

F is the result of calling the function "temp" which uses the symbolics to return a vector with six elements.

In case of your example just one of these six values is real and positive and this is the one to pick. I won't bet that its always the first or always the second one (even this may be the case here).

Furthermore sometimes because of round-off errors even the real solutions are returned with a very tiny imaginary part.

 

1)  |Im(F)|<^10^.10 returns a 6-element vector with a 1 where F is a real value (Imaginary part 0 or very small) and a zero if F is non.real.

 

2) F is multiplied b the vector created in the first step, so all non-real values are set to zero

 

3) this new vector is sorted using the "sort" function. That way the largest (positive ?) value comes last in the vector returned

 

4) "reverse" changes the order of the vector elements so that that positive value is the first element

 

5) This first element is now chosen using the matrix index ORIGIN

 

And, no, this sure is not the most elegant or intuitive way to achieve this task 😉

 

After all I think its best to avoid the symbolics altogether and just use Mathcads numeric facilities.

LucMeekes
23-Emerald III
(To:J_power)

The question is to find the peak values in:

LucMeekes_1-1718309499282.png

an example of which is:

LucMeekes_2-1718309518852.png

That means solving:

LucMeekes_3-1718309646691.png

Which gives a huge result. You can just select the one result, that is real and positive:

LucMeekes_0-1718309453682.png

And use it to calculate the peak value with:

LucMeekes_4-1718309742298.png

Which you can plot over values of lambda and Q:

LucMeekes_5-1718309795639.png

And of course you can pick the Peak value for any set of lambda and Q values:

LucMeekes_6-1718309956760.png

Success!
Luc

Hi,

Thanks for your response.

May I know how to use positive in the equation.

I try to do the same thing as you, but Mathcad can't be shown.

 

 

 

LucMeekes
23-Emerald III
(To:J_power)

Sure. I see from Werner's results that Mathcad 15 provides the positive as second element of the result array. So, define 

positive := ORIGIN+1

and use that to index the f() function.

 

Success!

Luc

Werner_E
25-Diamond I
(To:LucMeekes)


@LucMeekes wrote:

Sure. I see from Werner's results that Mathcad 15 provides the positive as second element of the result array. So, define 

positive := ORIGIN+1

and use that to index the f() function.

 

Success!

Luc


Seems to apply only to the symbolic solution using numeric values as in my sheet.

When using the pure symbolic approach, the solution yielding positive values is the first one as in your MC11.

Werner_E_0-1718541416920.png

BTW, it seems not to be necessary here, but to be on the safe side we could use a small utility function to be sure to get the positive value:

Werner_E_1-1718541993973.png

 

Lucs method using the symbolic "solve" with all the variables undefined only works because Mathcad is capable enough to find all solution for f and so we can later pick the one we are interested in. Depending on the equation provided is easily possible that the symbolic solve would fail (more likely in MC15 than in MC11).

 

Mathcad 15 sheet attached

 

Got it, thanks,

 

Announcements

Top Tags