Solve eqn and get real solution

77 views (last 30 days)
ly
ly on 8 Oct 2015
Edited: ly on 8 Oct 2015
I want to solve an eqn and get the real solution. This is the code:
...
s=solve(R_);
...
And this is solution: s =
0.3971412063699492853956558622094
-0.8763850946630804323385057262195
- 0.13537805585343442652857506799495 - 0.83663803641655759940578883730279*i
- 0.13537805585343442652857506799495 + 0.83663803641655759940578883730279*i
As you can see "s" has two solutions are real (0.3971 and -0.87638) and two imaginary (with i). The real solution is needed. Which command can be used in this case? Give the example is helpful.

Answers (2)

Torsten
Torsten on 8 Oct 2015
s=solve(R_,s,'Real',true);
Best wishes
Torsten.
  1 Comment
ly
ly on 8 Oct 2015
Edited: ly on 8 Oct 2015
I see it is not working. I use MatLab R2011b
This is the code: y is function, s is variable
syms s
y=-(2*((622930548819969075*s^4)/147573952589676412928 - (45369884049352485*s^3)/576460752303423488 + (69272938975695885*s^2)/144115188075855872 - (2396595835289415*s)/2251799813685248 + 2755552026909489/4503599627370496)*((124586109763993815*s^5)/147573952589676412928 - (45369884049352485*s^4)/2305843009213693952 + (23090979658565295*s^3)/144115188075855872 - (2396595835289415*s^2)/4503599627370496 + (2755552026909489*s)/4503599627370496 - 8557508135623347/36028797018963968) + 2*((10728642163125225*s^3)/288230376151711744 - (938834444243547705*s^4)/295147905179352825856 - (72312578171060145*s^2)/576460752303423488 + (3614047914544827*s)/36028797018963968 + 17054950948113267/1152921504606846976)*((10728642163125225*s^4)/1152921504606846976 - (187766888848709541*s^5)/295147905179352825856 - (24104192723686715*s^3)/576460752303423488 + (3614047914544827*s^2)/72057594037927936 + (17054950948113267*s)/1152921504606846976 - 1819839641949093/72057594037927936))/(2*(((17054950948113267*s)/1152921504606846976 + (3614047914544827*s^2)/72057594037927936 - (24104192723686715*s^3)/576460752303423488 + (10728642163125225*s^4)/1152921504606846976 - (187766888848709541*s^5)/295147905179352825856 - 1819839641949093/72057594037927936)^2 + ((2755552026909489*s)/4503599627370496 - (2396595835289415*s^2)/4503599627370496 + (23090979658565295*s^3)/144115188075855872 - (45369884049352485*s^4)/2305843009213693952 + (124586109763993815*s^5)/147573952589676412928 - 8557508135623347/36028797018963968)^2)^(3/2))
m=solve(y,s)
mm=solve(y,s,'Real',true)
This is result:
y =
-(((1341080270390653*s^3)/18014398509481984 - (1833661023913179*s^4)/288230376151711744 - (4519536135691259*s^2)/18014398509481984 + (3614047914544827*s)/18014398509481984 + 4263737737028317/144115188075855872)*((1341080270390653*s^4)/144115188075855872 - (5867715276522173*s^5)/9223372036854775808 - (6026048180921679*s^3)/144115188075855872 + (3614047914544827*s^2)/72057594037927936 + (4263737737028317*s)/288230376151711744 - 1819839641949093/72057594037927936) + ((608330614082001*s^4)/72057594037927936 - (5671235506169061*s^3)/36028797018963968 + (4329558685980993*s^2)/4503599627370496 - (2396595835289415*s)/1125899906842624 + 2755552026909489/2251799813685248)*((7786631860249613*s^5)/9223372036854775808 - (5671235506169061*s^4)/288230376151711744 + (1443186228660331*s^3)/9007199254740992 - (2396595835289415*s^2)/4503599627370496 + (2755552026909489*s)/4503599627370496 - 8557508135623347/36028797018963968))/(2*(((2755552026909489*s)/4503599627370496 - (2396595835289415*s^2)/4503599627370496 + (1443186228660331*s^3)/9007199254740992 - (5671235506169061*s^4)/288230376151711744 + (7786631860249613*s^5)/9223372036854775808 - 8557508135623347/36028797018963968)^2 + ((4263737737028317*s)/288230376151711744 + (3614047914544827*s^2)/72057594037927936 - (6026048180921679*s^3)/144115188075855872 + (1341080270390653*s^4)/144115188075855872 - (5867715276522173*s^5)/9223372036854775808 - 1819839641949093/72057594037927936)^2)^(3/2))
m =
0.85586995465205551704383696315741
3.3845549086104546062118333757515
6.0644608074070649395928866885874
0.86774544065327612268034185895668 - 0.28338346625708125900409850345349*i
0.86774544065327612268034185895668 + 0.28338346625708125900409850345349*i
5.9090579197766355323813767511608 - 3.2214680329909146257449746295832*i
5.9090579197766355323813767511608 + 3.2214680329909146257449746295832*i
6.2175092150938920522167229879549 + 0.81988112353725460786890788489671*i
6.2175092150938920522167229879549 - 0.81988112353725460786890788489671*i
mm =
0.85586995465205551704383696315741
3.3845549086104546062118333757515
6.0644608074070649395928866885874
0.86774544065327612268034185895668 - 0.28338346625708125900409850345349*i
0.86774544065327612268034185895668 + 0.28338346625708125900409850345349*i
5.9090579197766355323813767511608 - 3.2214680329909146257449746295832*i
5.9090579197766355323813767511608 + 3.2214680329909146257449746295832*i
6.2175092150938920522167229879549 + 0.81988112353725460786890788489671*i
6.2175092150938920522167229879549 - 0.81988112353725460786890788489671*i
As you can see both "m" and "mm" solution have imaginary parts "i".
Can you check again?

