MATLAB Answers

# How can i select correct initial points to use fsolve effectively?

13 views (last 30 days)
Volkan Yangin on 7 Dec 2020
Edited: John D'Errico on 7 Dec 2020
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 CommentsShowHide 1 older comment
Volkan Yangin on 7 Dec 2020
There may not be solution of these nonlinear set, i know. But when i change x0, fsolve gives different messages, i.e., "No solution found." or "Solver stopped prematurely." etc. My purpose is how to converge to zero by changing x0. I don't think that there is mistake about writing of code. To have one or more sets of S to make or converge zero, what kind of changes can be implemented? Or, can it be possible?

Sign in to comment.

### Answers (1)

John D'Errico on 7 Dec 2020
Edited: John D'Errico on 7 Dec 2020
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 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!

Translated by