![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/502213/image.jpeg)
Problem with summation of a function
2 ビュー (過去 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.
0 件のコメント
回答 (1 件)
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...')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/502213/image.jpeg)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Number Theory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!