trying to solve two non-linear simultaneous equations but I had an error figuring out my two unknowns (X(1) &x(2)) , can anyone pls help?

조회 수: 3 (최근 30일)

답변 (3개)

Star Strider
Star Strider 2023년 5월 9일
I cannot fun images of code, only code in text format. I can’t even see all of ‘F’.
The problem is the choice of initial conditions for ‘x0’.
Using:
x0 = rand(2,1);
will probably work. At least it won’t throw that same error.
.

Torsten
Torsten 2023년 5월 9일
편집: Torsten 2023년 5월 9일
Maybe you divide somewhere by x(1) or x(2) in the definition of your function F (which would result in a division-by-zero in the F-evaluation at the start).
Change your initial value vector x0.

John D'Errico
John D'Errico 2023년 5월 9일
편집: John D'Errico 2023년 5월 9일
ARGH. Why would you post a picture of your code? And at that, only a partial picture? Even if I try to show why your code fails, I cannot, since I cannot even see the entire function.
It is just as easy to paste in the code itself, as it is to insert a picture. In fact, it is easier. So why would you make it more difficult to get help? So at best, ll I can do is guess at the problem. Fsolve says you have an undefined result. I would postilate it has seen a NaN, and is upset at the idea, since it can do nothing then.
And that suggest the odds are good that your problem is in your starting values. NEVER start an optimizer at the point [0,0]. It can do all sorts of bad things. But here, my bet is the problem is more in that at the point [0,0], your function is itself undefined. It may well be generating NaNs.
My advice when you run an optimization is to first, TEST the function. Try evaluating it at the start point. Does it make sense? If not, then what will the optimizer do? Computers tend to be pretty dumb things. Then, evaluate the objective at another point. Does the objective return a different value? If not, then again you have a problem.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by