# MATLAB: Getting this warning message: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments. How to fix this

vectorize

close all
clear
clc
fprintf('Solutions:\n————-\n')
XO = [1,1,1]'; % Initial guess 1
X = fsolve(@system,XO)
XO = [1,10,1]'; % Initial guess 2
X = fsolve(@system, XO)
% Plotting
figure, fimplicit3(@(x,y,z) 2*x.^2 – 4*x + y^2 + 3*z.^2 + 6*z + 2) % First Equation
xlabel('x'), ylabel('y'),zlabel('z'), title('First Equation')
figure, fimplicit3(@(x,y,z) x.^2 + y.^2 – 2*y + 2*z.^2 – 5) % Second Equation
xlabel('x'), ylabel('y'), zlabel('z'), title ('Second Equation')
figure, fimplicit3(@(x,y,z) 3*x.^2 – 12*x + y.^2 + 3*z.^2 + 8) % Third Equation
xlabel('x'), ylabel('y'), zlabel('z'), title ('Third Equation')
function F = system(X)
% X = [x y z]
F = [2*X(1)^2 – 4*X(1) + X(2)^2 + 3*X(3)^2 + 6*X(3) + 2;
X(1)^2 + X(2)^2 – 2*X(2) + 2*X(3)^2 – 5;
3*X(1)^2 – 12*X(1) + X(2)^2 + 3*X(3)^2 + 8];
end