fsolve no solution found system of two equations

7 views (last 30 days)
hello,
I have a strange problem when trying to solve a very simple system with fsolve:
--------------------
x0=[1e17 1e19]
[x,FVAL,EXITFLAG] = fsolve(@ nested_solver_straight_wg , x0,options);
function F = nested_solver_straight_wg(x)
C=5.4e-22;
D=1.53e-18;
A=8.88e-21;
B=5.84e-20;
ne = x(1) ;
pe = x(2);
F(1) = A*ne.^1.16+B*pe.^1.109-7.24;
F(2) = C*ne.^1.011+D*pe.^0.838-2.7687e-04;
end
----------------------
When i run what i get is:
No solution found.
fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
value of the function tolerance.
<stopping criteria details>
-------------------------
I tried changing tolerances but I wasn't able to proceed further.
I tried also to solve just the equation
F(1) = A*ne.^1.16+B*pe.^1.109-7.24;
with pe=7e17 but even in this very simple case the solver isn't able to find a solution (ne) which we know it must have one in the simple case of a single equation even with different starting point and tolerances.
What am I missing?

Accepted Answer

Torsten
Torsten on 27 Mar 2022
A=8.88e-21;
B=5.84e-20;
C=5.4e-22;
D=1.53e-18;
A=A*(1e18)^1.16
B=B*(1e19)^1.109
C=C*(1e18)^1.011
D=D*(1e19)^0.838
x1=linspace(0,(7.24/B)^(1/1.109),100)
x2=linspace(0,(2.7687e-4/D)^(1/0.838),100)
y1=((7.24-B*x1.^1.109)/A).^(1/1.16);
y2=((2.7687e-4-D*x2.^0.838)/C).^(1/1.011)
plot(x1,y1)
hold on
plot(x2,y2)
As you can see: The two equations don't have a point in common.

More Answers (1)

