Clear Filters
Clear Filters

Problem in using fsolve

4 views (last 30 days)
Sameer
Sameer on 10 Jun 2014
Answered: Alex Sha on 11 Dec 2019
Hi
I am trying to solve the following set of equations but the solver is prematurely stopped and If I alter the MaxIter and MaxEvals then also its showing stopped prematurelly and then I tried to alter the tolerance then its shows no solution found. Can anyone guide how can i obtain the solution for the following set of equations.
function F = compare(X)
rho=1000.0;
F=[
1.0*7.018e-4*4.2850022315+-1.0*1.25e-3*X(2)+-1.0*7.36e-5*X(3)+-1.0*4.47e-5*(4);
-1.0*1.25e-3*X(1)+1.0*1.66e-5*X(4)+1.0*4.47e-5*X(5)+1.0*1.07e-4*X(6);
+1.0*7.36e-5*X(2)-1.0*1.07e-4*X(6)+1.0*1.07e-4*X(7);
1.0*4.47e-5*X(3)+-1.0*4.47e-5*X(5)+-1.0*1.07e-4*X(7);
1.0*0.4*rho*4.2850022315979^2+1.0*807362.4375+-1.0*0.4*rho*X(2)^2 + -1.0*X(9);
1.0*0.4*rho*4.2850022315979^2 + 1.0*807362.4375+-1.0*0.4*rho*X(3)^2+-1.0*X(10);
1.0*0.4*rho*4.2850022315979^2 + 1.0*807362.4375+-1.0*0.4*rho*X(4)^2+-1.0*X(11);
-1.0*0.4*rho*X(1)^2 + -1.0*X(8)+ 1.0*0.4*rho*X(4)^2 + 1.0*X(11);
-1.0*0.4*rho*X(1)^2 + -1.0*X(8) + 1.0*0.4*rho*X(5)^2 + 1.0*X(12);
-1.0*0.4*rho*X(1)^2 + -1*X(8) + 1.0*0.4*rho*X(6)^2 + 1.0*X(13);
-1.0*0.4*rho*X(6)^2 + -1.0*X(13) + 1.0*0.4*rho*X(2)^2 + 1.0*X(9);
-1.0*0.4*rho*X(6)^2 + -1.0*X(13) + 1.0*0.4*rho*X(7)^2 + 1.0*X(14);
1.0*0.4*rho*X(3)^2 + 1.0*X(10) + -1.0*0.4*rho*X(5)^2 + -1.0*X(12);
1.0*0.4*rho*X(3)^2 + 1.0*X(10) + -1.0*0.4*rho*X(7)^2 + -1.0*X(14)
];
end
options = optimset('Display','iter','TolX',1e-7,'MaxFunEvals',18000,'MaxIter',2200);
[Sol,fval,exitflag]=fsolve(@compare,X,options);
following error comes
No solution found.
fsolve stopped because the last step was ineffective. However, the vector of function
values is not near zero, as measured by the default value of the function tolerance.
<stopping criteria details>
where X's are the variables
Please Guide!!!
Regards
  2 Comments
Geoff Hayes
Geoff Hayes on 10 Jun 2014
Sameer - it may be helpful to format your above code so that it is easier to read (highlight the code and press the {}Code button).
Also you may want to include additional information - what is V, what is P? What was your initial condition? Did you include any options? What is the code you used to evaluate this system of equations? What is the solution obtained by fsolve?
Unfortunately, I don't have access to the Optimization Toolbox so can't test out the above, but if you provide more information, someone else might be able to.
Sameer
Sameer on 10 Jun 2014
Thanks for the tip....
Regards

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 10 Jun 2014
Edited: Star Strider on 10 Jun 2014
You have to write your function so that all of your unknowns are in the same parameter vector.
So calling your parameter vector ‘B’:
B = [V(1) ... V(7) P(1) ... P(7)];
then replace V(1) with B(1), P(1) with B(8), and so forth.
If you intend ‘F’ to be an anonymous function, you have to write it as:
F = @(B,rho) [1.0*10.0*25+-1.0*17.0*B(2)+ ... + -1.0*0.4*rho*B(7)^2 + -1.0*B(14)];
(I abbreviated the function here.) Use the ‘Search’ and ‘Replace’ utilities in the MATLAB Editor to do this more easily.
Your call to fsolve is then:
[x,fval] = fsolve(@(B) F(B,rho),x0)
Your F function will get ‘rho’ from your workspace.
EDIT — Try using different starting values for ‘X’ that are reasonably close to what you expect them to be. Otherwise experiment with them. If it doesn’t converge on a solution after several attempts, it may not have a solution. If you believe it should, go back to your original equations and be sure you wrote ‘F’ correctly.
  12 Comments
