Can I solve a special system of implicit functions by using the command "fsolve"

4 views (last 30 days)
My system of implicit functions is as follows:
where C and D are known vectors, A is a sysmmetric matrix.
How can I write the corrected codes to solve the vector x.
Thank you very much.
My trial codes are
fun=@x() x -C-D/((x'*A*x)-0.5)
x0=0.05*ones(1,20)
x=fsolve(fun, x0)
But, it appears that
Warning: Trust-region-dogleg algorithm FSOLVE cannot handle non-square system; using Levenberg-Marquardt algorithm instead.
  2 Comments
Walter Roberson
Walter Roberson on 5 Jan 2019
I think the -0.5 has to do with matrix square root . However it suggests inversion because of the negative but then it is the denominator which would invert again . It would seem to make more sense to rewrite in numerator without the negative . II have to wonder if something is cut out of the image .
Are Mjaavatten
Are Mjaavatten on 5 Jan 2019
There are some typos in your code that causes it to crash, at least in my 2014b Matlab version. Here is a corrected version using random parameters that successfully finds a solution (in most cases) for the much smaller problem with two unknowns:
N = 2;
C = rand(N,1);
D = rand(N,1);
A = rand(N);
A = A'*A; % Make sure A is symmetric
fun = @(x) x-C-D*sqrt(x'*A*x);
x0=0.05*ones(N,1); % x0 should be column vector
x=fsolve(fun, x0);
Using random parameters I never found a solution for N > 3, which illustrates that solving a large system of nonlinear equations can be very tricky. For your system of 20 equations you will probably need a very good initial guess.
Good luck!

Sign in to comment.

Accepted Answer

Wan-Yi Chiu
Wan-Yi Chiu on 5 Jan 2019
Edited: Wan-Yi Chiu on 5 Jan 2019
Thanks for everyone.
I solve the problem.

More Answers (1)

John D'Errico
John D'Errico on 5 Jan 2019
Edited: John D'Errico on 5 Jan 2019
I think Walter misread things, or perhaps did not notice something important.. While the -.5 is a square root indication, the product X'*A*x is a SCALAR. So there is no matrix square root to worry about. That means we can freely rewrite it as:
(x - C)*sqrt(x'*A*x) == D
That might make things a bit safer, as long as A is not singular. And even if it is, we would still need to avoid the nullspace of A.
Can I write it in MATLAB?
A = rand(5); A = A + A';
C = rand(5,1);D= rand(5,1);
X = sym('X',[5,1]);
Xsol = solve((X - C)*sqrt(X'*A*X) == D)
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
> In solve (line 304)
Xsol =
struct with fields:
X1: [1×1 sym]
X2: [1×1 sym]
X3: [1×1 sym]
X4: [1×1 sym]
X5: [1×1 sym]
Xsol.X1
ans =
1.0450171038540518504055495386235
Xsol.X2
ans =
0.85132210237551594113241214282493
So vpasolve had absolutely no problems, not even a blink of a computational eyelid. Fsolve should do equally well.
fun = @(x) (x-C)*sqrt(x'*A*x) - D;
>> xfsol = fsolve(fun,rand(5,1))
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
xfsol =
1.04501710385406
0.851322102375523
0.462783315557349
0.876195096917408
0.204903935826943
Verification...
[xfsol,C + D/sqrt(xfsol'*A*xfsol)]
ans =
1.04501710385406 1.04501710385405
0.851322102375523 0.851322102375516
0.462783315557349 0.462783315557353
0.876195096917408 0.876195096917407
0.204903935826943 0.204903935826949
Easy peasy.

Community Treasure Hunt

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

Start Hunting!