[1d粒子模拟] field plot

2021/12/10 23:18:23

本文主要是介绍[1d粒子模拟] field plot,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

%
% Field plot (Ex,Ey,Ez,By,Bz)
%     xlabel('X');
%     str = {'Ex','Ey','Ez','By','By'};
%     ylabel(str(n))
%
function hdiag = plotfield(hdiag, n, jdiag)
  global prm ren
  global nxp2
  global X1 X2 X2

  global ex ey ez
  global by bz
  global bx0 by0
  
  switch n
   case 1
    f = ex*ren.e;
    m = prm.emax;
   case 2
    f = ey*ren.e;
    m = prm.emax;
   case 3
    f = ez*ren.e;
    m = prm.emax;
   case 4
    f = (by-by0)*ren.b;
    m = prm.bmax;
   case 5
    f = bz*ren.b;
    m = prm.bmax;
  end

  if jdiag == 1
    xx = 0:prm.dx:(prm.nx-1)*ren.x;
    hdiag.plt(hdiag.nplt).hplot(n) = plot(xx, f(X2),'k-','LineWidth',2);
    
    csvwrite('xx_init.csv',xx)
    switch n
        case 1
          csvwrite('Ex.csv',f(X2)');
        case 2
          csvwrite('Ey.csv',f(X2)');
        case 3
          csvwrite('Ez.csv',f(X2)');
        case 4
          csvwrite('By.csv',f(X2)');
        case 5
          csvwrite('Bz.csv',f(X2)');
    end
   
    if m > 0 
      axis([0 (prm.nx-1)*ren.x  -m m]);
    else
      set(gca,'xlim',[0 (prm.nx-1)*ren.x]);
    end
    xlabel('X');
    str = {'Ex','Ey','Ez','By','By'};
    ylabel(str(n))
  else
    %set(hdiag.plt(hdiag.nplt).hplot(n),'ydata',f(X2))  %加快计算速度
    switch n
        case 1
          dlmwrite('Ex.csv',f(X2)','delimiter',',','-append');
        case 2
          dlmwrite('Ey.csv',f(X2)','delimiter',',','-append');
        case 3
          dlmwrite('Ez.csv',f(X2)','delimiter',',','-append');
        case 4
          dlmwrite('By.csv',f(X2)','delimiter',',','-append');
        case 5
          dlmwrite('Bz.csv',f(X2)','delimiter',',','-append');
    end
  end
    
return



这篇关于[1d粒子模拟] field plot的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程