Reputation: 153
I have a function in a .m file:
function [func diff1 diff2]=fun(x)
func=(3*x^3)+6;
diff1=(3*(x+0.00000001)^3-3*((x)^3))/0.00000001;
diff2=(3*((x+0.00000001)^3)-2*3*(x^3)+3*(x-.00000001)^3)/(.00000001^2);
end
In the second function I want to be able to pass in the function as a parameter. I keep getting
"Attempted to access fun(3); index out of bounds because numel(fun)=1."
Does anyone have any ideas?
function [x,N,fval]=halley(fun,guess,tol);
fval=fun(guess);
end
Upvotes: 0
Views: 103
Reputation: 16334
You need to pass a function handle when calling halley
:
halley(@fun, 3, 0.1)
Upvotes: 2