⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 run.m

📁 解决麦克斯韦的matlab源文件
💻 M
字号:
function run(datapath,prb,scal)% MATLAB-Script running the numerical experiments for% the transient Maxwell's equations in a cavityif (nargin < 1), datapath = './'; endif (nargin < 2), prb = -1; endif (nargin < 3), scal = 0.5; endfinaltime = 3; timestep = 0.01;disp('MATLAB based numerical experiments for transient Maxwell equations');disp('Goal is the comparison of nodal and edge element discretizations');disp('Further explanations are furnished in the accompanying readme.tex');fprintf('Path for output files %s\n',datapath);fprintf('Relative scaling of C and R: %d <-> %d\n',2*scal,2*(1-scal));disp('Results can be viewed using replay.m');load('meshes.mat');drawmesh(Square0,'Square0');[en,solv,sole,times] = leapfrog(Square0,'initSq',timestep,finaltime,2,scal);fprintf('Finished on Square0: Results stored in %s',[datapath,'Square0_res']);save([datapath,'Square0_res'],'en','solv','sole','times');figure; clf;subplot(1,2,1);plot(en(:,1),en(:,2),'r-',en(:,1),en(:,4),'b-');legend('Nodal scheme','Edge elements');title('Square0: Electric energy');xlabel('time');subplot(1,2,2);plot(en(:,1),en(:,3),'r-',en(:,1),en(:,5),'b-');legend('Nodal scheme','Edge elements');title('Square0: Magnetic energy');xlabel('time');drawnow;clear en solv sole times;drawmesh(Lshape0,'Lshape0');[en,solv,sole,times] = leapfrog(Lshape0,'initL',timestep,finaltime,2,scal);fprintf('Finished on Lshape0: Results stored in %s',[datapath,'Lshape0_res']);save([datapath,'Lshape0_res'],'en','solv','sole','times');figure; clf;subplot(1,2,1);plot(en(:,1),en(:,2),'r-',en(:,1),en(:,4),'b-');legend('Nodal scheme','Edge elements');title('Lshape0: Electric energy');xlabel('time');subplot(1,2,2);plot(en(:,1),en(:,3),'r-',en(:,1),en(:,5),'b-');legend('Nodal scheme','Edge elements');title('Lshape0: Magnetic energy');xlabel('time');drawnow;clear en solv sole times;drawmesh(Square1,'Square1');[en,solv,sole,times] = leapfrog(Square1,'initSq',0.25*timestep,finaltime,8,scal);fprintf('Finished on Square1: Results stored in %s',[datapath,'Square1_res']);save([datapath,'Square1_res'],'en','solv','sole','times');figure; clf;subplot(1,2,1);plot(en(:,1),en(:,2),'r-',en(:,1),en(:,4),'b-');legend('Nodal scheme','Edge elements');title('Square1: Electric energy');xlabel('time');subplot(1,2,2);plot(en(:,1),en(:,3),'r-',en(:,1),en(:,5),'b-');legend('Nodal scheme','Edge elements');title('Square1: Magnetic energy');xlabel('time');drawnow;clear en solv sole times;drawmesh(Lshape1,'Lshape1');[en,solv,sole,times] = leapfrog(Lshape1,'initL',0.25*timestep,finaltime,8,scal);fprintf('Finished on Lshape1: Results stored in %s',[datapath,'Lshape1_res']);save([datapath,'Lshape1_res'],'en','solv','sole','times');figure; clf;subplot(1,2,1);plot(en(:,1),en(:,2),'r-',en(:,1),en(:,4),'b-');legend('Nodal scheme','Edge elements');title('Lshape1: Electric energy');xlabel('time');subplot(1,2,2);plot(en(:,1),en(:,3),'r-',en(:,1),en(:,5),'b-');legend('Nodal scheme','Edge elements');title('Lshape1: Magnetic energy');xlabel('time');drawnow;clear en solv sole times;drawmesh(Square2,'Square2');[en,solv,sole,times] = leapfrog(Square2,'initSq',timestep/16,finaltime,32,scal);fprintf('Finished on Square2: Results stored in %s',[datapath,'Square2_res']);save([datapath,'Square2_res'],'en','solv','sole','times');figure; clf;subplot(1,2,1);plot(en(:,1),en(:,2),'r-',en(:,1),en(:,4),'b-');legend('Nodal scheme','Edge elements');title('Square2: Electric energy');xlabel('time');subplot(1,2,2);plot(en(:,1),en(:,3),'r-',en(:,1),en(:,5),'b-');legend('Nodal scheme','Edge elements');title('Square2: Magnetic energy');xlabel('time');drawnow;clear en solv sole times;drawmesh(Lshape2,'Lshape2');[en,solv,sole,times] = leapfrog(Lshape2,'initL',timestep/16,finaltime,32,scal);fprintf('Finished on Lshape2: Results stored in %s',[datapath,'Lshape2_res']);save([datapath,'Lshape2_res'],'en','solv','sole','times');figure; clf;subplot(1,2,1);plot(en(:,1),en(:,2),'r-',en(:,1),en(:,4),'b-');legend('Nodal scheme','Edge elements');title('Lshape2: Electric energy');xlabel('time');subplot(1,2,2);plot(en(:,1),en(:,3),'r-',en(:,1),en(:,5),'b-');legend('Nodal scheme','Edge elements');title('Lshape2: Magnetic energy');xlabel('time');drawnow;clear en solv sole times;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -