필터 지우기
필터 지우기

Implementation of infinite series in MATLAB.

조회 수: 31 (최근 30일)
Sudhir Sahoo
Sudhir Sahoo 2021년 2월 11일
댓글: Walter Roberson 2022년 9월 18일
How I can impliment this type of infinite series in MATLAB given a function as where , here l,\gamma are constant. when I use
syms k;
exp = symsum(H(k + 1,gamma_av),k,1,Inf);
I used to get error like this "The following error occurred converting from sym to double:
Unable to convert expression into double array."
Please help me out.
  댓글 수: 5
Walter Roberson
Walter Roberson 2021년 2월 11일
The error is not in the part of the code that you posted. We need to see the rest of the code.
Sudhir Sahoo
Sudhir Sahoo 2021년 2월 12일
@Walter Roberson Ok sir I am posting the code as follows
syms k;
snr = 2;
l = 2;
expression2 = symsum(H(k + 1,snr,l),k,1,Inf);
and my function i defined as
function [out] = H(y,z,l)
%gam, y,z,l are user inputs
m = -1/log2(cos(pi/6)); % in paper its used as small gamma.(\gamma)
out1 = (2/z)^y;
out2 = gamma(y) - igamma(y,(l^(-2*(m + 2))/2)*z);
out = out1 * out2;
end
And I want to calculate the sum

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 2월 13일
The error message you get is because the symbolic engine was not able to find a convergent value for the infinite series when you use double(). And depending on the number of digits you use for vpa() it might or might not find a solution.
Interestingly, if you use a finite series such as 75 terms, then double() does well at converting the value, whereas you need on the order of 150+ digits in order for vpa to be able to resolve it: if you use a high finite Limit and too few digits then vpa() will tend to return exactly 0.
format long g
syms k;
snr = 2;
l = 2;
Limit = Inf;
expression2 = symsum(H(k + 1,snr,l),k,1,Limit);
for D = 120:129
try
D
ev = vpa(expression2, D)
ed = double(ev)
catch ME
fprintf('failed working at %d digits\n', D);
end
end
D =
120
ev = 
failed working at 120 digits
D =
121
ev = 
0.000000003077984867743638419940134683770443072429756599385419397056352496391763650277668849759282913432606221931130564797576520443
ed =
3.07798486774364e-09
D =
122
ev = 
0.0000000030779848677436384199401346837704430724297565993854193970563524963917636502776688497592829134326062219311305647975746247394
ed =
3.07798486774364e-09
D =
123
ev = 
0.00000000307798486774363841994013468377044307242975659938541939705635249639176365027766884975928291343260622193113056479757456758764
ed =
3.07798486774364e-09
D =
124
ev = 
0.000000003077984867743638419940134683770443072429756599385419397056352496391763650277668849759282913432606221931130564797574605713361
ed =
3.07798486774364e-09
D =
125
ev = 
failed working at 125 digits
D =
126
ev = 
0.00000000307798486774363841994013468377044307242975659938541939705635249639176365027766884975928291343260622193113056479757460092717886
ed =
3.07798486774364e-09
D =
127
ev = 
0.000000003077984867743638419940134683770443072429756599385419397056352496391763650277668849759282913432606221931130564797574600914952293
ed =
3.07798486774364e-09
D =
128
ev = 
failed working at 128 digits
D =
129
ev = 
0.00000000307798486774363841994013468377044307242975659938541939705635249639176365027766884975928291343260622193113056479757460091191697691
ed =
3.07798486774364e-09
double(expression2)
Error using symengine
Unable to convert expression containing remaining symbolic function calls into double array. Argument must be expression that evaluates to number.

Error in sym/double (line 702)
Xstr = mupadmex('symobj::double', S.s, 0);
function [out] = H(y,z,l)
Pi = sym(pi);
%gam, y,z,l are user inputs
m = -1/log2(cos(Pi/6)); % in paper its used as small gamma.(\gamma)
out1 = (2/z)^y;
out2 = gamma(y) - igamma(y,(l^(-2*(m + 2))/2)*z);
out = out1 * out2;
end

추가 답변 (1개)

Sahil
Sahil 2022년 9월 18일
편집: Walter Roberson 2022년 9월 18일
function [out] = H(y,z,l)
Pi = sym(pi);
%gam, y,z,l are user inputs
m = -1/log2(cos(Pi/6));
% in paper its used as small gamma.(\gamma)
out1 = (2/z)^y;
out2 = gamma(y) - igamma(y,(l^(-2*(m + 2))/2)*z);
out = out1 * out2;
end

카테고리

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