Implementation of infinite series in MATLAB.
26 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sudhir Sahoo
el 11 de Feb. de 2021
Comentada: Walter Roberson
el 18 de Sept. de 2022
How I can impliment this type of infinite series in MATLAB given a function as
where
, here l,\gamma are constant. when I use
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/516292/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/516297/image.png)
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 comentarios
Walter Roberson
el 11 de Feb. de 2021
The error is not in the part of the code that you posted. We need to see the rest of the code.
Respuesta aceptada
Walter Roberson
el 13 de Feb. de 2021
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
double(expression2)
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
0 comentarios
Más respuestas (1)
Sahil
el 18 de Sept. de 2022
Editada: Walter Roberson
el 18 de Sept. de 2022
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 comentario
Walter Roberson
el 18 de Sept. de 2022
What is the difference between that and what I posted last year at https://www.mathworks.com/matlabcentral/answers/742277-implementation-of-infinite-series-in-matlab#answer_622427 ?
Ver también
Categorías
Más información sobre Calculus en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!