Solve Function Doesn't Give The Solutions

This is the parameter
clear; close; clc;
syms a1_head a2_head b hstar
%Parameter Massa
m1 = 8095; % massa train set 1 dalam kg
m2 = 8500; % massa train set 2 dalam kg
g = 10;
c_0_1 = 0.01176;
c_1_1 = 0.00077616;
c_2_1 = 4.48 ;
c_0_2 = 0.01176 ;
c_1_2 = 0.00077616;
c_2_2 = 4.48;
v_0 = 300;
hstar = 120;
a_1 = -1./m1.*(c_1_1 + 2.*c_2_1.*v_0);
a_2 = -1./m2.*(c_1_2 + 2.*c_2_2.*v_0);
a_1_head = 1-(a_1.*hstar);
a_2_head = 1-(a_2.*hstar);
b = 1;
This is the model
% Model data
A = sym(zeros(4,4));
A(1,2) = a_1_head;
A(3,2) = (a_2_head) - 1; A(3,4) = a_2_head;
display(A);
B = sym(zeros(4,2));
B(1,1) = -b*hstar;
B(2,1) = b;
B(3,2) = -b*hstar ;
B(4,1) = -b; B(4,2) = b;
display(B);
This is the Q and R matrix for LQR
% Q and R matrices for ARE
Q = [10 0 0 0;
0 10 0 0;
0 0 10 0;
0 0 0 10;
];
R = sym(zeros(2,2)); R(1,:) = [1 0]; R(2,:) = [0 1]; display(R);
This is the S matrix that I want to find the value
% Matrix S to find
svar = sym('s',[1 16]);
S = [svar(1:4); svar(5:8); svar(9:12); svar(13:16)];
S(2,1) = svar(2);
S(3,1) = svar(3);
S(3,2) = svar(7);
S(4,1) = svar(4);
S(4,2) = svar(8);
S(4,3) = svar(12);
display(S);
This is the Algebra Ricatti Equation (ARE) in LQR Control
% LHS of ARE: A'*S + S*A' - S*B*Rinv*B'*S
left_ARE = transpose(A)*S + S*A - S*B*inv(R)*transpose(B)*S;
display(left_ARE);
% RHS of ARE: -Q
right_ARE = -Q;
display(right_ARE);
I use the solve function to find value of S matriks
Find S
syms s1 s2 s3 s4 s6 s7 s8 s11 s12 s16
[Sol_s] = solve(left_ARE == right_ARE,s1,s2,s3,s4,s6,s7,s8,s11,s12,s16,'Real',true)
But the answer(solution) from solve like that. There is a variable x that i don't know
Sol_s =
struct with fields:
s1: [2×1 sym]
s2: [2×1 sym]
s3: [2×1 sym]
s4: [2×1 sym]
s6: [2×1 sym]
s7: [2×1 sym]
s8: [2×1 sym]
s11: [2×1 sym]
s12: [2×1 sym]
s16: [2×1 sym]
>> vpa(Sol_s.s1)
ans =
0.00000000000000000040859201997183266363736715737362*x^7 - 0.000000000001292747173772775983242070865976*x^6 + 0.0000015262175064767887069297714018443*x^5 - 0.79679406124260841586996673723117*x^4 + 155208.81351720644561857433778132*x^3 + 7112858.7612670786982068414016205*x^2 + 108634010.42148359450942426361058*x + 552988510.84561362711489334430607
0.00000000000000000020499055506656593566660625665166*x^7 - 0.00000000000064871158271130010923295137360766*x^6 + 0.00000076601975870779972515899504293451*x^5 - 0.39998727113373076657212134425168*x^4 + 77926.337795483306183297402674704*x^3 + 3571036.0433220579501871782146977*x^2 + 54537896.71647223250810434173391*x + 277607756.88722181441803051789872
>> vpa(Sol_s.s2)
ans =
- 0.00000000000000000031260583959047249814694055447793*x^7 + 0.00000000000098905577988552374034850303549741*x^6 - 0.0000011676793205823800112784869250653*x^5 + 0.60961154908164182468172656314696*x^4 - 118747.17710114932017447930936862*x^3 - 5457407.0206974194274463617331546*x^2 - 83573329.145320152948094088924873*x - 426479043.54369671880276326751334
- 0.00000000000000000032365118353566263532308345273194*x^7 + 0.0000000000010242240764674830710076551817231*x^6 - 0.0000012094370452875433539209714880716*x^5 + 0.63152332992457965547656341647457*x^4 - 123034.60895321337878520443201568*x^3 - 5655911.3774460846397440247453401*x^2 - 86636236.777808615440767863132122*x - 442230554.80769573806658012394346
>> vpa(Sol_s.s3)
ans =
0.0000000000000000000010776575438999520316538127429084*x^7 - 0.0000000000000034096078345527396375991806997797*x^6 + 0.0000000040253825881136818413774049305516*x^5 - 0.0021015349611454802346225087217245*x^4 + 409.36084570596063399343217949922*x^3 + 18938.36880217893351979479924197*x^2 + 291993.50120838165763852700250626*x + 1500485.4678457105543481903948988
- 0.00000000000000000041666832842512374615974790886976*x^7 + 0.0000000000013185854853866499151812140304409*x^6 - 0.0000015570286714848943410537775793585*x^5 + 0.8130229545475701019194852997876*x^4 - 158394.79247503034137610097150089*x^3 - 7259023.3274984798704782100693356*x^2 - 110868678.30972936220866037440766*x - 564374966.98865965783991745150745
>> vpa(Sol_s.s4)
ans =
0.0000000000000000000014228409703424497861474646268027*x^7 - 0.0000000000000045017366112576086307555233406427*x^6 + 0.000000005314750975152131845714002972785*x^5 - 0.0027746779808566367452971500674644*x^4 + 540.48408167395620003882852791153*x^3 + 24757.747980942663555794256513835*x^2 + 377958.31952099355656247974473802*x + 1923166.530892430026770775363493
0.0000000000000000000023193355511678347273166656795793*x^7 - 0.0000000000000073397520256740640487837787182755*x^6 + 0.0000000086670182256809939350882653924303*x^5 - 0.0045255973789649557650852704388279*x^4 + 881.68616552361166280706272097366*x^3 + 40393.656783854177046779159405732*x^2 + 616754.69331512724884616078670876*x + 3138681.4020773718736419352352328
>> vpa(Sol_s.s6)
ans =
- 0.000000000000000022006336529571817230209213311748*x^7 + 0.000000000069626005207446692167524264364454*x^6 - 0.000082200475821668055631814879425621*x^5 + 42.914497164630049410319474600551*x^4 - 8359387.0930143709758499635784225*x^3 - 382387662.93012000327080222222905*x^2 - 5827384455.2847427100003526481025*x - 29587579250.550523363703915448321
- 0.000000000000000025002231287155086974127450112697*x^7 + 0.000000000079121875258332337913776610719734*x^6 - 0.000093429687431695914874771958800029*x^5 + 48.785538562659557207332817154875*x^4 - 9504498.929505799236089462678773*x^3 - 435370306.00846953347659747350646*x^2 - 6644367672.3679146002218490792474*x - 33786329437.38166020805340239827
>> vpa(Sol_s.s7)
ans =
0.00000000000000000025569963231254537081649139584652*x^7 - 0.00000000000080900975738079800385855474939705*x^6 + 0.00000095511681683491535731968205794489*x^5 - 0.49863865781308244522352509310329*x^4 + 97130.498837171086515556658964247*x^3 + 4494101.0379877774836523120182835*x^2 + 69298502.116075437676103381862363*x + 356149465.9042365809352931154343
0.0000000000000000000015023043416658044818117509971356*x^7 - 0.0000000000000047541811528920007743725411473973*x^6 + 0.0000000056138919601726527683759200771913*x^5 - 0.002931367433451308848204776259538*x^4 + 571.09503266523001592434936146943*x^3 + 26159.338852936025767577334375426*x^2 + 399345.5827675731856692656648735*x + 2031937.4929783588149908825597278
>> vpa(Sol_s.s8)
ans =
- 0.000000000000000000017423118618084831929830862790716*x^7 + 0.000000000000055125128523282993141578608099266*x^6 - 0.000000065080736244752471556193477098825*x^5 + 0.033976773274815242226234938519543*x^4 - 6618.3918152997107197929705528418*x^3 - 303061.20015840970654893674015787*x^2 - 4623463.04197949737532115401195*x - 23501224.452355499378972417099829
- 0.000000000000000000018476917340887162236508871167814*x^7 + 0.000000000000058471915042480914496818710438269*x^6 - 0.000000069045541385168727596306044837525*x^5 + 0.036053035957476786546322342447713*x^4 - 7023.9263332222742397498791136158*x^3 - 321824.06004694090757346294728009*x^2 - 4912773.5723496489797387292827707*x - 24988039.623927850151456500151167
>> vpa(Sol_s.s11)
ans =
0.00000000000000000041119629783273028264519058921762*x^7 - 0.0000000000013009868665244108119791105781729*x^6 + 0.0000015359452882952913401827632335578*x^5 - 0.80187265434412110159568710275759*x^4 + 156198.08052664176034300508696723*x^3 + 7158323.8866181131831523373220071*x^2 + 109330254.65157047767529156319121*x + 556541496.93083652400446027963023
- 0.00000000000000000020771378465236870650240546526077*x^7 + 0.00000000000065732949437268293588570845859109*x^6 - 0.00000077619606862262249756751814375767*x^5 + 0.40530096411080625205677575409412*x^4 - 78961.561847579934284088187742172*x^3 - 3618623.8712567317582544282624458*x^2 - 55266816.721319493314377599392582*x - 281328390.05487908210968779383083
>> vpa(Sol_s.s12)
ans =
- 0.0000000000000000000015153372531006669942761978246883*x^7 + 0.0000000000000047943863006019005344930952094381*x^6 - 0.0000000056602533372161527651811224147036*x^5 + 0.0029550548809761743405798500431343*x^4 - 575.62005058550944282823558765466*x^3 - 26349.726554223897542645543275317*x^2 - 401979.85441516660058061899440103*x - 2043879.8478415220815018039779193
- 0.00000000000000000000081703120950203024550491468244366*x^7 + 0.0000000000000025855708727820632744112375708782*x^6 - 0.000000003053126265508341166712345315239*x^5 + 0.00159422994551364691688049417929*x^4 - 310.59113285838164688271335950423*x^3 - 14234.317930918151279201825030306*x^2 - 217409.11054755406317689512183527*x - 1106743.9090990130586510526755051
>> vpa(Sol_s.s16)
ans =
x
x

