Numerical Method to solve single function with multiple variables

30 ビュー (過去 30 日間)
Mohamed Hassan
Mohamed Hassan 2019 年 8 月 1 日
編集済み: Mohamed Hassan 2019 年 8 月 2 日
Hello,
I am trying to solve a single function that has two unknowns [e.g. f(x,y)], however most numerical methods I have seen require the system of equations to have the same number of functions as variables (to use Jacobian matrix). I wanted to know if there was a numerical method(s) that can solve it (closet I found was gradient descent but not quite sure how to utilize or if it will work).
  2 件のコメント
James Tursa
James Tursa 2019 年 8 月 1 日
Please show more detail. What is the equation? Are you trying to minimize it? Or ...?
Mohamed Hassan
Mohamed Hassan 2019 年 8 月 2 日
編集済み: Mohamed Hassan 2019 年 8 月 2 日
alright so the function is:
f= sqrt((500*((x)^(1/3)-1))^2+(200*(1-(y)^(1/3)))^2)
I have an initial guess of where the answer might be, and looking at the gradient descent it seems it can solve it as long as it has the guess and the formula. I just wanted to know if this method works or something better.
Also, I understand if my question did not cover the problem I have or I did not convey enough information so please ask for more clarification if needed

サインインしてコメントする。

回答 (1 件)

John D'Errico
John D'Errico 2019 年 8 月 1 日
編集済み: John D'Errico 2019 年 8 月 1 日
What you do not understand is why it fails, and why a numerical method there has to fail. The simplest way to understand this is to pose a trivial problem. Thus
x + y == 1
You can't get much simpler, right? But, what is the solution? In fact, there are infinitely any solutions. We can write them as ordered pairs, of the form (x,1-x). Thus, pick any value of x, and you get a solution. But until you do so, there are infinitely many solutions, none any better than the rest.
It gets worse when you consider some general problem
f(x,y) == 0
I can arbitrarily set it to zero, since f(x,y) is a completely general relation. But here, for any value of x, there might be 0, 1, 2, 3, ... even infinitely many solutions. Again, pick a value for x or y, and a numerical solver MIGHT be able to find a solution. There might even be an analytical solution that solve could find. But an underdetermined problem (more unknowns than equations) will fail for a numerical solver.
If you want a mathematical description of the solution locus, I might call it a 1-manifold, embedded in a 2-dimensional cartesian space. In the first example, the locus of solutions form a line, infinitely many of them, extending to infinity in either direction. But a numerical solver does not understand a concept like that. It cannot.
The best thing you can do is to try to use a tool like solve, solving for one variable as a function of the other. Then you can write it in functional form. y = f(x) of x = g(y). And of course, most such general implicit functions will not have an analytical solution, no matter how hard you look.
You can use tools like fimplicit if your goal is simply to visualize the solution locus. It is surprisingly smart. As an example, consider this simple expression:
syms x y
EQ = x + sin(x+y) - exp(y) - 1;
fimplicit(EQ)
grid on
xlabel X
ylabel Y
I will conjecture that it might not have a trivial solution.
solve(EQ,x)
Warning: Unable to find explicit solution. For options, see help.
> In solve (line 317)
ans =
Empty sym: 0-by-1
>> solve(EQ,y)
Warning: Unable to find explicit solution. For options, see help.
> In solve (line 317)
ans =
Empty sym: 0-by-1
Solve found nothing. But if I pick any value for x (or y) I might find 1 or more solutions. A tool like fzero would suffice then.
eqfun = matlabFunction(EQ)
eqfun =
function_handle with value:
@(x,y)x+sin(x+y)-exp(y)-1.0
>> x0 = 1.5;
>> fzero(@(y) eqfun(x0,y),0)
ans =
0.37448
>> fzero(@(y) eqfun(x0,y),-2)
ans =
-1.8498
>> fzero(@(y) eqfun(x0,y),-5)
ans =
-4.1364
As you can see, it finds at least three distinct solutions. (Possibly more exist.) Remember that fzero is dependent on the starting value. But a numerical solver like fzero (or any other) simply does not understand the concept of what you might want it to do.

カテゴリ

Help Center および File ExchangeRobust Control Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by