can't turn on the jacobian for lsqnonlin
7 views (last 30 days)
Show older comments
i have defined my vector objective function like this....
function [r5,jacr5] = myfunction5(N)
global F1
F1 = 1008000;
r = zeros(10000,1);
f = zeros(10000,1);
jacr5 = zeros(10000,3);
for p = 1:10000
r(p,1) = 5 * sin(2*3.14*F1*(p/(10000000))+0.3);
end
for q1 = 1:10000
f(q1,1) = N(1) * sin((2*3.14*N(2)*(q1/10000000)) + N(3));
end
r5 = r-f;
if nargout>1
jacr5(:,1) = - myfunction1(N(2),N(3));
jacr5(:,2) = - myfunction2(N(1),N(2),N(3));
jacr5(:,3) = - myfunction3(N(1),N(2),N(3));
end
end
where myfunction1 goes something like....
function r1 = myfunction1(y,z)
f1 = zeros(10000,1);
for q1 = 1:10000
f1(q1,1) = sin((2*3.14*y*(q1/10000000)) + z);
end
r1 = f1;
end
similar is myfunction2 and 3.
Now in the main function where i have called lsqnonlin(), i have tried to turn on the jacobian but the "options" statement is basically doing nothing. Also when i tried to change the tolerance to 1e-8 by writing
options = optimset('Jacobian','on','TolX',1e-8);
it was of no use. Because of this, i am constantly getting this message when i run the optimization...
Local minimum possible.
lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the default value of the function tolerance.
value of N thus achieved is not as close to the answer as it should be. Please suggest something soon.
0 Comments
Answers (2)
Alan Weiss
on 28 May 2013
Did you pass the options to the solver? I mean, when you call lsqnonlin, did you include options something like this:
x = lsqnonlin(fun,x0,lb,ub,options)
Alan Weiss
MATLAB mathematical toolbox documentation
Alan Weiss
on 29 May 2013
Did you get iterative display? Yes? Then the options were accepted and used by the solver.
To check the values of options, do not issue an optimset command. Just enter "options" at the command line. You will see the values in the options structure.
As far as your problem of not getting accurate enough solutions, there are several possibilities. One is to use pi instead of 3.14 in your formulas. Another is to give a better initial guess, such as taking the result N and feeding it back in as n, the initial guess. For more suggestions, see the documentation.
Alan Weiss
MATLAB mathematical toolbox documentation
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!