How can i select correct initial points to use fsolve effectively?
조회 수: 12 (최근 30일)
이전 댓글 표시
Hi,
I try to solve 3 nonlinear equations and use fsolve. Solution may change because of selection of initial points. Additionally, some initial points may cause the command not to work.
To fix these problems, how can i configure my equations correctly?
Thanks,
clear all
clc
fcn = @(x) [(153*cos(1/10))/41 - (1530*atan(x(1)/x(3) - (329*x(2))/(250*x(3))))/41 + (2*sin(1/10))/41 - x(2)*x(3) - (1530*atan(x(1)/x(3) + (371*x(2))/(250*x(3)))*cos(1/10))/41; (151011*atan(x(1)/x(3) - (329*x(2))/(250*x(3))))/2665 + (1113*sin(1/10))/13325 - (3*cos(1/10)*(113526*atan(x(1)/x(3) + (371*x(2))/(250*x(3))) - 56763/5))/5330; (2*cos(1/10))/41 - (153*sin(1/10))/41 + x(1)*x(2) - (21*x(3)^2)/82000 + (1530*atan(x(1)/x(3) + (371*x(2))/(250*x(3)))*sin(1/10))/41 - 265340743084671/1803199069552640]
x0 = [-5,-5,10];
S = fsolve(fcn, x0)
댓글 수: 2
Walter Roberson
2020년 12월 7일
Is the question how to code fsolve to give you back all of the solutions, or is the question how to code fsolve to return one particular solution that you will "think" towards it, or is the question how to get fsolve to search around until it finds the solution with the smallest L2 norm from x0?
답변 (1개)
John D'Errico
2020년 12월 7일
편집: John D'Errico
2020년 12월 7일
You cannot magically fix this.
I have often used the comparison that any nonlinear numerical optimization routine is comparable to setting a blind man down on the face of the earth, and asking him to find the spot lowest in elevation. And this fellow is allowed to use only a cane, to determine the local gradient of the surface. (I'll allow him to carry scuba gear in his journey.)
Do you think, if I set him down in some random spot on the earth to start his search, he will find a spot in the bottom of the Marianas trench in the Pacific ocean? If you do, then you may be a bit of an optimist. (No visually challenged individuals were harmed in this thought experiment.)
And that was just a 2-dimensional problem. Your problem lives in 3 dimensions. As you move up in dimension, problems ALWAYS become more complicated. And most nonlinear problems have multiple solutions. (There is a simple correspondence between minimization and nonlinear rootfinding.)
So wanting a numerical optimizer to find always the solution you want it to find is a bit, well, I'll call it wildly optimistic.
Asking how to choose "correct" points is just silly. Sorry, but it is. No better than asking how to somehow know the best place to set my blind person down on the earth to solve his task, while lacking any detailed knowledge of geography. Do you really expect a good solution to arise in that case?
The point being, when you change the starting point, fsolve can sometimes get stuck. For example, put our poor blind searcher down in the vicinity of the Dead Sea, and while he will find a low spot that is under water, it will not get him into the Pacific ocean. He will get stuck. And there are various ways he can get into trouble, just as there are various ways a solver like fsolve can get into trouble. Start in a bad place, expect garbage for a result.
The point is, if you want a good solution, then you need to provide intelligent starting values. Or else, accept what you get, and if you are unhappy with that result, then choose better starting values next time. Multi-start methods do exactly that. You start from various locations, hoping that one of the solutions returned will make you happy.
But I am sorry. There is no magical way to automatically choose the "correct" starting values. (Again, remember that even though I described this problem in terms of a minimization, that there is a simple direct correspondence between rootfinding and minimization.) For low dimensional problems, there are graphical methods that can help you to find intelligent starting value choices. But even they are not infallible. I can always give you a problem that will cause any such method to fail.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!