I have a function called MySolve and i am looking to adapt it to use Varargin.
As far as i am aware Varargin allows defaults for parameters to be set. but can be over-ridden if an input is given. I am having trouble understanding the syntax for using Varargin, here is the function MySolve.m that i have written:
function [x,converged]=MySolve(f,x0,tol,maxit)%Set Converged intial value to 0 (false)
%Set initial value of x as x0
converged=0;x=x0;%run a loop from 1 to maxit
for k=0:maxit x1=x; r=f(x); J=MyJacobian(f,x,1e-6); x=x-(J\r); if(max(abs(x-x1)))<tol && max(abs(f(x)))<tol converged=1; end end
I am looking to have defaults for tol and maxit as 1e-10 and 100 respectively.
any help is much appreciated.
Best Answer