Thomas
Thomas

Reputation: 11

creating a matlab code for Box evolutionary search method

Solve the following nonlinear system of equations in the interval 0 ≤ 𝑥, 𝑦 ≤ 5 by using the Box Evolutionary optimization algorithm. Take, the initial point 𝑋=(x,y)T=(1,1)T and size of reduction parameter delta=(2,2)T x^2+y=11 x+y^2=7 after running my code it is getting into infinite loop,can anyone help me out?

clc
clear
syms x y
e=1;
a=2;
f(x,y)=(x^2+y-11)^2;
g(x,y)=(x+y^2-7)^2;
k=1;
while(k~=0)
    d1=2;
    d2=2;
    D=(d1^2+d2^2)^(0.5);
    x0=1;
    y0=1;
    xb1=x0;
    xb2=y0;
    x1=xb1+d1/2;
    y1=xb2+d2/2;
    x2=xb1+d1/2;
    y2=xb2-d2/2;
    x3=xb1-d1/2;
    y3=xb2+d2/2;
    x4=xb1-d1/2;
    y4=xb2-d2/2;
    f1=f(x1,y1)+g(x1,y1);
    f2=f(x2,y2)+g(x2,y2);
    f3=f(x3,y3)+g(x3,y3);
    f4=f(x4,y4)+g(x4,y4);
    if f1<f2 && f1<f3 && f1<f4
        xb1=x1;
        xb2=y1;
    elseif f2<f1 && f2<f3 && f2<f4
        xb1=x2;
        xb2=y2;
    elseif f3<f1 && f3<f2 && f3<f4
        xb1=x3;
        xb2=y3;
    elseif f4<f1 && f4<f2 && f4<f3
        xb1=x4;
        xb2=y4;
    end
    if xb1==x0 && xb2==y0
        d1=d1/a;
        d2=d2/a;
        if D<e
            disp("x value is")
            disp(xb1)
            k=0;
            break
        end
    else 
        x0=xb1;
        y0=xb2;
    end  
end

        

i am using k as condition for while loop

Upvotes: 1

Views: 195

Answers (0)

Related Questions