solution to differential equations system looks strange. What is wrong with my code?
3 次查看(过去 30 天)
显示 更早的评论
I am writing a code to solve the differential equations. I have written the following code but my solution looks wierd. First, I get long digits numbers, which I do not get if I solve the system by hand. secondly, I get constants like C1 and C2 etc... Though I have defined the values of all parameters of functions. Please tell me what is wrong in my code:
%defined parameters
hf12 = exp(-21.6079+0.0099).*exp(-0.0134.*t)
hf13 = 0
hf14 = 0
hf15 = exp(-9.65573+0.01844+0.0821).*exp(0.02246*t)
hf11 = -(hf12+hf15)
hf21 = 0
hf23 = exp(-1.666-0.1116).*exp(-0.0025.*t)
hf24 = exp(-8.96236+0.07691).*exp(0.00978.*t)
hf25 = exp(-9.65573+0.08218).*exp(0.02246.*t)
hf22 = -(hf23+hf24+hf25)
hf31 = 0
hf32 = exp(-21.6079+0.0676+0.0099).*exp(-0.0134.*t)
hf34 = 0
hf35 = exp(-9.65573-(0.11853)+0.08218).*exp(0.02246.*t)
hf33 = -(hf32+hf35)
hf41 = 0
hf42 = exp(-21.609-0.4176+0.0099).*exp(-0.0134.*t)
hf43 = 0
hf45 = exp(-9.65573-0.00415+0.08218).*exp(0.02246.*t)
hf44 = -(hf42+hf45)
%% solution
syms p11(t) p22(t) p33(t) p44(t) p55(t) p12(t) p13(t) p14(t) p15(t) p21(t) p23(t) p24(t) p25(t) ...
p31(t) p32(t) p34(t) p35(t) p41(t) p42(t) p43(t) p45(t) p51(t) p52(t) p53(t) p54(t) p55(t)
ode = [diff(p11,t) == exp(hf12+hf15),...
diff(p22,t) == exp(hf23+hf24+hf25),...
diff(p33,t) == exp(+hf32+hf35),...
diff(p44,t) == exp(+hf42+hf45),...
diff(p12,t) == p11.*hf12+p12*hf22,...
diff(p13,t) == 0,...
diff(p14,t) == 0,...
diff(p15,t) == p11.*hf15+p12*hf25,...
diff(p21,t) == 0,...
diff(p23,t) == p22.*hf23+p23*hf33,...
diff(p24,t) == p22.*hf24+p24*hf44,...
diff(p25,t) == p22.*hf25+p23*hf35+p24.*hf45,...
diff(p31,t) == 0,...
diff(p32,t) == p32.*hf22+p33*hf32,...
diff(p34,t) == 0,...
diff(p35,t) == p32.*hf25+p33*hf35,...
diff(p41,t) == 0,...
diff(p42,t) == p42.*hf22+p44*hf42,...
diff(p43,t) == 0,...
diff(p45,t) == p42.*hf25+p44*hf45,...
diff(p51,t) == 0,...
diff(p52,t) == 0,...
diff(p53,t) == 0,...
diff(p54,t) == 0,...
diff(p55,t) == 1]
cond1 = p11(t)+p12(t)+p13(t)+p14(t)+p15(t) == 1;
cond2 = p21(t)+p22(t)+p23(t)+p24(t)+p25(t) == 1;
cond3 = p31(t)+p32(t)+p33(t)+p34(t)+p35(t) == 1;
cond4 = p41(t)+p42(t)+p43(t)+p44(t)+p45(t) == 1;
cond5 = p51(t)+p52(t)+p53(t)+p54(t)+p55(t) == 1;
S = dsolve(ode)
These equations are solutions to probabilities therefore, I am expecting the answers between 0 and 1.
采纳的回答
Walter Roberson
2021-1-29
编辑:Walter Roberson
2021-1-29
Q = @(v) sym(v)
syms t real
%defined parameters
hf12 = exp(Q(-21.6079)+Q(0.0099)).*exp(Q(-0.0134).*t)
hf13 = 0
hf14 = 0
hf15 = exp(Q(-9.65573)+Q(0.01844)+Q(0.0821)).*exp(Q(0.02246)*t)
hf11 = -(hf12+hf15)
hf21 = 0
hf23 = exp(Q(-1.666)-Q(0.1116)).*exp(Q(-0.0025).*t)
hf24 = exp(Q(-8.96236)+Q(0.07691)).*exp(Q(0.00978).*t)
hf25 = exp(Q(-9.65573)+Q(0.08218)).*exp(Q(0.02246).*t)
hf22 = -(hf23+hf24+hf25)
hf31 = 0
hf32 = exp(Q(-21.6079)+Q(0.0676)+Q(0.0099)).*exp(Q(-0.0134).*t)
hf34 = 0
hf35 = exp(Q(-9.65573)-Q(0.11853)+Q(0.08218)).*exp(Q(0.02246).*t)
hf33 = -(hf32+hf35)
hf41 = 0
hf42 = exp(Q(-21.609)-Q(0.4176)+Q(0.0099)).*exp(Q(-0.0134).*t)
hf43 = 0
hf45 = exp(Q(-9.65573)-Q(0.00415)+Q(0.08218)).*exp(Q(0.02246).*t)
hf44 = -(hf42+hf45)
%% solution
syms p11(t) p22(t) p33(t) p44(t) p55(t) p12(t) p13(t) p14(t) p15(t) p21(t) p23(t) p24(t) p25(t) ...
p31(t) p32(t) p34(t) p35(t) p41(t) p42(t) p43(t) p45(t) p51(t) p52(t) p53(t) p54(t) p55(t)
ode = [diff(p11,t) == exp(hf12+hf15),...
diff(p22,t) == exp(hf23+hf24+hf25),...
diff(p33,t) == exp(+hf32+hf35),...
diff(p44,t) == exp(+hf42+hf45),...
diff(p12,t) == p11.*hf12+p12*hf22,...
diff(p13,t) == 0,...
diff(p14,t) == 0,...
diff(p15,t) == p11.*hf15+p12*hf25,...
diff(p21,t) == 0,...
diff(p23,t) == p22.*hf23+p23*hf33,...
diff(p24,t) == p22.*hf24+p24*hf44,...
diff(p25,t) == p22.*hf25+p23*hf35+p24.*hf45,...
diff(p31,t) == 0,...
diff(p32,t) == p32.*hf22+p33*hf32,...
diff(p34,t) == 0,...
diff(p35,t) == p32.*hf25+p33*hf35,...
diff(p41,t) == 0,...
diff(p42,t) == p42.*hf22+p44*hf42,...
diff(p43,t) == 0,...
diff(p45,t) == p42.*hf25+p44*hf45,...
diff(p51,t) == 0,...
diff(p52,t) == 0,...
diff(p53,t) == 0,...
diff(p54,t) == 0,...
diff(p55,t) == 1].';
ode = ode(t);
cond1 = p11(t)+p12(t)+p13(t)+p14(t)+p15(t) == 1;
cond2 = p21(t)+p22(t)+p23(t)+p24(t)+p25(t) == 1;
cond3 = p31(t)+p32(t)+p33(t)+p34(t)+p35(t) == 1;
cond4 = p41(t)+p42(t)+p43(t)+p44(t)+p45(t) == 1;
cond5 = p51(t)+p52(t)+p53(t)+p54(t)+p55(t) == 1;
S = dsolve(ode)
S.p11
vpa(S.p11, 5)
Sc = struct2cell(S);
Sv = simplify(vertcat(Sc{:}), 'steps', 10)
symvar(Sv)
conds = [cond1; cond2; cond3; cond4; cond5]
temp = subs(conds, S);
%do not simplify() the equations directly, as it will test to see
%whether the left side equals the right side and will say "symfalse"
conds_subs = simplify(lhs(temp)-rhs(temp), 'steps', 10)
symvar(conds_subs)
5 个评论
Walter Roberson
2021-1-30
Your first four p5* have derivative 0 so they must be constant. Your p55 derivative is 1, so the function must be 1*t plus a constant. The five together total 1. But the five added are a series of constants plus t. That cannot be constant unless t is restricted to 0. Therefore your equations are wrong.
Walter Roberson
2021-1-30
Notice that you have exp() of terms that are already exp(). See sigma 19 in the above "where" list to see it come in as a factor. You can be fairly sure that you will not be able to find a closed form solution for integrals or ode that include such terms.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Equation Solving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!