This is my first time writing code using varargin, so appologies if I'm doing it completely wrong.
I'm trying to keep it as general as possible, and the function file is below.
For example, say I set the inputs as
fun = @(x, Q) x^3 + Q
If I want to send Q=7 through varargin, how would I set it up, both in the function file and the line of code I call it from?
function [xroot,residual,ea,iter_count] = root_finder(fun,xi,es,max_it,varargin)
es = 10^-5;
max_it = 30;
fun_at_x1 = fun(xi(1));
fun_at_x2 = fun(xi(2));
new_root = xi(2) - fun_at_x2 * ((xi(2) - xi(1)) / (fun_at_x2 - fun_at_x1));
fun_at_new_root = fun(new_root);
xi= [xi(2) new_root];
if abs(fun_at_new_root) < es
residual = fun_at_new_root
iter_count = loops
ea = (xi(2) - xi(1)) / xi(2)