Problem with summation of a function

1 次查看(过去 30 天)
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.

回答(1 个)

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);
subplot(2,1,1)
fplot(som,[0.1 10],'MeshDensity',100)
title('input values: 0.1000, 0.2000, 0.3000, 0.4000, 0.5000, 0.6000...')
subplot(2,1,2)
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.

类别

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