diff --git a/姚安欣/fun2.m b/姚安欣/fun2.m new file mode 100644 index 0000000..7c77430 --- /dev/null +++ b/姚安欣/fun2.m @@ -0,0 +1,15 @@ +function f=fun2(x) +a=[1.25,8.75,0.5,5.75,3,7.25]; +b=[1.25,0.75,4.75,5,6.5,7.25]; + f1 = 0; % 初始化f1 + f2 = 0; % 初始化f2 +for i=1:6 + s=sqrt((a(i)-x(13))^2+(b(i)-x(14))^2); + f1=x(i)*s+f1; +end +for i=7:12 + s=sqrt((a(i-6)-x(15))^2+(b(i-6)-x(16))^2); + f2=s*x(i)+f2; +end +f=f1+f2; +end \ No newline at end of file