Solve function is unable to return the results of System of equations in the desired single number format instead of fraction ? help

3 Ansichten (letzte 30 Tage)
% In am interested in obtaining Steady state solution of 6 state ergodic
% continuous time markov chain where the long term probabilies in each
% state is given by Vector P = [ p1 p2 p3 p4 p5 p6] and
% State Transition rate matrix A wehre
% A =[-0.00074 0.00062 0.00012 0 0 0;
% 30 -30.00077 0.00031 0.00046 0 0;
% 0 0 -0.00012 0.00012 0 0;
% 0 0 0 - 0.00063 0.0004 0.00023;
% 2 0 0 0 -2 0 ;
% 0.2 0 0 0 0 -0.2]
% We obtain p1, p2 ...p6 by solving Equation 1 & 2 below:
% P*A = 0 .... Equation 1
% p1+p2+p3+4+p5+p6 = 1 ..... Equation 2
%
format long
syms eqn1 eqn2 eqn3 eqn4 eqn5 eqn6 eqn7 eqns sol p1sol p2sol p3sol p4sol p5sol p6sol p1 p2 p3 p4 p5 p6
eqn1 = -p1*0.00074+p2*30+ p5*2 + p6*0.2 == 0
eqn2 = p1*0.00062 - p2*30.00077 == 0;
eqn3 = p1*0.00012 +0.00031*p2 - p3*0.00012 == 0;
eqn4 = p2*0.00046 +p3*0.00012- p4*0.00063 == 0;
% eqn5 = p4*0.0004 - p5*2 == 0; we drop this equation and use eqn7 below
% for obatining p1, p2 ...p6
eqn6 = p4*0.00023 - p5*0.2 == 0;
eqn7 = p1+p2+p3+p4+p5+p6==1;
eqns = [eqn1, eqn2, eqn3, eqn4, eqn6, eqn7]
sol = solve([eqns],[p1,p2,p3,p4,p5,p6]);
format short
p1sol = sol.p1
p2sol = sol.p2
p3sol = sol.p3
p4so4 = sol.p4
p5so5 = sol.p5
p6so6 = sol.p6
p1sol = sol.p1
p2sol = sol.p2
p3sol = sol.p3
p4so4 = sol.p4
p5so5 = sol.p5
p6so6 = sol.p6
>> Solve_ergodic_ctmc
eqn1 =
30*p2 - (37*p1)/50000 + 2*p5 + p6/5 == 0
eqns =
[30*p2 - (37*p1)/50000 + 2*p5 + p6/5 == 0, (31*p1)/50000 - (8444466037051747*p2)/281474976710656 == 0, (3*p1)/25000 + (31*p2)/100000 - (3*p3)/25000 == 0, (23*p2)/50000 + (3*p3)/25000 - (63*p4)/100000 == 0, (23*p4)/100000 - p5/5 == 0, p1 + p2 + p3 + p4 + p5 + p6 == 1]
p1sol =
16625042510445626906250000/36395607773662890434476703
p2sol =
343575393447444480000/36395607773662890434476703
p3sol =
16625930080212032804490000/36395607773662890434476703
p4so4 =
3167094689375285334920000/36395607773662890434476703
p5so5 =
3642158892781578135158/36395607773662890434476703
p6so6 =
-26445240656283633798455/36395607773662890434476703

Akzeptierte Antwort

John D'Errico
John D'Errico am 23 Jun. 2021
Bearbeitet: John D'Errico am 23 Jun. 2021
Sure it is. You just need to convert the result from a fraction, into a floating point number. So either use double to create a double precision result, or use vpa to create a symbolic floating point number. Thus...
double(p1sol)
or
vpa(p1sol)
Note that setting format short did nohing, since the result that was displayed was in symbolic form.
Or, you could have used vpasolve instead of solve. vpasolve would return a floating point symbolic result directly.

Weitere Antworten (0)

Kategorien

Mehr zu Systems of Nonlinear Equations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by