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

## Solving system of non-linear equations

SOLVED  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.   Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions  Ruby IV
(in response to PierreTOMASINI)

## 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. 15 REPLIES 15  Opal
(in response to PierreTOMASINI)

## 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  Regular Member
(in response to terryhendicott)

## Re: Solving system of non-linear equations

Many thanks Terry for the quick reply.

Take care

Pierre  Ruby IV
(in response to PierreTOMASINI)

## 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.   Regular Member
(in response to Werner_E)

## 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  Regular Member
(in response to Werner_E)

## 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   Ruby IV
(in response to PierreTOMASINI)

## 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.  Regular Member
(in response to Werner_E)

## Re: Solving system of non-linear equations

Thank you. I will look into it.  Regular Member
(in response to Werner_E)

## 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. A looping attempt. Notice identical values in column 3 and 4.   Ruby IV
(in response to PierreTOMASINI)

## 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.  Ruby IV
(in response to Werner_E)

## 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 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.   Regular Member
(in response to Werner_E)

## 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  Regular Member
(in response to PierreTOMASINI)

## Re: Solving system of non-linear equations

Good news the project seems to be completed.

Thank you Werner  for your valuable inputs.

Pierre  Regular Member
(in response to PierreTOMASINI)

## Re: Solving system of non-linear equations   Regular Member
(in response to Werner_E)

## 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  Regular Member
(in response to PierreTOMASINI)

## 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