Sign in to comment.


Torsten
Torsten on 8 Oct 2015
syms s
y=-(2*((622930548819969075*s^4)/147573952589676412928 - (45369884049352485*s^3)/576460752303423488 + (69272938975695885*s^2)/144115188075855872 - (2396595835289415*s)/2251799813685248 + 2755552026909489/4503599627370496)*((124586109763993815*s^5)/147573952589676412928 - (45369884049352485*s^4)/2305843009213693952 + (23090979658565295*s^3)/144115188075855872 - (2396595835289415*s^2)/4503599627370496 + (2755552026909489*s)/4503599627370496 - 8557508135623347/36028797018963968) + 2*((10728642163125225*s^3)/288230376151711744 - (938834444243547705*s^4)/295147905179352825856 - (72312578171060145*s^2)/576460752303423488 + (3614047914544827*s)/36028797018963968 + 17054950948113267/1152921504606846976)*((10728642163125225*s^4)/1152921504606846976 - (187766888848709541*s^5)/295147905179352825856 - (24104192723686715*s^3)/576460752303423488 + (3614047914544827*s^2)/72057594037927936 + (17054950948113267*s)/1152921504606846976 - 1819839641949093/72057594037927936))/(2*(((17054950948113267*s)/1152921504606846976 + (3614047914544827*s^2)/72057594037927936 - (24104192723686715*s^3)/576460752303423488 + (10728642163125225*s^4)/1152921504606846976 - (187766888848709541*s^5)/295147905179352825856 - 1819839641949093/72057594037927936)^2 + ((2755552026909489*s)/4503599627370496 - (2396595835289415*s^2)/4503599627370496 + (23090979658565295*s^3)/144115188075855872 - (45369884049352485*s^4)/2305843009213693952 + (124586109763993815*s^5)/147573952589676412928 - 8557508135623347/36028797018963968)^2)^(3/2))
m=solve(y,s)
ix=arrayfun(@isreal,double(m));
m=m(ix);
disp(m);
Best wishes
Torsten.
  1 Comment
ly
ly on 8 Oct 2015
Edited: ly on 8 Oct 2015
Your code is run and this is the result in my MatLab:
y =
-(((1341080270390653*s^3)/18014398509481984 - (1833661023913179*s^4)/288230376151711744 - (4519536135691259*s^2)/18014398509481984 + (3614047914544827*s)/18014398509481984 + 4263737737028317/144115188075855872)*((1341080270390653*s^4)/144115188075855872 - (5867715276522173*s^5)/9223372036854775808 - (6026048180921679*s^3)/144115188075855872 + (3614047914544827*s^2)/72057594037927936 + (4263737737028317*s)/288230376151711744 - 1819839641949093/72057594037927936) + ((608330614082001*s^4)/72057594037927936 - (5671235506169061*s^3)/36028797018963968 + (4329558685980993*s^2)/4503599627370496 - (2396595835289415*s)/1125899906842624 + 2755552026909489/2251799813685248)*((7786631860249613*s^5)/9223372036854775808 - (5671235506169061*s^4)/288230376151711744 + (1443186228660331*s^3)/9007199254740992 - (2396595835289415*s^2)/4503599627370496 + (2755552026909489*s)/4503599627370496 - 8557508135623347/36028797018963968))/(2*(((2755552026909489*s)/4503599627370496 - (2396595835289415*s^2)/4503599627370496 + (1443186228660331*s^3)/9007199254740992 - (5671235506169061*s^4)/288230376151711744 + (7786631860249613*s^5)/9223372036854775808 - 8557508135623347/36028797018963968)^2 + ((4263737737028317*s)/288230376151711744 + (3614047914544827*s^2)/72057594037927936 - (6026048180921679*s^3)/144115188075855872 + (1341080270390653*s^4)/144115188075855872 - (5867715276522173*s^5)/9223372036854775808 - 1819839641949093/72057594037927936)^2)^(3/2))
m =
0.85586995465205551704383696315741
3.3845549086104546062118333757515
6.0644608074070649395928866885874
0.86774544065327612268034185895668 - 0.28338346625708125900409850345349*i
0.86774544065327612268034185895668 + 0.28338346625708125900409850345349*i
5.9090579197766355323813767511608 - 3.2214680329909146257449746295832*i
5.9090579197766355323813767511608 + 3.2214680329909146257449746295832*i
6.2175092150938920522167229879549 + 0.81988112353725460786890788489671*i
6.2175092150938920522167229879549 - 0.81988112353725460786890788489671*i
[ empty sym ]
It is "[ empty sym ]"
Do you think it could be the version I used is MatLab R21011b?

Sign in to comment.

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!