Matt J
Matt J on 27 Mar 2022
Your function is not differentiable for x(2)<0, so we must impose a lower bound to make it positive. But when we do that as below, the result is that x(2)=0. So, the solver probably thinks that an exact solution might lie at x(2)<0, but we cannot let it got there, because of non-differentiability.
s=[1e8;1e10];
x0=[5.8787e+17, 7e17];
tol=1e-15;
options=optimoptions('lsqnonlin','SpecifyObjectiveGradient',true,...
'StepTolerance',tol,'OptimalityTolerance',tol,'FunctionTolerance',tol,'Display','iter',...
'MaxFunEvals',1e5,'MaxIter',2e3);
[x,~,FVAL,EXITFLAG,out,~,Jf] = lsqnonlin(@(x) nested_solver_straight_wg(x,s) , x0,[-inf,0],[],options);
Norm of First-order Iteration Func-count f(x) step optimality 0 1 2.55317e+14 1.84e+14 1 2 2.55317e+14 10 1.84e+14 2 3 2.55317e+14 20 1.84e+14 3 4 2.55317e+14 40 1.84e+14 4 5 2.55317e+14 80 1.84e+14 5 6 2.55317e+14 160 1.84e+14 6 7 2.55317e+14 320 1.84e+14 7 8 2.55317e+14 640 1.84e+14 8 9 2.55316e+14 1280 1.83e+14 9 10 2.55315e+14 2560 1.83e+14 10 11 2.55313e+14 5120 1.82e+14 11 12 2.55308e+14 10240 1.8e+14 12 13 2.553e+14 20480 1.76e+14 13 14 2.55283e+14 40960 1.68e+14 14 15 2.55251e+14 81920 1.53e+14 15 16 2.55198e+14 163840 1.21e+14 16 17 2.55127e+14 327680 5.88e+13 17 18 2.55105e+14 308083 4.12e+10 18 19 2.55105e+14 655195 1.29e+07 19 20 2.55105e+14 1.31072e+06 4.18e+03 20 21 2.55105e+14 2.62087e+06 249 21 22 2.55105e+14 5.24288e+06 445 22 23 2.55105e+14 1.04857e+07 979 23 24 2.55105e+14 2.09713e+07 1.87e+03 24 25 2.55105e+14 4.19412e+07 3.79e+03 25 26 2.55105e+14 8.3871e+07 7.49e+03 26 27 2.55105e+14 1.67772e+08 1.51e+04 27 28 2.55105e+14 3.35544e+08 3e+04 28 29 2.55105e+14 6.71089e+08 6.02e+04 29 30 2.55105e+14 1.34218e+09 1.2e+05 30 31 2.55105e+14 2.68435e+09 2.41e+05 31 32 2.55105e+14 5.36871e+09 4.82e+05 32 33 2.55105e+14 1.07374e+10 9.63e+05 33 34 2.55105e+14 2.14748e+10 1.93e+06 34 35 2.55105e+14 4.29497e+10 3.85e+06 35 36 2.55105e+14 8.58993e+10 7.7e+06 36 37 2.55105e+14 1.71799e+11 1.54e+07 37 38 2.55105e+14 3.43597e+11 3.08e+07 38 39 2.55105e+14 6.87195e+11 6.17e+07 39 40 2.55104e+14 1.37439e+12 1.23e+08 40 41 2.55103e+14 2.74878e+12 2.47e+08 41 42 2.55101e+14 5.49756e+12 4.95e+08 42 43 2.55097e+14 1.09951e+13 9.94e+08 43 44 2.55088e+14 2.19902e+13 2e+09 44 45 2.55071e+14 4.39805e+13 4.07e+09 45 46 2.55037e+14 8.79609e+13 8.41e+09 46 47 2.54969e+14 1.75922e+14 1.78e+10 47 48 2.54832e+14 3.51844e+14 3.98e+10 48 49 2.54558e+14 7.03687e+14 9.62e+10 49 50 2.54011e+14 1.40737e+15 2.58e+11 50 51 2.52915e+14 2.81475e+15 7.78e+11 51 52 2.50717e+14 5.6295e+15 2.59e+12 52 53 2.50717e+14 14058.8 8.72e+08 53 54 2.46305e+14 1.1259e+16 9.12e+12 54 55 2.46304e+14 51399 3.57e+09 55 56 2.37413e+14 2.2518e+16 3.31e+13 56 57 2.37404e+14 200745 2e+10 57 58 2.19449e+14 4.5036e+16 1.17e+14 58 59 2.19321e+14 836897 1.79e+11 59 60 1.84274e+14 9.0072e+16 3.76e+14 60 61 1.82081e+14 3.9502e+06 2.46e+12 61 62 1.82081e+14 26181.7 1.25e+09 62 63 1.5537e+14 1.80144e+17 7.83e+14 63 64 1.03301e+14 2.90551e+07 4.87e+13 64 65 1.03067e+14 2.14393e+06 2.97e+11 65 66 1.03067e+14 1.80144e+17 2.97e+11 66 67 8.25926e+13 4.5036e+16 5.73e+13 67 68 8.17492e+13 5.2478e+06 9.6e+11 68 69 8.17489e+13 91550.4 2e+09 69 70 8.17489e+13 9.0072e+16 2e+09 70 71 7.06276e+13 2.2518e+16 1.55e+13 71 72 7.0492e+13 2.62091e+06 1.81e+11 72 73 7.0492e+13 31295 5.13e+08 73 74 5.09232e+13 4.5036e+16 1.46e+13 74 75 4.43874e+13 4.0075e+07 3.45e+12 75 76 4.34045e+13 2.21289e+07 7.25e+11 76 77 4.33221e+13 8.42888e+06 1.09e+11 77 78 4.33197e+13 1.6383e+06 1.05e+10 78 79 4.33197e+13 166504 8.61e+08 79 80 4.33197e+13 9.0072e+16 8.61e+08 80 81 4.33197e+13 2.2518e+16 8.61e+08 81 82 4.33197e+13 5.6295e+15 8.61e+08 82 83 4.18795e+13 1.40737e+15 1.77e+11 83 84 4.1848e+13 7.79595e+06 5e+10 84 85 4.18443e+13 3.07267e+06 1.4e+10 85 86 4.18439e+13 990328 3.87e+09 86 87 4.18439e+13 2.81475e+15 3.87e+09 87 88 4.08818e+13 7.03687e+14 7.71e+10 88 89 4.07878e+13 1.65372e+07 4.51e+10 89 90 4.06869e+13 1.6143e+07 1.82e+10 90 91 4.06864e+13 126902 1.8e+10 91 92 4.06862e+13 31725.6 1.79e+10 92 93 4.0686e+13 63451.2 1.79e+10 93 94 4.06854e+13 126902 1.77e+10 94 95 4.06844e+13 253805 1.74e+10 95 96 4.06822e+13 507610 1.67e+10 96 97 4.06779e+13 1.01522e+06 1.53e+10 97 98 4.06692e+13 2.03044e+06 1.25e+10 98 99 4.06511e+13 4.06088e+06 6.23e+09 99 100 4.06362e+13 7.76141e+06 6.3e+08 100 101 4.06348e+13 1.54283e+07 5.56e+07 101 102 4.06346e+13 3.07614e+07 4.68e+06 102 103 4.06346e+13 6.15994e+07 3.86e+05 103 104 4.06346e+13 1.23451e+08 3.16e+04 104 105 4.06346e+13 2.43789e+08 2.57e+03 105 106 4.06346e+13 4.93803e+08 209 106 107 4.06346e+13 9.87605e+08 17 107 108 4.06346e+13 1.97521e+09 1.38 108 109 4.06346e+13 3.95042e+09 0.112 109 110 4.06346e+13 7.90084e+09 0.00912 110 111 4.06346e+13 1.64817e+10 0.000753 111 112 4.06345e+13 3.32409e+10 0.000753 112 113 4.06344e+13 6.65334e+10 0.000753 113 114 4.06342e+13 1.33067e+11 0.000752 114 115 4.06339e+13 2.58119e+11 0.000752 115 116 4.06331e+13 5.32267e+11 0.000752 116 117 4.06315e+13 1.06453e+12 0.000751 117 118 4.06302e+13 8.57099e+11 0.000751 118 119 4.0627e+13 2.12907e+12 0.000749 119 120 4.06206e+13 4.25814e+12 0.000747 120 121 4.06079e+13 8.51627e+12 0.000742 121 122 4.05828e+13 1.70325e+13 0.000731 122 123 4.05338e+13 3.40651e+13 0.00071 123 124 4.044e+13 6.81302e+13 0.000667 124 125 4.02697e+13 1.3626e+14 0.000582 125 126 3.99985e+13 2.72521e+14 0.000413 126 127 3.97335e+13 5.45042e+14 7.33e-05 127 128 3.97335e+13 1.66044e-05 7.33e-05 128 129 3.97335e+13 4.15111e-06 7.33e-05 129 130 3.97335e+13 1.03778e-06 7.33e-05 130 131 3.97335e+13 2.59444e-07 7.33e-05 131 132 3.97335e+13 6.4861e-08 7.33e-05 132 133 3.97335e+13 1.62153e-08 7.33e-05 133 134 3.97335e+13 4.05381e-09 7.33e-05 134 135 3.97335e+13 1.01345e-09 7.33e-05 135 136 3.97335e+13 2.53363e-10 7.33e-05 136 137 3.97335e+13 6.33408e-11 7.33e-05 137 138 3.97335e+13 1.58352e-11 7.33e-05 138 139 3.97335e+13 3.9588e-12 7.33e-05 139 140 3.97335e+13 9.89701e-13 7.33e-05 140 141 3.97335e+13 2.47425e-13 7.33e-05 141 142 3.97335e+13 6.18563e-14 7.33e-05 142 143 3.97335e+13 1.54641e-14 7.33e-05 143 144 3.97335e+13 3.86602e-15 7.33e-05 144 145 3.97335e+13 9.66505e-16 7.33e-05 Local minimum possible. lsqnonlin stopped because the size of the current step is less than the value of the step size tolerance.
x
x = 1×2
1.0e+18 * 1.0639 0.0000
FVAL=FVAL./s
FVAL = 2×1
-0.0016 0.0006
function [F,J] = nested_solver_straight_wg(x,s)
C=5.4e-22 ;
D=1.53e-18 ;
A=8.88e-21 ;
B=5.84e-20 ;
ne = x(1) ;
pe = x(2);
F(1) = A*ne.^1.16+B*pe.^1.109-7.24;
F(2) = C*ne.^1.011+D*pe.^0.838-2.7687e-04;
F=s.*F(:);
if nargout>1
J(1,1) = A*ne.^0.16*1.16; J(1,2)=B*1.109*pe.^0.109;
J(2,1) = C*ne.^0.011*1.011; J(2,2)=D*pe.^(0.838-1)*0.838;
J=s.*J;
end
end
  2 Comments
