필터 지우기
필터 지우기

symbolic vector to usual vector.

조회 수: 2 (최근 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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by