# How to express a variable (function) in terms of specific variables?

18 views (last 30 days)
Andrian Mirza on 26 Nov 2021
Answered: Paul on 26 Nov 2021
I wish to return r1 as a function of all the symbolic variables under syms besides the [C_S, C_CS, C_BS]. But I am not exactly sure of how I should proceed.
The code below returns 4 zero solutions, which is technically correct. But the thing is that r1 is not 0, it is a function, and thus I need a function in all the symbolic variables with known IVPs.
syms C_S C_CS C_BS C_C C_P C_B r1 r2 r3 k_A k_A1 k_S k_S1 k_D k_D1
Ct = C_S + C_CS + C_BS
func1 = k_A*C_C*C_S - k_A1*C_CS
func2 = k_S*C_CS - k_S1*C_BS*C_P
func3 = k_D*C_BS - k_D1*C_B*C_S
Eq1 = [func1 == r1, func2 == 0, func3 == 0, Ct]
KA = k_A/k_A1
KS = k_S/k_S1
KD = k_A/k_D1
[x, y, z, w] = solve(Eq1, [r1 C_S C_CS C_BS])
##### 2 CommentsShowHide 1 older comment
Andrian Mirza on 26 Nov 2021
Edited: Andrian Mirza on 26 Nov 2021
So, in the picture below it is solved by hand, I solved for r1, the overbar stays for S in the index in the above code. So we have three rate expressions, from which r2 and r3 are equal to 0. And the goal is to express r1 as a function of all but [C_CS, C_S C_BS]. I hope that this is a clear response from my side. Paul on 26 Nov 2021
syms C_S C_CS C_BS C_C C_P C_B r1 r2 r3 k_A k_A1 k_S k_S1 k_D k_D1
Ct = C_S + C_CS + C_BS
Ct = r1 = k_A*C_C*C_S - k_A1*C_CS;
r2 = k_S*C_CS - k_S1*C_BS*C_P;
r3 = k_D*C_BS - k_D1*C_B*C_S;
sol = solve([r2==0,r3==0],[C_CS C_S],'ReturnConditions',true)
sol = struct with fields:
C_CS: (C_BS*C_P*k_S1)/k_S C_S: (C_BS*k_D)/(C_B*k_D1) parameters: [1×0 sym] conditions: C_B ~= 0 & k_D1 ~= 0 & k_S ~= 0
r1 = subs(r1,[C_CS C_S],[sol.C_CS sol.C_S])
r1 = [num,den]=numden(r1)
num = den = r1 = num/den
r1 = 