Demo entry 6734623

kr_ki

   

Submitted by Hongchen Li on Apr 21, 2018 at 04:58
Language: Matlab. Code size: 1.6 kB.

Taylor=zeros(5,6);                                                          %生成泰勒展开系数的矩阵
Taylor(1,:)=[1 1 1 1 1 1];
Taylor(2,:)=[-3 -2 -1 0 1 2];
for line=3:1:5
    for column=1:1:6
        Taylor(line,column)=Taylor(2,column)^(line-1)/factorial(line-1);
    end
end
c=[0 1 0 0 0]';                                                             %除了u的一阶导数为1,其它阶导数均为零
Aa=(Taylor(:,6));                                                           %把自由参数b1所乘的列向量挑出来,方便后面减到等号右边
Am=(Taylor(:,1:5));
b=zeros(6,1);                                                               %生成待求向量b
test=zeros(1,601);
record=0;
for p=-300:1:300                                                            %该循环为优化部分,p=-300:1:300 是为了使数组 test() 括号里面是正整数,否则会报错
    b(1:5)=Am\(c-p/100*Aa);
    q=0;
    while abs(-b(1)*sin(3*q)+(-b(2)+p/100)*sin(2*q)+(-b(3)+b(5))*sin(q)-q)<0.05;  %优化条件
        q=q+0.01;
    end
    test(p+301)=q;
    if q>record
        record=q;
        b_star=p/100;
    end
end
b(6)=b_star;                                                                %得到最优值
b(1:5)=Am\(c-b(6)*Aa);                                                      %优化系数
alpha=0:0.05:pi;                                                            %绘图区间[0,pi]
kr=b(1)*cos(3*alpha)+(b(2)+b(6))*cos(2*alpha)+(b(3)+b(5))*cos(alpha)+b(4);  %耗散误差
ki=-b(1)*sin(3*alpha)+(-b(2)+b(6))*sin(2*alpha)+(-b(3)+b(5))*sin(alpha);    %色散误差
%%画出kr,ki随有效波数变化的关系曲线
figure(1);
plot(alpha,alpha,'b-',alpha,kr,'r-');legend('alpha','kr');title('kr曲线');
figure(2);
plot(alpha,alpha,'b-',alpha,ki,'r-');legend('alpha','ki');title('ki曲线');
 

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).