matlab - Function as a parameter -


i have function in .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 second function want able pass in function parameter. keep getting

"attempted access fun(3); index out of bounds because numel(fun)=1."

does have ideas?

function [x,n,fval]=halley(fun,guess,tol); fval=fun(guess); end 

you need pass function handle when calling halley:

halley(@fun, 3, 0.1) 

Comments

Popular posts from this blog

java - unable show chart in xls document using jasper reports -

java.lang.RuntimeException: Could not generate dummy secret at sun.security.ssl.RSAClientKeyExchange.<init> -

javascript - How to change image src on success AJAX -