2 件のコメント

Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 17 日
Please help me
Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 21 日
i get the warning like this
Warning: Solutions are parameterized by the symbols: x. To include parameters and conditions in the solution, specify the
'ReturnConditions' value as 'true'.
> In sym/solve>warnIfParams (line 475)
In sym/solve (line 357)
In Algebra_Ricatti_Equation_Dengan_Fungsi_Solve (line 85)
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify
the 'ReturnConditions' value as 'true'.
> In sym/solve>warnIfParams (line 478)
In sym/solve (line 357)
In Algebra_Ricatti_Equation_Dengan_Fungsi_Solve (line 85)
What does is mean?

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2020 年 9 月 21 日

1 投票

Warning: Solutions are parameterized by the symbols: x. To include parameters and conditions in the solution, specify the
There are several possibilities.
  1. When you use non-polynomial equations, it is not uncommon for there to be situations under which something that is being divided by could hypothetically equal 0. solve() tries to figure out all combinations of values under which expressions it divides by can be 0, and lists out all of the combinations as separate solutions, together with the solution that would be implied when that combination is 0. It is not uncommon in such a situation for a variable to vanish under the hypothesis that some of the inputs are 0, and when that happens the number of variables in the equations can drop below the number of equations, giving you an indefinite number of solutions. MATLAB generates parametric solutions for those situations, generating a variable to take the parametric solution with regards to.
  2. When you use nonlinear equations, there can potentially be families of solutions instead of single solutions. This is most obvious when you are using periodic or semi-periodic functions such as trig functions or bessel functions, but it can also occur even with something like x*exp(x) == constant, which can have up to two real solutions for some constants. When MATLAB detects that multiple solutions are possible. it will generate a variable that stands in for the multiple solutions, and then in the "conditions" returned when returnconditions is true, it will describe the periodicity or constraints
  3. When you use inequalities, there are multiple solutions. MATLAB synthesizes a variable with that is as refined as practical, and then in the "conditions" it describes the constraints using inequalities
  4. Sometimes there are exact solutions based upon the coefficients, but the exact solutions would be expressed as the roots of an expression involving variables. In such a situation, MATLAB might generate the exact solutions in-line, without using an extra parameter, but in other cases the expression would be complex enough that instead MATLAB generates an extra variable and then in "conditions" it describes the polynomial whose roots would form the variable. In this case, MATLAB can essentially be "lazy", not bothering to work out something that has a perfectly good solution.
  5. Sometimes equations can be solved in terms of systems of polynomials, in which one variable becomes the primary variable, and the other variables can then be expressed in terms of polynomial expressions of the primary variable. This gives you a family of solutions for the variables, in which each variable other than the first has a exact expression based upon the value of the first variable, but the first variable has multiple roots. Instead of "expanding" the solutions to all of those other variables, MATLAB sometimes generates an intermediate variable and phrases the other variables in terms of that variable, and in the conditions lists the generated variable in terms of the polynomial whose roots it is. This can be much more compact, and can make the solutions for the other variables understandable when expanding the roots out would just tend to obscure the solutions.
