Get Help

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Solving system of non-linear equations

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-18-2020
08:48 PM

04-18-2020
08:48 PM

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.

Code (Mathcad file attached)

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-19-2020
07:03 AM

04-19-2020
07:03 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-18-2020
10:00 PM

04-18-2020
10:00 PM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-18-2020
11:12 PM

04-18-2020
11:12 PM

Re: Solving system of non-linear equations

Many thanks Terry for the quick reply.

Take care

Pierre

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-19-2020
07:03 AM

04-19-2020
07:03 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-19-2020
10:37 AM

04-19-2020
10:37 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-25-2020
06:22 PM

04-25-2020
06:22 PM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-25-2020
09:16 PM

04-25-2020
09:16 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-25-2020
10:34 PM

04-25-2020
10:34 PM

Re: Solving system of non-linear equations

Thank you. I will look into it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-29-2020
11:10 PM

04-29-2020
11:10 PM

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.

Mathcad 15

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-30-2020
06:10 AM

04-30-2020
06:10 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-30-2020
06:22 AM

04-30-2020
06:22 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-30-2020
10:55 PM

04-30-2020
10:55 PM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-30-2020
11:09 PM

04-30-2020
11:09 PM

Re: Solving system of non-linear equations

Good news the project seems to be completed.

Thank you Werner terryhendicott for your valuable inputs.

Pierre

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

04-30-2020
11:54 PM

04-30-2020
11:54 PM

Re: Solving system of non-linear equations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

06-18-2020
11:20 PM

06-18-2020
11:20 PM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

06-18-2020
11:22 PM

06-18-2020
11:22 PM

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