Error: Not Enough Input Arguments.

12 views (last 30 days)
Park
Park on 27 Jan 2014
Answered: Azzi Abdelmalek on 27 Jan 2014
"Error using newton_mathod (line 48). Not enough input arguments" why does it give me this error message? here is my code:
function [ x, ex ] = newton_mathod(f,df,x0,tol,nmax)
syms x;
f=@(x)0.95*x^3 - 5.9*x^2 + 10.9*x - 6
df=@(x)2.85*x^2 - 11.8*x + 10.9
x0=1;
if nargin == 3
tol = 1e-4;
nmax = 1e1;
elseif nargin == 4
nmax = 1e1;
elseif nargin ~= 5
disp('newton invalid input parameters');
end
f = inline('f');
df = inline('df');
x(1) = x0 - (f(x0)/df(x0));
ex(1) = abs(x(1)-x0);
k = 2;
while (ex(k-1) >= tol) && (k <= nmax);
x(k) = x(k-1) - (f(x(k-1))/df(x(k-1)));
ex(k) = abs(x(k)-x(k-1));
k = k+1;
end
end

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 27 Jan 2014
I don't know if you have done this code or find it somewhere. This code represent a function, but at the same time the input argument f and df are unnecessary, because they are defined inside your function
f=@(x)0.95*x^3 - 5.9*x^2 + 10.9*x - 6
df=@(x)2.85*x^2 - 11.8*x + 10.9
Then just after, they are replaced by
f = inline('f');
df = inline('df');

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!