how to solve 2 equations with 3 unknown by iteration

7 views (last 30 days)
Hello again,
This week I asked a question and took no answer. But the question looked too particular to me. Generally my problem is not physics or thermodynamics. It is about 2 equations and 3 unknowns. I have 2 equations seem like that :
A = .... + B^2 - ...;
C = .... - B - ....;
As you see B unknown is common for both equations. Well, there is one more thing about equations, B depends to A and B properties and taken from REFPROP. So, I am trying to solve those equations with a 'for' loop iteration.
I guess 'B' as initial value. I calculate A and C with guessed B. Then I take a new 'B' with "refpropm" function according to A and C. After that, I check guessed 'B' and new 'B'. If it converges to tolerance that I set(difference, for example 1e-7),new 'B' setted as 'B' and main loop continues to next control volume. If it doesnt converge, again new 'B' setted as 'B' but it goes for next step of iteration and A and C calculated again. , until convergence.
It looks simple. Iteration Works for many control volumes. But, at a point iteration loop doesnt work and there is no convergence, it goes even to infinity. I couldnt realise the problem.
Main question is that : how can I solve those equations? Is my approach mistaken? Please help me. It took too much time.
  2 Comments
Michael Haderlein
Michael Haderlein on 13 Aug 2014
There is no unique solution for a system of two equations with three unknowns. You need as many equations as unknowns. Do you have one more equation? To me it sounds like there is, but I'm not sure if I understand you correctly.
Usually you can solve such systems of equations with the fsolve function.
Roger Stafford
Roger Stafford on 13 Aug 2014
It is misleading for you to state that you have three unknowns and only two equations. The requirement that B be equal to the output of 'refpropm' with A and C as inputs is the equivalent of a third equation. Therefore, in effect, you have three unknowns and three equations, not two.
As you have determined by your experiments, the procedure you are using is too simple-minded to ensure that you will ever converge to a solution. Sometimes it may work but other times it will not. You have no reason to suppose one way or the other. It needs to be much smarter to have a reasonable chance of success. If the algorithm finds that it seems to be going away from a solution instead of toward it, it needs to make a change in direction in some intelligent way. As Michael has pointed out, that is precisely what matlab's 'fsolve' function in the Optimization Toolbox can do.

Sign in to comment.

Answers (0)

Categories

Find more on Thermal Analysis in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!