Why is this not working
2 次查看(过去 30 天)
显示 更早的评论
Trying to solve 9 equtions 9 unknowns.
function [F] = MyFunc(x);
F = zeros(9,1);
x0 = [200, 150, 100, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5];
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);
x = fsolve(@MyFunc,x0);
end
0 个评论
采纳的回答
Star Strider
2020-3-11
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
0 个评论
更多回答(1 个)
Alex Sha
2020-3-14
There are another five more solutions:
No. x1 x2 x3 x4 x5 x6 x7 x8 x9
1 300 200 200 0 0.0447213595499958 -0.0447213595499958 3.07555837662612E-68 0.0447213595499958 -0.0447213595499958
2 300 200 200 0 -0.0447213595499958 0.0447213595499958 1.27131391300829E-57 -0.0447213595499958 0.0447213595499958
3 299.975612730155 206.230947445434 193.744665284721 -0.000698387712451196 0.0433000381719742 -0.046093589021779 0.0223484067984383 -0.0460935890217791 0.0433000381719743
4 299.975612730155 206.230947445434 193.744665284721 0.000698387712451196 -0.0433000381719742 0.046093589021779 -0.0223484067984383 0.0460935890217791 -0.0433000381719743
5 277.777777777778 188.888888888889 188.888888888889 -0.0210818510677892 -0.0421637021355784 -0.0421637021355784 4.53008323503054E-19 -0.0421637021355784 -0.0421637021355784
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!