So, MATLAB has found solutions to the equations, but those solutions either have conditions attached (e.g., avoiding division by 0) or have multiple solutions (periodic / semi-periodic), or the solutions are most naturally expressed as a parameterized family.
In such cases, it is often necessary to go through and carefully solve for the combinations of circumstances that make the listed conditions true.
In this particular case, it is the last of those that applies: the solutions it can find are families of solutions based upon all of the real roots of a degree 8 polynomial. That particular polynomial happens to have all 8 of its roots real, so the two solutions (per variable) that MATLAB finds, parameterized in terms of the roots of a polynomial of degree 8, means that there are actually a total of 16 different solutions. (The second family of solutions uses a different polynomial of degree 8, by the way -- the two are very similar but not quite the same.)
X = solve(sol_s1.conditions(1));
subs(sol_s1.s1(1), sol_s1.parameters, X)

19 件のコメント

Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 21 日
I will try. Thank you for help me
Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 21 日
I just try but it can't run the code
Error using sym/subsref (line 868)
SYM objects do not support nested indexing. Assign intermediate values to variables instead.
Error in ARE_Find_S (line 74)
X = solve(Sol_s.s1.conditions(1));
>> subs(Sol_s1.s1(1), sol_s1.parameters, X)
Unable to resolve the name Sol_s1.s1.
Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 22 日
編集済み: Ivan Dwi Putra 2020 年 9 月 22 日
what do you mean sol_s1.conditions(1)?
do you mean sol_s1.conditions(1) is the first vpa(Sol_s.s1)? like this
0.00000000000000000040859201997183266363736715737362*x^7 - 0.000000000001292747173772775983242070865976*x^6 + 0.0000015262175064767887069297714018443*x^5 - 0.79679406124260841586996673723117*x^4 + 155208.81351720644561857433778132*x^3 + 7112858.7612670786982068414016205*x^2 + 108634010.42148359450942426361058*x + 552988510.84561362711489334430607
and what about Sol_s1.s1(1) ?
and in sol_s1.parameters, X parameter is what?
and what about x in all solution from solve? is x = X ?
Walter Roberson
Walter Roberson 2020 年 9 月 22 日
Where I wrote sol_s1 substitute Sol_s which is the output of solve() called with 'returnconditions', true
vpa(Sol_s.s1) %will probably be something in terms of x
%the first solution for s1, and the conditions under which the first solution holds
vpa(Sol_s.s1(1)), vpa(Sol_s.conditions(1))
and in sol_s1.parameters, X parameter is what?
It is the name of the variable that MATLAB generated internally to parameterize the solution.
Walter Roberson
Walter Roberson 2020 年 9 月 22 日
%Find S
syms s1 s2 s3 s4 s6 s7 s8 s11 s12 s16
disp('Starting solving. Please wait')
Sol_s = solve(left_ARE == right_ARE,s1,s2,s3,s4,s6,s7,s8,s11,s12,s16,'Real',true, 'returnconditions', true);
disp('done solving!')
disp('First solution for s1 is:')
s1_1 = Sol_s.s1(1);
disp(vpa(s1_1))
v1 = symvar(s1_1);
fprintf('It was parameterized with respect to generated variable named "%s"\n', char(v1));
c1 = Sol_s.conditions(1);
fprintf('The first solution is true only under the conditions that:\n');
disp(c1);
sol_c1 = vpa(solve(c1, v1));
disp('Thes solution to the first condition are:');
disp(sol_c1);
disp('So the numeric version of the first solution to s1 are:');
s1_1_num = double(subs(s1_1, v1, sol_c1));
disp(s1_1_num);
disp('The numeric version of the first solution to s2 are:');
s2_1_num = double(subs(Sol_s.s2(1), v1, sol_c1));
disp(s2_1_num);
Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 23 日
編集済み: Ivan Dwi Putra 2020 年 9 月 23 日
I want ask about this code
c1 = Sol_s.conditions(1);
fprintf('The first solution is true only under the conditions that:\n');
disp(c1);
When i run this code, the answer like this
The first solution is true only under the conditions that:
in(x, 'real') & x^8 - (916226538835195303940847833543438095319164387471763563279994624106705243132498853771767185403097716940341104196565209649983978085603352459847748941112579960181079604512061144175614588220860842883642767366422053517388208836649577499936966937284363662448750420295680*x^7)/289588484072615531935192761754923769803009942973508764028371901707448967034970137335524241384243405225015390812474556008647007712966351554328649480888837630911921959693728664276514006561882095190312421482871863445022293873876221990191293557441425954657953943 + (988208451938524118722290779907981887595701866579795261275157196814276923495912100507546757898991470429807303147297870196852374614655559332150561105420057020405477685688234902492454774331678311637482754595944242744677684749689588297421972010842317182667212198344488661936148009803742168*x^6)/264562167801738975258412426253192457620729503528207164744626912088018153769544245819303825132216178690526229055486684061376503292835649116736154814581786731429797373530255306938733694116234714642825026001419628154800948294542538548328036890904748518454834600931163839745089 - (64777963473152384021045087144845098840775041316808376408516184381137625105993229843777608699915104682515829506964031988000067384785899534005856111322132423941743051709155353648277145023459614749081594547215024460538988563191297204256641678060825657460413855122908067606672062184687161129162311722563656983680488729489*x^5)/33218807127227759684539100864668001924182004095831766568668800957807645532582470510776953151118106498445683178811489103278300107166270100632573530968330233156307527594217053800773873426378203521435578193690633791325522772045739599127731038373053718237705656796023395053814997001587283449348918083584 + (129784269391234277483799829044040007760022251187845001958492329130331631985469912880243505435271033200486517183363279668437772736760616406852180758947451507168626392981495611817237199045676390437363763057313844933197358755100241539467413154544968306830943774317413884610563143791475761731168842506133858935398534520841699008169382527331023641109635063039*x^4)/341688426844066234624831631941481211287562410536788942300279578390887083371615217768631901342995603321114523213784092391143319447792738820536830210724404879200649331251790446080146041232396139318329696364862971724832354932135988434248422525042966339035400264315182236545030474765048719097792207671992647577622417543431651516743680 + (161652640237197800165614748170112458158119523086000668204139654592766931884850579928756733521686562684408023728598629660068833078997308460017200877050435819477553835145303115801646826293610089249421682086635828521483403341650678513733494396189473787636575331415804742832658416033574386306667704763356753718482453633100138040109205390172186064390811926245*x^3)/6931335932327409140582391700816727977444668255726195259499266670169636269453936602921940827218442920982027999772273671036637606498862026179850236920595480671694861399653928303879626797504252187370831664028022072439894855397713385006759256633092683801677038302291040245485820666291675742486859319407280341673787360297346907766784 + (38277862874072381838222323540820541947308940149284448378166435163659534921797589191159182026900245403695324642212807006477751797485837155150013082549286775114713458652385055245376480649579221593080604717197572972991011022857846401502966275018026968129232181111290906752893969666612835421676380803336370318610081276257814668142212107362495033509096907487926977188833479229939488769928309*x^2)/71295674813785834797366804117466970880670305429334634641446995901257379112274562224519654219017589082412634288387026012725139537199278506624895999385961934100971645455665014261149647301303897320059022194356147672345987519883496280775838590899022614698119909147647593336678194743738920398558633056319188542909861071375608448473370736292081036311499271496007680 + (393356353318377771816450796534715067717601021030744551608036483199869673517569711479968852463067384004737188312095835895770985660419786589930522512464144155108834169870677468306809037849679999421838177237121668144699672977174067559819094909838081423957576686899635398800615716140051122351651000923317132955355777135650048693270152826303676366544585244313115334436141166477861522569379940750962595547216117585316289*x)/71615901557611421480295412026987291034597831511937218745767357498421859572266496543799724971044847901101626516741647914899493577089058815849570456264826939168497833815972587304235960998855122577696634837280647666239507520559418399922767772906079641002954759914314911229877533096635932515447132781138944224873503477407908885010646512928365912727077682590401269759731135278484982218096640 + 31042058860887617537195623425798689475247643831916157754128966841408630134030711621390990791038058438826688582340793689801137733406037697145300060996601001810869914916011436204488687940139541147790482970965795828619982539565930884917873574319443006220800864058966467764390090795911093437738392985666976579825975186528317457019466038653288820802887604701729099776786818836886564225037981510887228289135025341264576053260177833409386080058716452401/1473281364169316232103011164550407859843970252029887966117939661405727426088239857630082620443358193486226139550409000027984419289501791274328708489559056459178652241327313527882065468342355502899335941552913563159551901456520482891337601507949119447818378777681024996739206909882502024529988336741347874200732927964115450877194859314165774754220237629225915028756067364212432424556498114672738010017787189747358105600 == 0
I;m sorry, I still don't really understand, why there is x^8 and what is Sol_s.condition(1), condition (1) is what? thank you.
and why the final find s1 like this code, what is basically looking for a numerical s1 like that
disp('So the numeric version of the first solution to s1 are:');
s1_1_num = double(subs(s1_1, v1, sol_c1));
disp(s1_1_num);
For s3,s4,s6,s7,s8,s11,s12,s16, Is it like this?
disp('The numeric version of the first solution to s3 are:');
s3_1_num = double(subs(Sol_s.s3(1), v2, sol_c2));
disp(s3_1_num);
disp('The numeric version of the first solution to s4 are:');
s4_1_num = double(subs(Sol_s.s4(1), v3, sol_c3));
disp(s4_1_num);
disp('The numeric version of the first solution to s6 are:');
s6_1_num = double(subs(Sol_s.s6(1), v4, sol_c4));
disp(s6_1_num);
disp('The numeric version of the first solution to s7 are:');
s7_1_num = double(subs(Sol_s.s7(1), v6, sol_c6));
disp(s7_1_num);
disp('The numeric version of the first solution to s8 are:');
s8_1_num = double(subs(Sol_s.s8(1), v7, sol_c7));
disp(s8_1_num);
disp('The numeric version of the first solution to s11 are:');
s11_1_num = double(subs(Sol_s.s11(1), v8, sol_c8));
disp(s11_1_num);
disp('The numeric version of the first solution to s12 are:');
s12_1_num = double(subs(Sol_s.s12(1), v11, sol_c11));
disp(s12_1_num);
disp('The numeric version of the first solution to s16 are:');
s16_1_num = double(subs(Sol_s.s16(1), v12, sol_c12));
disp(s16_1_num);
Walter Roberson
Walter Roberson 2020 年 9 月 23 日
You have a non-linear system. When you normalize it, some of the variables end up being multiplied by themselves, so the equations are polynomials. The solutions to polynomials are not single values: they are a set of as many values as the degree of the polynomial, which happens to be degree 8. Also, only real solutions are wanted for this purpose.
MATLAB could have coded the solution by substituting
root(z^8 - (916226538835195303940847833543438095319164387471763563279994624106705243132498853771767185403097716940341104196565209649983978085603352459847748941112579960181079604512061144175614588220860842883642767366422053517388208836649577499936966937284363662448750420295680*z^7)/289588484072615531935192761754923769803009942973508764028371901707448967034970137335524241384243405225015390812474556008647007712966351554328649480888837630911921959693728664276514006561882095190312421482871863445022293873876221990191293557441425954657953943 + (988208451938524118722290779907981887595701866579795261275157196814276923495912100507546757898991470429807303147297870196852374614655559332150561105420057020405477685688234902492454774331678311637482754595944242744677684749689588297421972010842317182667212198344488661936148009803742168*z^6)/264562167801738975258412426253192457620729503528207164744626912088018153769544245819303825132216178690526229055486684061376503292835649116736154814581786731429797373530255306938733694116234714642825026001419628154800948294542538548328036890904748518454834600931163839745089 - (64777963473152384021045087144845098840775041316808376408516184381137625105993229843777608699915104682515829506964031988000067384785899534005856111322132423941743051709155353648277145023459614749081594547215024460538988563191297204256641678060825657460413855122908067606672062184687161129162311722563656983680488729489*z^5)/33218807127227759684539100864668001924182004095831766568668800957807645532582470510776953151118106498445683178811489103278300107166270100632573530968330233156307527594217053800773873426378203521435578193690633791325522772045739599127731038373053718237705656796023395053814997001587283449348918083584 + (129784269391234277483799829044040007760022251187845001958492329130331631985469912880243505435271033200486517183363279668437772736760616406852180758947451507168626392981495611817237199045676390437363763057313844933197358755100241539467413154544968306830943774317413884610563143791475761731168842506133858935398534520841699008169382527331023641109635063039*z^4)/341688426844066234624831631941481211287562410536788942300279578390887083371615217768631901342995603321114523213784092391143319447792738820536830210724404879200649331251790446080146041232396139318329696364862971724832354932135988434248422525042966339035400264315182236545030474765048719097792207671992647577622417543431651516743680 + (161652640237197800165614748170112458158119523086000668204139654592766931884850579928756733521686562684408023728598629660068833078997308460017200877050435819477553835145303115801646826293610089249421682086635828521483403341650678513733494396189473787636575331415804742832658416033574386306667704763356753718482453633100138040109205390172186064390811926245*z^3)/6931335932327409140582391700816727977444668255726195259499266670169636269453936602921940827218442920982027999772273671036637606498862026179850236920595480671694861399653928303879626797504252187370831664028022072439894855397713385006759256633092683801677038302291040245485820666291675742486859319407280341673787360297346907766784 + (38277862874072381838222323540820541947308940149284448378166435163659534921797589191159182026900245403695324642212807006477751797485837155150013082549286775114713458652385055245376480649579221593080604717197572972991011022857846401502966275018026968129232181111290906752893969666612835421676380803336370318610081276257814668142212107362495033509096907487926977188833479229939488769928309*z^2)/71295674813785834797366804117466970880670305429334634641446995901257379112274562224519654219017589082412634288387026012725139537199278506624895999385961934100971645455665014261149647301303897320059022194356147672345987519883496280775838590899022614698119909147647593336678194743738920398558633056319188542909861071375608448473370736292081036311499271496007680 + (393356353318377771816450796534715067717601021030744551608036483199869673517569711479968852463067384004737188312095835895770985660419786589930522512464144155108834169870677468306809037849679999421838177237121668144699672977174067559819094909838081423957576686899635398800615716140051122351651000923317132955355777135650048693270152826303676366544585244313115334436141166477861522569379940750962595547216117585316289*z)/71615901557611421480295412026987291034597831511937218745767357498421859572266496543799724971044847901101626516741647914899493577089058815849570456264826939168497833815972587304235960998855122577696634837280647666239507520559418399922767772906079641002954759914314911229877533096635932515447132781138944224873503477407908885010646512928365912727077682590401269759731135278484982218096640 + 31042058860887617537195623425798689475247643831916157754128966841408630134030711621390990791038058438826688582340793689801137733406037697145300060996601001810869914916011436204488687940139541147790482970965795828619982539565930884917873574319443006220800864058966467764390090795911093437738392985666976579825975186528317457019466038653288820802887604701729099776786818836886564225037981510887228289135025341264576053260177833409386080058716452401/1473281364169316232103011164550407859843970252029887966117939661405727426088239857630082620443358193486226139550409000027984419289501791274328708489559056459178652241327313527882065468342355502899335941552913563159551901456520482891337601507949119447818378777681024996739206909882502024529988336741347874200732927964115450877194859314165774754220237629225915028756067364212432424556498114672738010017787189747358105600, z)
instead of x in each place that x appears in the first solution for the s variables, but the result would be pretty long: the first of the 8 different solutions would be over 70 kilobytes (instead of "only" 30 kilobytes). And when you looked at the 8 solutions for the first of the two families of solutions, it would not be at all clear how they related to each other.
Walter Roberson
Walter Roberson 2020 年 9 月 23 日
Sol_s.condition(1), condition (1) is what
Sol_s.condition(1) is the condition under which Sol.s*(1) is valid for the various s variables.
For example, if you had an equation that included a 1/(x-y) term, then you can multiply everything through by (x-y) so that you no longer have a division, but that fails if there are circumstances under which x == y. When MATLAB is finding the solutions, it will create one solution for the case where x ~= y, and it will create another solution for the circumstance that x == y (it is not necessarily an error for x == y, since you might be in the middle of an exp() term)
In this particular case, the condition is being used to express roots of a polynomial of degree 8 in a form that is more compact than subsituting in the placeholder for roots of a polynomial. (This particular polynomial of degree 8 does not have a closed form algebraic number solution.)
Walter Roberson
Walter Roberson 2020 年 9 月 23 日
For s3,s4,s6,s7,s8,s11,s12,s16, Is it like this?
Not quite. You should be substituting v1 in each of those, not v2, v3, and so on.
v1 is referring to the name of the variable that MATLAB generated, which is stored in sol.parameters . Only one variable was generated.
Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 24 日
編集済み: Ivan Dwi Putra 2020 年 9 月 24 日
this code i still not understand, why need use double and subs? Thank you
so the definition of this is
disp('So the numeric version of the first solution to s1 are:');
s1_1_num = double(subs(s1_1, v1, sol_c1));
disp(s1_1_num);
which code I still don't understand, why should I double and use the subs function
s_num = double(subs(si,parameters,solution for condition)) like this ?
what was the starting formula like when i search in matlab help?
Thank you
Walter Roberson
Walter Roberson 2020 年 9 月 24 日
You do not need to use double and subs. You can proceed by purely numeric root finding with fsolve. However any one call to fsolve will only return one of the 16 solutions to the equations, and to get the other ones you would need good starting values.
The code path I set up for you finds formulas for all 16 solution, and describes the solutions in indefinitely precise form, so you could calculate them to as many decimal places as you needed. It shows you the relationship between the 16 solutions, answering explicitly the questions of how many solutions there are and how to find them. There is no guessing needed about starting points.
Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 24 日
ok thank you for helping me with my problem
Walter Roberson
Walter Roberson 2020 年 9 月 24 日
If you use
[Sol_s] = vpasolve(left_ARE == right_ARE,s1,s2,s3,s4,s6,s7,s8,s11,s12,s16)
then you will get numeric solutions. You will also get warnings that there might be numeric instabilities.
Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 24 日
so if i use vpasolve, i don't need the previous code?
Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 24 日
what the different about use vpasolve which immediately generates a numeric and use previous long code? and the result is different to when i use vpasolve there is 16 variations every S but with use previous code the variant only 8
Walter Roberson
Walter Roberson 2020 年 9 月 24 日
If you use vpasolve() you do not need the code that analyzes the conditions and does the substitutions.
vpasolve() is giving you 16 total solutions for each variable.
solve() is returning two solutions for each variable, but each of the two solutions depends upon a polynomial of degree 8, so each of the two expands to 8, for a total of 2*8 = 16 solutions.
Remember in the solve() code I posted, I had the lines
disp('First solution for s1 is:')
s1_1 = Sol_s.s1(1);
There is also the second solution for s1 that has to be processed, Sol_s.s1(2) which requires finding the solution to the second condition, Sol_s.conditions(2)
Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 25 日
ok,so from my understanding, using both codes will produce the same result right?
Thank you
Walter Roberson
Walter Roberson 2020 年 9 月 25 日
I was worried that due to round-off errors that the values might not match, but when I take double() of both versions, then there are exact matches (which is rare for floating point.) So, yes, both codes will produce the same double() output. The solve() version gives you information about why those particular outputs, and does not give you any warning messages; the vpasolve() version is much less bother but gives you warning messages.
Because of the warning messages that vpasolve() gives, it would be natural to wonder if the vpasolve() results are correct. The fact that double() of the results match the solutions from solve() tells you that double() of the results is as close you can get in double precision to the actual solutions.
Ivan Dwi Putra
Ivan Dwi Putra 2020 年 9 月 25 日
ok thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with Symbolic Math Toolbox についてさらに検索

製品

リリース

R2020a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by