Problem with summation of a function

조회 수: 1(최근 30일)
Audrique Vertessen
Audrique Vertessen 2020년 4월 21일
답변: Tarunbir Gambhir 2021년 1월 28일
Here is my code:
D = 1;
w_eg = 1;
w_0 = 1;
syms k;
som = @(w)symsum(exp(-D).*D.^k.*kroneckerDelta(w - w_eg - k.*w_0)/factorial(k),k,0,100);
fplot(@(w)symsum(exp(-D).*D.^k.*kroneckerDelta(sym(w - w_eg - k.*w_0))/factorial(k),k,0,100),[0,100])
The parameters are there to change afterwords. The problem is i get wrong values, it seems like the kroneckerDelta or the summation is not working properly. I know that kroneckerDelta should get a sym as input but im not sure if i should then do
syms w - w_eg - k.*w_0;
since k is already in symbolic notation.


Tarunbir Gambhir
Tarunbir Gambhir 2021년 1월 28일
The summation is working correctly. The 'w - w_eg - k.*w_0' is a symbolic expression since it contains a symbolic variable. The reason why you are not getting the wrong values might be because of the 'Interval' and the 'MeshDensity' chosen for 'fplot'. Consider the following code for plotting your function:
D = 1;
w_eg = 1;
w_0 = 1;
syms k;
som = @(w) symsum(exp(-D).*D.^k.*kroneckerDelta(w - w_eg - k.*w_0)/factorial(k),k,0,100);
fplot(som,[0.1 10],'MeshDensity',100)
title('input values: 0.1000, 0.2000, 0.3000, 0.4000, 0.5000, 0.6000...')
fplot(som,[0 10],'MeshDensity',100)
title('input values: 0, 0.1010, 0.2020, 0.3030, 0.4040, 0.5051...')
It seems like the function being plotted is very sensitive to the input and thus to see the peaks you need to experiment with the 'Interval' and the 'MeshDensity'. I suggest you go through this section for more clarity.

Community Treasure Hunt

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

Start Hunting!

Translated by