MATLAB: Find optimized x1, x2, x3 for a given y.

genetic algorithmmatlab functionoptimization

Hi,
I have a function like below:
y=x1^2+2*x1*x2+x3^2;
I want to find the values for x1, x2 and x3 for y=2.
How can I do that? I tried with genetic algorithm using 'ga' function but looks like that's not the right one. Can anyone please help me how should I approach or is there any built in function to get that? Thanks in advance.

Best Answer

y = 2;
fun = @(x) (x(1).^2 + 2.*x(1).*x(2) + x(3).^2 - y).^2
bestx = ga(fun, 3);
x1 = bestx(1); x2 = bestx(2); x3 = bestx(3);
Note: there are an infinite number of solutions. It does not start to get interesting until you put on constraints.