Substitute implicit dependent expressions into another one

Hi Everyone!
This is my first question, so sorry for mistakes!
I would like to know that is there an opportunity to substitute implicit expressions which depend on eachother into another equation?
I have these equations:
Xm1=Km*(1-dm/pm)-Xm12;
Xm12=(am1*Xm1/am21)*(Xt/(Xt+Ktstar));
Xm2=0;
Xt=Kt*(1-(dt1*Xm1-dt2*Xm12))/(pt*(1+rm12*Xm12));
and I would like to substitute into
pt*Xt*(1-Xt/Kt)*(1+rm2*Xm2+rm12*Xm12)-dt1*Xt*Xm1-dt2*Xt*Xm12
I have values for the parameters: pt Kt Ktstar rm12 dt1 dt2 pm1 pm12 Km am1 am21 dm1 dm12 am12 dm pm
Can someone please help me?

2 Comments

Could you tell what’s your desired result?
Actually, I would like to check a result I get calculated by hand.
Xm1,Xm12,Xm2,Xt are my steady state values for a complex eq system and by hand I got the implicit results above.
I would like to substitute them back into the equations in my system and see that for different values I really get zeros for these equation.
Thank you for the quick response!

Sign in to comment.

 Accepted Answer

I would start with this:
syms pt Kt Ktstar rm12 dt1 dt2 pm1 pm12 Km am1 am21 dm1 dm12 am12 dm pm Xm12 Xt
Xm1=Km*(1-dm/pm)-Xm12;
Xm12=(am1*Xm1/am21)*(Xt/(Xt+Ktstar));
% Xm2=0;
Xt=Kt*(1-(dt1*Xm1-dt2*Xm12))/(pt*(1+rm12*Xm12));
Xt = simplify(Xt, 'Steps',250)
producing:
Xt = (Kt*dt2)/(pt*rm12) - (Kt*(dt1*(Xm12 + Km*(dm/pm - 1)) + 1) - (Kt*dt2)/rm12)/(pt*((Xt*am1*rm12*(Xm12 + Km*(dm/pm - 1)))/(am21*(Ktstar + Xt)) - 1))
and then use the subs function to replace the parameters with their values.
.

4 Comments

Thank you for your answer!
I tried that you wrote but probably I misunderstood it.
In the end I suppose to get a number for this expression:
pt*Xt*(1-Xt/Kt)*(1+rm2*Xm2+rm12*Xm12)-dt1*Xt*Xm1-dt2*Xt*Xm12
but whatever I try, my Xm1,Xm12,Xt always remain a variable instead. :(
My pleasure!
It is straightforward to keep ‘Xm1’, ‘Xm12’, and ‘Xt’ as variables. Simply do not substitute them, and to make this easier, specify them as the argument list to your function.
The revised code:
syms pt Kt Ktstar rm12 dt1 dt2 pm1 pm12 Km am1 am21 dm1 dm12 am12 dm pm Xm12 Xt Xm1
% Xm1=Km*(1-dm/pm)-Xm12;
% Xm12=(am1*Xm1/am21)*(Xt/(Xt+Ktstar));
% Xm2=0;
Eqn = subs(Kt*(1-(dt1*Xm1-dt2*Xm12))/(pt*(1+rm12*Xm12)) - Xt, {Xm1,Xm12},{Km*(1-dm/pm)-Xm12, (am1*Xm1/am21)*(Xt/(Xt+Ktstar))});
fcn(Xm1, Xm12, Xt) = simplify(Eqn, 'Steps',500)
The original function is:
fcn(Xm1, Xm12, Xt) =
(Kt*(dt1*(Xm12 + Km*(dm/pm - 1)) + (Xm1*Xt*am1*dt2)/(am21*(Ktstar + Xt)) + 1))/(pt*((Xm1*Xt*am1*rm12)/(am21*(Ktstar + Xt)) + 1)) - Xt
The subs call would go like this:
fcn(Xm1, Xm12, Xt) = subs(fcn, {pt Kt Ktstar rm12 dt1 dt2 pm1 pm12 Km am1 am21 dm1 dm12 am12 dm pm},{1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16})
producing (with these scalars):
fcn(Xm1, Xm12, Xt) =
(2*(5*Xm12 + (60*Xm1*Xt)/(11*(Xt + 3)) - 29/16))/((40*Xm1*Xt)/(11*(Xt + 3)) + 1) - Xt
Use the appropriate parameter values. (I used this string of numbers simply to test the code.)
.
Thank you very much for your help! I could solve now that I wanted :D

Sign in to comment.

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Asked:

Lyz
on 7 Jun 2020

Commented:

on 7 Jun 2020

Community Treasure Hunt

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

Start Hunting!