How to apply sum function for simulating charges around a circle?
1 次查看(过去 30 天)
显示 更早的评论
I'm trying to model electric potential energy of protons arranged in a circle, graphically is(the next plot was made manually in geogebra 3d),
For
:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/543646/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/543651/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/543656/image.jpeg)
Asumming k=1, q1=1, q2=2 , mathematically can been described as:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/543661/image.png)
The thing is that i want to generalize this into a summation function in matlab for n charges separated in the circle, mathematically it will be:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/543666/image.png)
I try the next code, but it doesn't work. Any suggestions? I can't understand how the sum function works exactly:
[x,y,t]=meshgrid(-15:0.5:15,-15:0.5:15, 0:pi/8:pi/2);
r=5;
z=sum(1./sqrt((x-r*cos(t)).^2+(y-r*sin(t).^2)), 3);
surf(x(:,:,1),y(:,:,1),z);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/543671/image.png)
0 个评论
回答(2 个)
Matt J
2021-3-9
编辑:Matt J
2021-3-9
xs=linspace(0,10,500);
[x,y,t]=meshgrid(xs,xs, 0:pi/8:pi/2);
r=5;
z=sum(1./ ( (x-r*cos(t)).^2 + (y-r*sin(t)).^2 ), 3);
surf(x(:,:,1),y(:,:,1),z,'EdgeColor','none','FaceAlpha',0.3,'FaceColor','g');
6 个评论
Matt J
2021-3-9
编辑:Matt J
2021-3-9
Is the same r being used in the geogebra drawing? Also, you've presented different versions of your equations in different places, some with sqrt()'s and some without. Including or removing sqrt would affect the sharpness of the peaks.
Here's what we get with r=1 and including the sqrt():
r=1;
xs=linspace(0,1.5*r,500);
[y,x,t]=ndgrid(xs,xs, 0:pi/8:pi/2);
z=sum(1./ sqrt( (x-r*cos(t)).^2 + (y-r*sin(t)).^2 ), 3);
surf(x(:,:,1),y(:,:,1),z,'EdgeColor','none','FaceAlpha',0.3);
zlim([0,30]); view([-45,30])
axis vis3d
grid off
Walter Roberson
2021-3-9
I showed the strategy in https://www.mathworks.com/matlabcentral/answers/766426-how-can-i-handle-division-by-zero-inside-the-symsum-function#answer_642441
It would only take a small modification to the z = formula I showed there.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!