I'm new to Matlab and am working on implementing Newton's method on a nonlinear system. I'm using a very simple example but when I call the function I create, I get the error: "Not enough input arguments. Error in function1 (line 2) f=x.^3-x.^2-1;"
Here are my function definitions:
Newton's method part:
function [new, iter] = Netn(function1,dfunction1,x) tol=0.0001; old=x; u=function1(x); v=dfunction1(x); new=old-u/v; iter=1; while (abs(new-old)>=tol) old=new; u=function1(old); v=dfunction1(old); new=old-u/v; iter=iter+1; end end
Simple function definition
function f=function1(x) f=x.^3-x.^2-1; end
Simple function derivative definition (for Newton's)
function f=dfunction1(x) f=3*x.^2-2*x; end
You need to use function handles.
Change your call to
Change you main function to (you need to use feval when evaluating the functions passed by function handles)
Now you can also create other objective and derivative functions, with other names. And you pass those names as function handles in your call to Netn, without changing the code to Netn.