Solving one equation for the value of two variables

6 views (last 30 days)
I wrote some code to find the composition of two initial reactants and used an array of values to find where they both equal the ratio of final weight fractions. I'm trying now to make the code more robust and want the code to find the two values without the arrays.
Code: I'm trying to find cA and cB where the formula value AB will equate to the ratio dAdB.
%========================================
%Variables
%========================================
cA = 0:0.0001:1;
cB = 1:-0.0001:0;
rA = 0.92;
rB = 1.22;
dAdB = (0.79/0.21);
%========================================
%========================================
%Formula
%========================================
AB = (cA./cB).*(((rA.*cA)+cB)./(cA+(rB.*cB)));
%========================================

Answers (2)

John D'Errico
John D'Errico on 18 Oct 2017
Hint: You could use a contour plot, in the variables cA and cB. You want only ONE contour level, at 0.79/0.21.
Think about what a contour plot shows you.
But if you want a solution...
rA = 0.92;
rB = 1.22;
syms cA cB
cA = solve((cA./cB).*(((rA.*cA)+cB)./(cA+(rB.*cB))) == 0.79/0.21,cA)
Warning: Solutions are valid under the following conditions: cB ~= 0;
cB ~= 0. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
> In solve>warnIfParams (line 508)
In solve (line 357)
cA =
(725*cB)/483 - (6757654^(1/2)*cB)/966
(725*cB)/483 + (6757654^(1/2)*cB)/966
So the "solution" is a pair of straight lines that pass through the origin.

Torsten
Torsten on 19 Oct 2017
syms cA cB AB rA rB
eqns = [cA/cB*(rA*cA+cB) == AB*(cA+rB*cB) , cA+cB == 1];
vars = [cA cB];
[solcA, solcB] = solve(eqns, vars)
Best wishes
Torsten.

Categories

Find more on Mathematics 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!