1 iteration in fsolve: new x and no more
Mostra commenti meno recenti
I want to use fsolve to only use one iteration: get the Jacobian, get x1 and done. However when test the code below, which tries to find the zero of x^2, i see the following:
-iteration 0, 2 function evaluations: it seems f(x0) and 1 for finite difference
-iteration 1, 2 function evaluations: it seems f(x1) and 1 for finite difference
I do not want the last two evaluations. Is this possible?
I mean, this doubles the computation time, but it adds nothing for me. Especially since the Jacobian that is reported is the jacobian at x0 (not at x1). If it would at least give me the jacobian at x1 as output i could calculate the next iteration myself.
The solution would to program a similar routine myself, but I rather use fsolve (i also want to use JacobPattern for example).
clear all;
clc;
fun_res = @(xx)xx.^2;
x0 = 1;
ex_fl = -10;
iter = 0;
while ex_fl < 1 && iter < 100
iter = iter+1;
%[xx_it(iter,1),res(iter,1),ex_fl,~,jac(iter,1)] = fsolve(fun_res,x0,optimoptions(@fsolve,'Display','iter','MaxIterations',1));
[xx_it(iter,1),~,ex_fl] = fsolve(fun_res,x0,optimoptions(@fsolve,'Display','iter','MaxIterations',1));
x0 = xx_it(iter);
end
2 Commenti
Matt J
il 9 Mar 2021
If it would at least give me the jacobian at x1
I don't know why you think it isn't. The documentation states that the Jacobian should that at the "solution".
Sargondjani
il 9 Mar 2021
Risposta accettata
Più risposte (1)
Matt J
il 9 Mar 2021
0 voti
The solution would to program a similar routine myself, but I rather use fsolve (i also want to use JacobPattern for example).
You could also use an existing routine from the File Exchange, like this one,
https://www.mathworks.com/matlabcentral/fileexchange/13490-adaptive-robust-numerical-differentiation
It wouldn't be so difficult to adapt the routine to work with a JacobPattern.
1 Commento
Sargondjani
il 9 Mar 2021
Categorie
Scopri di più su Solver Outputs and Iterative Display in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!