First, it appears that you are trying to solve it inside the functions, and that won’t work.
Second, this:
F(9) = 0.01*x(6) + 0.04*x(7) - 0.01*X(9);
↑ ← HERE
MATLAB is case-sensitive, so ‘x’ and ‘X’ are different.
This works:
function [F] = MyFunc(x);
F = zeros(9,1);
F(1) = 300 - x(1) - 50000*x(4).^2;
F(2) = x(1) - x(2) - 50000*x(5).^2;
F(3) = x(1) - x(3) - 50000*x(6).^2;
F(4) = x(2) - x(3) - 25000*x(7).^2;
F(5) = x(2) - 100 - 50000*x(8).^2;
F(6) = x(3) - 100 - 50000*x(9).^2;
F(7) = 0.04*x(4) - 0.01*x(5) - 0.01*x(6);
F(8) = 0.01*x(5) - 0.01*x(8) - 0.04*x(7);
F(9) = 0.01*x(6) + 0.04*x(7) - 0.01*x(9);
end
x0 = [200, 150, 100, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5];
x = fsolve(@MyFunc,x0)'
and produces:
x =
277.777777777778
188.888888888889
188.888888888889
0.0210818510677892
0.0421637021355784
0.0421637021355784
2.57436435034422e-19
0.0421637021355784
0.0421637021355784
Best Answer