symbolic vector to usual vector.

3 views (last 30 days)
I have a 1xn sym array, it as symbolic numbers and 1 variable. little example:
g =
[ 1, (3*5^(1/2))/10, -(15*k)/29, -(27*5^(1/2)*((100*k)/261 - 370/2349))/200, (75*k^2)/1682 + (25*k)/522 + 9/232,...]
What I want to do is get this as a numerical polynomial in k, to find the roots.
One thing I tried was:
q=0;
for i=1:n
q=g(i)+q;
end
To get a symbolic expression that I can solve with
s=solve(q==0,k)
However, this only gives me the root(long expression,z,1) (4 roots, every root at the end changes the 1 for 2,3,4)
That's it, I want to solve for k.
Thanks in advance.

Accepted Answer

the cyclist
the cyclist on 3 Dec 2017
A quick search found this answer, which suggest that sym2poly and roots will do what you want.
  1 Comment
Marcos Hermosilla
Marcos Hermosilla on 3 Dec 2017
Thanks for encouraging that option, I had already tried that for g, but I never though on trying it for q, that seems to work, thanks.

Sign in to comment.

More Answers (1)

Karan Gill
Karan Gill on 5 Dec 2017
You don't need a loop to sum g. Just use sum. Then use vpasolve instead of solve to get numeric results. Easy.
>> syms k
>> g = [ 1, (3*5^(1/2))/10, -(15*k)/29, -(27*5^(1/2)*((100*k)/261 - 370/2349))/200, (75*k^2)/1682 + (25*k)/522 + 9/232]
g =
[ 1, (3*5^(1/2))/10, -(15*k)/29, -(27*5^(1/2)*((100*k)/261 - 370/2349))/200, (75*k^2)/1682 + (25*k)/522 + 9/232]
>> g = sum(g)
g =
(3*5^(1/2))/10 - (245*k)/522 + (75*k^2)/1682 - (27*5^(1/2)*((100*k)/261 - 370/2349))/200 + 241/232
>> gSol = vpasolve(g,k)
gSol =
4.655999784043073895594300397083
8.4637649957826080781662669845712

Community Treasure Hunt

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

Start Hunting!