# How can a differential equation be solved, if its constants are in a system of equation relation?

1 view (last 30 days)
Jani on 24 Aug 2021
Commented: Star Strider on 24 Aug 2021
So the whole equations are here, but for the sake of simplicity I reduced many of the constants, so I can focus only on the relevant things.
So as far as I can see, chi_b and chi_e are two unkwons in a system of equation. In the equation chi_b(z) there is chi_e and in the equation chi_e there is the avarage of chi_b(z). I can solve this with this script (simplified version):
syms chi_b chi_e
K_be=7
delta_b=4
nu_b=33
eqn1=2*chi_b+3*chi_e+exp(K_be * delta_b / nu_b)==chi_b;
eqn2=3*chi_b+2*chi_e==chi_e;
sol=solve([eqn1,eqn2],[chi_b,chi_e]);
chi_b=sol.chi_b
chi_e=sol.chi_e
And I can solve differential equation with this script: Y(1)=chi_p, Y(2)=T_p
[t,Y]=ode23('diffeq_fv',[0 5],[0;1]);
plot(t,Y(:,1),'+',t,Y(:,2),'o')
function Fv=diffeq_fv(t,Y);
Fv(1,1)=3*Y(1);
Fv(2,1)=-4*Y(1)+3*Y(2);
But the d/dt chi_p diff.eq. inculdes chi_e, and when I write chi_e into the diff equations it doesn't work.
[t,Y]=ode23('diffeq_fv',[0 5],[0;1]);
plot(t,Y(:,1),'+',t,Y(:,2),'o')
function Fv=diffeq_fv(t,Y);
syms chi_b chi_e
K_be=7
delta_b=4
nu_b=33
eqn1=2*chi_b+3*chi_e+exp(K_be * delta_b / nu_b)==chi_b;
eqn2=3*chi_b+2*chi_e==chi_e;
sol=solve([eqn1,eqn2],[chi_b,chi_e]);
chi_b=sol.chi_b
chi_e=sol.chi_e
Fv(1,1)=3*Y(1)*chi_e;
Fv(2,1)=-4*Y(1)+3*Y(2);
and gives me this error message: "Inputs must be floats, namely single or double."
So my quesion is how can a diff equation which includes a system of equation be solved?

Star Strider on 24 Aug 2021
It is difficult to follow the posted code, so I am not certain what you are doing.
If you want to pass those variables to ‘diffeq_fv’ it will be necessary to pas them as extra parameters:
function Fv=diffeq_fv(t,Y,chi_b,chi_e);
K_be=7
delta_b=4
nu_b=33
eqn1=2*chi_b+3*chi_e+exp(K_be * delta_b / nu_b)==13;
eqn2=3*chi_b+2*chi_e==12;
sol=solve([eqn1,eqn2],[chi_b,chi_e]);
chi_b=sol.chi_b
chi_e=sol.chi_e
Fv(1,1)=3*Y(1)*chi_e;
Fv(2,1)=-4*Y(1)+3*Y(2);
end
See Passing Extra Parameters for details.
The ode23 call then becomes:
[t,Y]=ode23(@(t,Y) diffeq_fv(t,Y,chi_b,chi_e),[0 5],[0;1]);
.
Star Strider on 24 Aug 2021
It would seem that it would only be necessary to switch the constants in the differential equation:
chi_b = 0.292013077080326;
chi_e = -0.876039231240978;
[t,Y]=ode23(@(t,Y) diffeq_fv(t,Y,chi_b,chi_e),[0 5],[0;1]);
figure
plot(t,Y)
grid
function Fv=diffeq_fv(t,Y,chi_b,chi_e);
% K_be=7
% delta_b=4
% nu_b=33
% eqn1=2*chi_b+3*chi_e+exp(K_be * delta_b / nu_b)==13;
% eqn2=3*chi_b+2*chi_e==12;
% sol=solve([eqn1,eqn2],[chi_b,chi_e]);
% chi_b=sol.chi_b
% chi_e=sol.chi_e
Fv(1,1)=3*Y(1)*chi_b;
Fv(2,1)=-4*Y(1)+3*Y(2);
end
Experiment to get different results.
.