symbolic vector to usual vector.

3 ビュー (過去 30 日間)
Marcos Hermosilla
Marcos Hermosilla 2017 年 12 月 3 日
回答済み: Karan Gill 2017 年 12 月 5 日
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.

採用された回答

the cyclist
the cyclist 2017 年 12 月 3 日
A quick search found this answer, which suggest that sym2poly and roots will do what you want.
  1 件のコメント
Marcos Hermosilla
Marcos Hermosilla 2017 年 12 月 3 日
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.

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

その他の回答 (1 件)

Karan Gill
Karan Gill 2017 年 12 月 5 日
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

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by