自再现模的迭代法的Matlab代码

垂雷大学激光工程的作业,网上找了一下百度文库有篇相关的文章,不过里面的代码写的不太规范(命名啊,空格啊),就按照自己的习惯改了改,再说百度文库也不好复制粘贴,就放在这里吧。万一有人用得着呢?

(一个课程的同学别抄啊)

% 注:QU渡越函数在提交的同一目录下,缺少这个函数无法运行
clear
clc

global steps cavity_length waveloss mirror_long wavalength

% 定义各种参数的初始值
wavalength  = 0.0000006328; %波长
cavity_length = 0.00006328; %腔长
mirror_long = 0.00001582; %镜长
N = 300; %渡越次数
waveloss = 2*pi/wavalength; %波失
steps = 500; %步长


% 声明变量的空间
x = linspace(-mirror_long, mirror_long, steps);
uN = ones(1,steps);
u1 = ones(1,steps);
u_n = ones(1,steps);

% 经过1次渡越
for i = 1:steps

    u1(i) = QU(x(i),u_n);

end
u_n1 = u1/max(abs(u1));

% 经过N次渡越
for i = 1:N

    for j = 1:steps

        uN(j) = QU(x(j),u_n);

    end

    u_n= uN/max(abs(uN));

end

% 做图,振幅
subplot(2,1,1)
grid on
plot(x,abs(uN)/abs(uN(steps/2)), 'b--')
hold on
plot(x,abs(u1)/abs(u1(steps/2)),'r')
title('振幅');xlabel('振幅分布');ylabel('相对振幅');

angle_uN=angle(uN)/pi*180;
angle_u1=angle(u1)/pi*180;
angle_uN=angle_uN-angle_uN(steps/2);
angle_u1=angle_u1-angle_u1(steps/2);

%做图,相位
subplot(2,1,2)
grid on
plot(x,angle_uN, 'b--')
hold on
plot(x,angle_u1, 'r')
title('相位');xlabel('相位分布');ylabel('相对相位');

QU 函数的代码(文件名为QU.m ,跟上面的代码放在一起就好)

function y=QU(x,u)

global steps cavity_length waveloss mirror_long wavalength

x_=linspace(-mirror_long,mirror_long,steps);

step_length=2*mirror_long/(steps-1);

y=sqrt(1i/cavity_length/wavalength*exp(-1i*waveloss*cavity_length))*sum(exp(-1i*waveloss/2/cavity_length*(-x_+x).^2).*u)*step_length;
    ```yml _config.yml
    highlight:
      enable: true
      line_number: true
      auto_detect: false
      tab_replace: 
    markdown:
      render:
        html: true
        xhtmlOut: false
        breaks: false
        linkify: true
        typographer: true
        quotes: '“”‘’'
      plugins:
        - markdown-it-abbr
        - markdown-it-footnote
        - markdown-it-ins
        - markdown-it-sub
        - markdown-it-sup
        - markdown-it-deflist
      anchors:
        level: 1
        collisionSuffix: 'v'
        permalink: false
        permalinkClass: header-anchor
        permalinkSymbol: ""
        permalinkBefore: false
    date_format: ll
    archive_generator:
      per_page: 0
      yearly: true
      monthly: false
      daily: false
    theme: cutie
    ```

结果大概长这样~

结果.jpg