优化计算MATLAB程序
首先,将目标函数写成M文件,其程序语句如下;
function f = fun (x)
global K L thetamax alpha
for i=1:61
f = 0
betae = atan(tan(alpha(i)/(1-(K/L)*tan(alpha(i))));
A(i)=2*x(1).^2*sin(x(2)+alpha(i));
B(i)=2*K*x(1)-2*x(1).^2*cos(x(2)+alpha(i));
C(i)=2*x(1).^2-4*x(1).^2*(cos(x(2)).^2+4*K*x(1)*cos(x(2))-2*K*x(1)* cos(x(2)+alpha(i));
theta3(i)= 2*acot((A(i)+sqrt(A(i).^2+B(i).^2-C(i).^2))/(B(i)+C(i))); beta(i)=x(2)+theta3(i)-pi;
if alpha(i)<=pi/18
f(i)=1.5*abs(beta(i)-betae3(i));
elseif alpha>=pi/18,alpha(i)<=pi/9;f(i)=abs(betaa(i)-betae3(i));
elsef(i)=0.5*abs(beta(i)-betae3(i));
global K L thetamax alpha
K=input
L=input
thetamax=input
x0(1)=input