marco nova
marco nova on 27 Mar 2022
What is the meaning of
if nargout>1
J(1,1) = A*ne.^0.16*1.16; J(1,2)=B*1.109*pe.^0.109;
J(2,1) = C*ne.^0.011*1.011; J(2,2)=D*pe.^(0.838-1)*0.838;
J=s.*J;
end
So with this version the solver is not able to solve the second equation, in fact if i change the equation:
F(2) = C*ne.^1.011+D*pe.^0.838-2.7687e-04;
with
F(2) = C*ne.^1.011+D*pe.^0.838-2.7687e-03;
or
F(2) = C*ne.^1.011+D*pe.^0.838-2.7687e-02;
the solutions are practically the same. Is there a way out? Note that ne and pe cannot be negative physically speaking.
Thank you for your help!
Matt J
Matt J on 27 Mar 2022
Edited: Matt J on 27 Mar 2022
What is the meaning of
That is the Jacobian of F. You should provide it, using the SpecifyObjectiveGradient, whenver possible, since otherwise fsolve/lsqnonlin must approximate it using finite differences.
So with this version the solver is not able to solve the second equation:
The second equation doesn't appear to be providing very much additional information. If we do a surface plot of your objective function, we can see that there is a long trench of essentially equivalent least squares solutions:
fsurf(@(x,y) nested_solver_straight_wg(x,y),[1e18,1.1e18,0, 5e16])
xlabel ne;
ylabel pe;
zlim([0,.1]);
view(43,50)
function F = nested_solver_straight_wg(ne,pe)
C=5.4e-22 ;
D=1.53e-18 ;
A=8.88e-21 ;
B=5.84e-20 ;
F1 = A*ne.^1.16+B*pe.^1.109-7.24;
F2 = C*ne.^1.011+D*pe.^0.838-2.7687e-04;
F=F1.^2+F2.^2;
end

Sign in to comment.

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!