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

Solving system of non-linear equations

SOLVED
PierreTOMASINI
Regular Member

Solving system of non-linear equations

Hello All,

    I am struggling to find the proper code for solving a system of non linear equations, using Mathcad 15.

    The equation are given in the screenshot below. The problem is related to thermodynamics.

 

    I followed a template with Find, however it just don't get me anywhere.

    What needs to be done to get the results ? Can someone explain the issue (for the layman).

 

   Thanks for the support,

 

   keep safe,

 

System of equations

     Result sough PA (Pas in code) and PS (Ps in code).

     Once PA and PS are available; related parameters "aS", "aA" (aA and aS in code) and x calculations are straightforward.

PierreTOMASINI_0-1587254607502.png

 

Code (Mathcad file attached)

 

Untitled2.png

Untitled3.png

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Solving system of non-linear equations

Here is my attempt for a solution.

Basically the problem was wrong syntax for the solve block and that you wrote your function definitions as if they were equations.

But using your values and equations the solve block could not find a solution. Either use much lower guess values or change other values (as written in the file) or maybe have a second look at your functions to see if there is something wrong with them.

Werner_E_1-1587294110438.png

 

 

View solution in original post

15 REPLIES 15

Re: Solving system of non-linear equations

Hi,

File enclosed you will need to check the equations and values as it does not solve properly.

 

You only need two equations for two unknowns.  You need a "Given" statement to start the solve block.

 

Cheers

Terry

 

Re: Solving system of non-linear equations

Many thanks Terry for the quick reply.

Take care

Pierre

Re: Solving system of non-linear equations

Here is my attempt for a solution.

Basically the problem was wrong syntax for the solve block and that you wrote your function definitions as if they were equations.

But using your values and equations the solve block could not find a solution. Either use much lower guess values or change other values (as written in the file) or maybe have a second look at your functions to see if there is something wrong with them.

Werner_E_1-1587294110438.png

 

 

View solution in original post

Re: Solving system of non-linear equations

Thank you. That's really great. I was worried by the 0 values from the previous post.

Thank you.

Pierre

Re: Solving system of non-linear equations

Thanks again for the help.

 

This time, I am looking to nest the resolution into a loop as one of the aim of the exercise is to to plot one input value to an output (mole fraction in gas vs. mole fraction in solid).

 

How it's done exactly ? I can't see how find is used with programming code.

 

Pierre

 

Mathcad 15 programming

 

PierreTOMASINI_0-1587853331333.png

 

Re: Solving system of non-linear equations

You can't use a solve block in a program.

But you can turn the solve block into a function of the values you would like to change and use that function in your program.

Simply close the solve block with f(..,..,..) := Find (Pas,Psb) and use function f in your program.

 

Re: Solving system of non-linear equations

Thank you. I will look into it.

Re: Solving system of non-linear equations

I got a function that seemed working at first glance, but actually all the output values are the same (column 3 and 4), what's wrong. What's wrong  ? 

 

Thanks for the help,

 

Pierre

 

Two different inputs with same output.

PierreTOMASINI_2-1588216054549.png

A looping attempt. Notice identical values in column 3 and 4.

PierreTOMASINI_0-1588215749820.png

Mathcad 15

Re: Solving system of non-linear equations

The formal argument of your function f (PzSb) is never used in the calculation/solve block. So do you think it would influence the result?

 

If you define

 

x:=5

a:=2

b:=3+x

f(x):=a+b

 

you should not be surprised that f returns the same value (10) regardless of the actual argument passed because the calculation of b uses x=5 all the time.

 

Apart from setting up the problem in a different way you can solve this by making b a function of x:

 

[no need for defining x:=5]

a:=2

b(x):=3+x

f(x):=a+b(x)

 

A similar approach has to be taken in your sheet. So far it uses PzSB=0.4 for every call of f.

The solution is to turn every calculation which uses PzSb into a function of PzSb.

 

Re: Solving system of non-linear equations

I gave it a try but unfortunately the solve block will not find a solution for values of PzSb smaller than 0.12

Werner_E_0-1588242411259.png

 

You may wrap a second function around f which returns NaNs in case of the solve block failing. That way you could use the function in your program with the loop and see, for which values it fails.

Werner_E_1-1588242129676.png

 

 

Re: Solving system of non-linear equations

Thank you. I understand my oversight.

I made a considerable progress in my project thanks to you input.

And I see I am close to the end.

 

Pierre

Re: Solving system of non-linear equations

Good news the project seems to be completed.

Thank you Werner  terryhendicott for your valuable inputs.

 

Pierre

 

Re: Solving system of non-linear equations

 

PierreTOMASINI_0-1588305233463.png

 

Re: Solving system of non-linear equations

Hello, I made good progress in my project and I have a publication under evaluation. I would like to thank you for your help in the acknowledgement section. What name should I put on ? 

Pierre

Re: Solving system of non-linear equations

Also, I couldn't find a template citation to reference Mathcad in the paper. Do you have any suggestion by any chance ?

Thanks

 

Pierre

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."