Solving a nonlinear system differential equation using symbols

7 views (last 30 days)
Hello,
I'm trying to solve a systems of non linear equations at equillbrium.
First I solved each equation individually and then made a system of equations to solve. I realized that I was getting 3 instead of 5 solutions
used the return conditions function and got the following using this code
syms a b c d e k_off_1p Pd1_0 k_on_1p Ab_initial_conc k_on_2p k_off_1p k_off_1c Cd137_0 k_on_1c k_on_2c k_off_1c
Eqns = [0 == -k_on_1p.*Ab_initial_conc*a + k_off_1p.*c - k_on_2p.*a*d + k_off_1p.*e;
0 == -k_on_1c.*Ab_initial_conc*b+k_off_1c.*d-k_on_2c.*b*c+k_off_1c.*e;
0 == k_on_1p.*Ab_initial_conc*a-k_off_1p.*c-k_on_2c.*b*c+k_off_1c.*e;
0 == k_on_1c.*Ab_initial_conc*b-k_off_1c.*d-k_on_2p.*a*d+k_off_1p.*e;
0 == k_on_2c.*b*c+k_on_2p.*a*d-(k_off_1c+k_off_1p)*e;
];
[sola,solb,solc,sold,sole] = solve(Eqns, [a,b,c,d,e],'ReturnConditions',true)
I got the error "Inconsistent output with 3 variables for input argument with 5 variables"
Trying to solve by hand, I also got three variables as an out put. using 2 other equations , I could redefine the 3rd and 4th eqns. My intention is to have matlab use the 3rd and 4th equation to substitute the values of c and d into the remaining eqns.
syms a b c d e k_off_1p Pd1_0 k_on_1p Ab_initial_conc k_on_2p k_off_1p k_off_1c Cd137_0 k_on_1c k_on_2c k_off_1c
Eqns = [0 == -k_on_1p.*Ab_initial_conc*a + k_off_1p.*c - k_on_2p.*a*d + k_off_1p.*e;
0 == -k_on_1c.*Ab_initial_conc*b+k_off_1c.*d-k_on_2c.*b*c+k_off_1c.*e;
c==Pd1_0 - a -e;
d==Cd137_0 - b -e;
0 == k_on_2c.*b*c+k_on_2p.*a*d-(k_off_1c+k_off_1p)*e;
];
[sola,solb,solc,sold,sole] = solve(Eqns, [a,b,c,d,e],'ReturnConditions',true)
I recieved the following error
Error using sym/cat>checkDimensions (line 68)
CAT arguments dimensions not consistent.
Error in sym/cat>catMany (line 33)
[resz, ranges] = checkDimensions(sz,dim);
Error in sym/cat (line 25)
ySym = catMany(dim, args);
Error in sym/vertcat (line 19)
ySym = cat(1,args{:});
Error in tewst (line 65)
Eqns = [0 == -k_on_1p.*Ab_initial_conc*a + k_off_1p.*c - k_on_2p.*a*d + k_off_1p.*e;
I am unsure how to proceed from here, because the dimensions are consistent in my mind, and I'm unsure how to introduce the 2 new equations from another perspective.
Thanks

Answers (2)

Paul
Paul on 31 Mar 2022
When using ReturnConditions, the outputs need to include Parameters and Conditions, or use only a single output
syms a b c d e k_off_1p Pd1_0 k_on_1p Ab_initial_conc k_on_2p k_off_1p k_off_1c Cd137_0 k_on_1c k_on_2c k_off_1c
Eqns = [0 == -k_on_1p.*Ab_initial_conc*a + k_off_1p.*c - k_on_2p.*a*d + k_off_1p.*e;
0 == -k_on_1c.*Ab_initial_conc*b+k_off_1c.*d-k_on_2c.*b*c+k_off_1c.*e;
0 == k_on_1p.*Ab_initial_conc*a-k_off_1p.*c-k_on_2c.*b*c+k_off_1c.*e;
0 == k_on_1c.*Ab_initial_conc*b-k_off_1c.*d-k_on_2p.*a*d+k_off_1p.*e;
0 == k_on_2c.*b*c+k_on_2p.*a*d-(k_off_1c+k_off_1p)*e;
];
[sola,solb,solc,sold,sole,parameters,conditions] = solve(Eqns, [a,b,c,d,e],'ReturnConditions',true)
Warning: Unable to find explicit solution. For options, see help.
sola = Empty sym: 0-by-1 solb = Empty sym: 0-by-1 solc = Empty sym: 0-by-1 sold = Empty sym: 0-by-1 sole = Empty sym: 0-by-1 parameters = Empty sym: 1-by-0 conditions = Empty sym: 0-by-1
% or
sol = solve(Eqns, [a,b,c,d,e],'ReturnConditions',true)
Warning: Unable to find explicit solution. For options, see help.
sol = struct with fields:
a: [0×1 sym] b: [0×1 sym] c: [0×1 sym] d: [0×1 sym] e: [0×1 sym] parameters: [1×0 sym] conditions: [0×1 sym]
solve() can't find the explicit soution, but that's a different problem.
  6 Comments
Walter Roberson
Walter Roberson on 1 Apr 2022
syms a b c d e k_off_1p Pd1_0 k_on_1p Ab_initial_conc k_on_2p k_off_1p k_off_1c Cd137_0 k_on_1c k_on_2c k_off_1c
Eqns = [0 == -k_on_1p.*Ab_initial_conc*a + k_off_1p.*c - k_on_2p.*a*d + k_off_1p.*e;
0 == -k_on_1c.*Ab_initial_conc*b+k_off_1c.*d-k_on_2c.*b*c+k_off_1c.*e;
0 == k_on_1p.*Ab_initial_conc*a-k_off_1p.*c-k_on_2c.*b*c+k_off_1c.*e;
0 == k_on_1c.*Ab_initial_conc*b-k_off_1c.*d-k_on_2p.*a*d+k_off_1p.*e;
0 == k_on_2c.*b*c+k_on_2p.*a*d-(k_off_1c+k_off_1p)*e;
];
sol = solve(Eqns, [a,b,c,d,e],'ReturnConditions',true,'IgnoreAnalyticConstraints',true)
sol = struct with fields:
a: [2×1 sym] b: [2×1 sym] c: [2×1 sym] d: [2×1 sym] e: [2×1 sym] parameters: [z z1] conditions: [2×1 sym]
sol.conditions
ans = 
Notice the conditions are symtrue . So the solutions apply for any real or complex-valued z and z1
Paul
Paul on 1 Apr 2022
Yse, z and z1 are free parameters such that d = z and e = z1, and then a,b, and c each have two solutions for given those same parameters.

Sign in to comment.


Torsten
Torsten on 2 Apr 2022
Edited: Torsten on 2 Apr 2022
Here is the sequence of commands to obtain the solution in Octave.
One can use the "solve" directly for all variables, but I deduced appropriate solution steps from the equations.
syms A B C D E f g h k l m n
% Rename Variables
% A = a
% B = b
% C = c
% D = d
% E = e
% f = k_on_1p
% g = Ab_initial_conc
% h = k_off_1p
% k = k_on_2p
% l = k_on_1c
% m = k_off_1c
% n = k_on_2c
%Eqns = [0 == -f*g*A + h*C + h*E - k*A*D;
% 0 == -l*g*B +m*D + m*E - n*B*C;
% 0 == f*g*A - h*C + m*E - n*B*C;
% 0 == l*g*B -m*D + h*E - k*A*D;
% 0 == -(m+h)*E + k*A*D + n*B*C;
% ];
Eqns = [0 == -f*g*A + h*C + h*E - k*A*D;...
0 == -l*g*B + m*D + m*E - n*B*C;...
0 == f*g*A - h*C + m*E - n*B*C;...
0 == l*g*B - m*D + h*E - k*A*D;...
0 == -(m+h)*E + k*A*D + n*B*C;...
];
%[solA solB solC solD solE] = solve(Eqns,[A B C D E])
Bsol = solve(Eqns(4),B)
Csol = solve(Eqns(1),C)
eqnA = subs(Eqns(3),[B,C],[Bsol,Csol])
Asol = solve(eqnA,A)
Bsol = subs(Bsol,A,Asol)
Csol = subs(Csol,A,Asol)
Check11 = simplify(subs(Eqns(1),[A,C],[Asol(1),Csol(1)]))
Check12 = simplify(subs(Eqns(1),[A,C],[Asol(2),Csol(2)]))
Check21 = simplify(subs(Eqns(2),[B,C],[Bsol(1),Csol(1)]))
Check22 = simplify(subs(Eqns(2),[B,C],[Bsol(2),Csol(2)]))
Check31 = simplify(subs(Eqns(3),[A,B,C],[Asol(1),Bsol(1),Csol(1)]))
Check32 = simplify(subs(Eqns(3),[A,B,C],[Asol(2),Bsol(2),Csol(2)]))
Check41 = simplify(subs(Eqns(4),[A,B],[Asol(1),Bsol(1)]))
Check42 = simplify(subs(Eqns(4),[A,B],[Asol(2),Bsol(2)]))
Check51 = simplify(subs(Eqns(5),[A,B,C],[Asol(1),Bsol(1),Csol(1)]))
Check52 = simplify(subs(Eqns(5),[A,B,C],[Asol(2),Bsol(2),Csol(2)]))

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!