OutputFcn for selfmade function to show iteration steps
Show older comments
Hello there,
I have written my own Levenberg-Marquardt Algorithm as shown below.
Now I want to show every step of the Iteration. Normally I do this with OutputFcn, but this won't work because OutputFun is only for Matlab functions (so I think).
How can I do this otherwise? Is there another option to integrate an OutputFcn? Otherwise I would need to save every x of the iteration, but I don't know how.
(By the way, there is a mistake in the Algorithm, where if eps_mu <=beta 0 x = x-s is wrong. There should be x(k+1) = x(k) which I also don't know how to do, but I am working on this ;) )
Thanks für every help :)
function x=levenberg_marquardt(f,dF,x0,mu0,beta0,beta1,maxit,tol)
n=length(x0);
k=0;
mu=mu0;
x=x0;
s=-(dF(x0)'*dF(x0) + mu^2*eye(n))\(dF(x0)'*f(x0));
while norm(s)>tol && k<maxit
for k=k+1
s=-(dF(x)'*dF(x)+mu^2*eye(n))\(dF(x)'*f(x));
eps_mu=0.5*((f(x)'*f(x)-(f(x+s)'*f(x+s)))/(-s'*dF(x)'*f(x)));
if eps_mu <= beta0
x=x-s;
mu=mu/2;
else
x=x+s;
if eps_mu >= beta1
mu=2*mu;
end
end
end
end
end
5 Comments
Walter Roberson
on 22 Dec 2020
What is it that you want to display at each point of the algorithm, and what form do you want to display it?
Nico Lange
on 22 Dec 2020
Nico Lange
on 23 Dec 2020
Walter Roberson
on 23 Dec 2020
In the time since then, I have had activity on more than 70 Questions. I have been working so much on responding to people the last while that I am very behind in my Christmas preparations..
Nico Lange
on 23 Dec 2020
Accepted Answer
More Answers (0)
Categories
Find more on Scopes and Data Logging in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!