Matlab:在条件不工作的情况下求解
Matlab: dsolve with conditions not working
我正在尝试求解由变量 eqn1 和 eqn2 给出的微分方程组。
lambda1 = 3;
lambda2 = 2;
gamma1 = 1;
gamma2 = 1;
delta1 = 1;
delta2 = 1;
syms n1(t) n2(t)
eqn1 = diff(n1) == (lambda1 - gamma1)*n1 - delta1*(n1 + n2)*n1;
eqn2 = diff(n2) == (lambda2 - gamma2)*n2 - delta1*(n1 + n2)*n2;
c1 = n1(0) == 10;
c2 = n2(0) == 10;
[a, b] = dsolve(eqn1, eqn2, c1, c2)
如果我不指定条件 c1 和 c2 以及 运行 只是:
[a, b] = dsolve(eqn1, eqn2)
然后一切正常,我得到:
a =
(6*exp(2*t)*n1(0))/(3*exp(2*t)*n1(0) + 4*exp((3*t)/2)*n2(0) + 6)
b =
(6*exp(t/2)*exp(t)*n2(0))/(3*exp(2*t)*n1(0) + 4*exp((3*t)/2)*n2(0) + 6)
但是当我尝试指定 n1(0) 和 n2(0) 时,如您在源代码中所见,我收到以下警告:
a =
Warning: The result cannot be displayed due a previously interrupted computation or out of memory. Run 'reset(symengine)' and rerun the commands to regenerate the result.
> In sym.disp at 36
In sym.display at 37
In competingForResources at 15
b =
[]
而且我无法绘制结果。我在那里错过了什么?如何以正确的方式指定条件,以便获得可绘制的结果?
您可以使用 subs
直接替换结果中的值
[a, b] = dsolve(eqn1, eqn2);
a=subs(a,'n1(0)',10);
a=subs(a,'n2(0)',10)
a =
(60*exp(2*t))/(30*exp(2*t) + 40*exp((3*t)/2) + 6)
同b
我正在尝试求解由变量 eqn1 和 eqn2 给出的微分方程组。
lambda1 = 3;
lambda2 = 2;
gamma1 = 1;
gamma2 = 1;
delta1 = 1;
delta2 = 1;
syms n1(t) n2(t)
eqn1 = diff(n1) == (lambda1 - gamma1)*n1 - delta1*(n1 + n2)*n1;
eqn2 = diff(n2) == (lambda2 - gamma2)*n2 - delta1*(n1 + n2)*n2;
c1 = n1(0) == 10;
c2 = n2(0) == 10;
[a, b] = dsolve(eqn1, eqn2, c1, c2)
如果我不指定条件 c1 和 c2 以及 运行 只是:
[a, b] = dsolve(eqn1, eqn2)
然后一切正常,我得到:
a =
(6*exp(2*t)*n1(0))/(3*exp(2*t)*n1(0) + 4*exp((3*t)/2)*n2(0) + 6)
b =
(6*exp(t/2)*exp(t)*n2(0))/(3*exp(2*t)*n1(0) + 4*exp((3*t)/2)*n2(0) + 6)
但是当我尝试指定 n1(0) 和 n2(0) 时,如您在源代码中所见,我收到以下警告:
a =
Warning: The result cannot be displayed due a previously interrupted computation or out of memory. Run 'reset(symengine)' and rerun the commands to regenerate the result.
> In sym.disp at 36
In sym.display at 37
In competingForResources at 15
b =
[]
而且我无法绘制结果。我在那里错过了什么?如何以正确的方式指定条件,以便获得可绘制的结果?
您可以使用 subs
[a, b] = dsolve(eqn1, eqn2);
a=subs(a,'n1(0)',10);
a=subs(a,'n2(0)',10)
a =
(60*exp(2*t))/(30*exp(2*t) + 40*exp((3*t)/2) + 6)
同b