poles & residues: partial fraction decomposition (partfrac) followed by use of residue matlab function
조회 수: 8 (최근 30일)
이전 댓글 표시
Dear all,
I am trying to extract the simple poles and residues of a @-function (that I define externally) by using a partial fraction decomposition in matlab (by partfrac). This works perfect for an already non-trivial choice of parameters. However, if I want to go to the range of parameters that I'm interested in, the coefficients of the partial fraction decomposition (i.e. coefficients multiplying the powers of x, where x is the dummy variable) become incredibly large, until they get outside the range of the matlab-double type, and become Inf. I don't understand how one could impose matlab to simplify the expression as to not get into above sketched problem. It seems matlab doesn't try to simplify the fraction at all. I appreciate any input.
Thank you,
Bogdan
P.S. Here is a snippet of the code:
if true
for l=1:N_Lorentz;
par1 = eps_fit(l);
par4 = W_fit(l);
fprintf('present interation in loop over N_L: %d',l);
syms x;
fctloop=@(x)fct_lorentzian_ortho(x,par1,par4,inc,N_Lorentz,en_min,en_max,discretiz_energ);
[Num,Den] = numden( simplify(partfrac(fctloop,x)) )
help1 = sym2poly(Num)
help2 = sym2poly(Den)
[res,pol,koe] = residue(help1,help2)
size(res)
size(pol)
size(koe)
Residues(1+2*(l-1)*N_Lorentz:2*N_Lorentz+2*(l-1)*N_Lorentz) =
res(1:2*N_Lorentz);
Vect_poles(1+2*(l-1)*N_Lorentz:2*N_Lorentz+2*(l-1)*N_Lorentz) = pol(1:2*N_Lorentz);
end
end
댓글 수: 0
답변 (1개)
Shishir Reddy
2025년 5월 28일
Hi Bogdan
As per my understanding you are encountering numerical overflows when converting symbolic expressions to numeric form using 'sym2poly', especially after using ‘partfrac’.
When ‘partfrac’ is applied to a symbolic function and then coefficients are extracted using ‘sym2poly’, it is essentially bridging the symbolic and numeric domains. If the symbolic expression has large or complex coefficients (possibly due to parameter values), ‘sym2poly’ can produce very large numbers that overflow MATLAB's double-precision limit, resulting in ‘Inf’.
Kindly refer the following workarounds to avoid ‘Inf’ values and very large coefficients.
1. Use ‘simplifyFraction’ before ‘partfrac’
This function simplifies the symbolic rational expression before decomposition, which often reduces coefficient sizes.
fct_simplified = simplifyFraction(fctloop(x));
[Num, Den] = numden(partfrac(fct_simplified));
2. Use variable precision arithmetic (vpa)
This function increases precision.
Num_vpa = vpa(Num, 50);
Den_vpa = vpa(Den, 50);
help1 = double(sym2poly(Num_vpa));
help2 = double(sym2poly(Den_vpa));
[res, pol, koe] = residue(help1, help2);
For more information regarding ‘simplifyFraction’ and ‘vpa’ functions, kindly refer the following documentations –
I hope this helps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!