Star Strider
Star Strider on 13 Jun 2014
My pleasure!
The GA should work for you.
Sameer
Sameer on 13 Jun 2014
Edited: Sameer on 13 Jun 2014
Didn't used that....Manupulated my equations and simplified them a bit and then took guess of 10's and it worked. Though there is a slight error but its fine as its involves the use of terms obtained from linear regression. So I am satisfied thus didn't feel like to use GA but thanks a lot for all the support.
Regards

Sign in to comment.

More Answers (2)

Marc
Marc on 15 Jun 2014
Edited: Marc on 15 Jun 2014
Taking Star Strider's approach, I compared "patternsearch" with "fsolve". For patternsearch, I used the following objective function:
fObj = sum(F.^2)
Called patternsearch and solve with the following initial guess...
xGuess = [1.0; 0.5; 0.25; 0.1; 1.2; 2.3; 3; 0.5;
2.0; 1.5; 1.2; 0.46; 0.9; 0.8; 2];
%xGuess = [10; 10; 10; 10; 10; 10; 10; 10;
% 10; 10; 10; 10; 10; 10; 10];
F = craxy14(xGuess)
options1 = optimset('Display','iter','TolX',1e-7,'MaxFunEvals',18000,'MaxIter',2200);
[Sol,fval,exitflag]=fsolve(@craxy14,xGuess,options1)
fvalComp = sum(fval.^2)
options = psoptimset('TolX', 1e-12, 'TolFun', 1e-10);
[Sol, fval, exitflag] = patternsearch(@craxy14_PS, xGuess,[],[],[],[],[],[],[],options)
And got the following output...
F =
0.0021850145660667
-0.0009486
0.0001117
-0.000363465
814604.93514992
814680.43514992
814701.73514992
-395.3
175.96
1716.4
-2014.9
1483.9
-549.96
-3574.3
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead. > In fsolve at 309 In tryCrazy at 13
First-Order Norm of
Iteration Func-count Residual optimality Lambda step
0 16 1.99105e+12 3.27e+08 0.01
1 41 1.48607e+12 6.51e+09 1e+07 36.218
2 58 1.04076e+12 2.68e+09 1e+08 30.8991
3 74 7.3865e+11 5.56e+09 1e+07 26.3164
4 91 1.36874e+11 8.44e+09 1e+08 42.257
5 107 3.31559e+09 9.86e+08 1e+07 13.2943
6 123 703959 2.58e+07 1e+06 2.72485
7 139 2.20032 1.47e+04 100000 0.0333549
8 155 0.00565597 3.26 10000 7.18966e-05
9 171 0.00565585 8.38e-05 1000 1.69513e-08
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 default value of the function tolerance.
Sol =
45.1305446907037
45.1305011994196
45.1305149725761
45.1305231544755
45.1305458382382
45.1305337039192
45.1305364903727
0.509518068564456
2.07974558905608
1.58247394623463
1.2870712557843
0.468086982642547
0.906189676429257
0.805586368498305
2
fval =
-0.0569063178351894
-0.0488177116737268
0.0033216051864278
-0.00482896878416497
5.23959542420016e-09
5.85573345368573e-09
4.49008474845414e-09
3.42615713577743e-09
-8.54356030366432e-11
5.20720910834882e-10
2.21098517272367e-09
-2.78552736432403e-10
2.18091139592147e-09
1.90836724200949e-09
exitflag =
-2
fvalComp =
0.00565584998315177
Optimization terminated: mesh size less than options.TolMesh.
Sol =
1
32
16.25
16.1
1.2
2.3
3
814306.935150146
405106.935150146
709081.935150146
711022.935149383
814130.935150108
812590.935150528
811106.935150909
2
fval =
0.00147856720654457
exitflag =
1
Not sure which one is "more" or "less" right.

Alex Sha
Alex Sha on 11 Dec 2019
Two of solutions:
1:
x1 0.0302626794484622
x2 2.44987629792448
x3 -3.17840769482201
x4 -0.0245615818144686
x5 -0.291871074861581
x6 0.479277650607576
x7 -1.20587090572179
x8 814706.568818013
x9 812306.177599867
x10 810666.024960118
x11 814706.693841399
x12 814672.859660183
x13 814615.052323371
x14 814125.285293413
2:
x1 0.168219021935448
x2 2.20358006851998
x3 1.00461250566195
x4 0.191813576695766
x5 0.564198756330943
x6 1.69971951063707
x7 0.18398593079529
x8 814695.616094183
x9 812764.629102568
x10 814303.236635307
x11 814692.218170638
x12 814579.607055261
x13 813551.316583983
x14 814693.394820827

Community Treasure Hunt

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

Start Hunting!