Error: Not Enough Input Arguments.
조회 수: 10 (최근 30일)
이전 댓글 표시
"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
댓글 수: 0
답변 (1개)
Azzi Abdelmalek
2014년 1월 27일
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');
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!