Undefined function 'abs' for input arguments of type 'function_handle'
Ältere Kommentare anzeigen
function [root,rootHistory, iter,errorValue]=myNewton(fh,dfh,initialGuess, tol , maxIter )
numLoop = 0;
rootHistory = [];
x = initialGuess;
a = @(x)fh;
while abs(a) >= tol
x1 = initialGuess - fh/dfh;
initialGuess = x1;
numLoop = numLoop + 1;
rootHistory = [rootHistory x1];
if numLoop == maxIter
break
end
end
root = x1;
iter = numLoop;
errorValue = abs(fh(root));
end
I don't know why it is giving me this error statement. There are also other syntax error in my code as well. Can someone help please? The instructions are in the PDF
1 Kommentar
bdlawr
am 9 Nov. 2017
Antworten (1)
Walter Roberson
am 9 Nov. 2017
You need to change
a = @(x)fh;
to
a = fh(x);
You need to change
to
x1 = initialGuess - fh(SOMEINPUT)/dfh(SOMEINPUT);
You will need to figure out what is appropriate for SOMEINPUT.
You will also need to change a somewhere in the loop.
6 Kommentare
Walter Roberson
am 9 Nov. 2017
No, fh is a handle to a function. It says so right in your instructions.
To invoke a function handle, you name the function handle, then ( then the list of parameters then ) -- just like the fh(x) that I showed.
bdlawr
am 9 Nov. 2017
Walter Roberson
am 9 Nov. 2017
Please post your current code.
bdlawr
am 9 Nov. 2017
Bearbeitet: Walter Roberson
am 15 Nov. 2017
Walter Roberson
am 15 Nov. 2017
In the first position, are you passing in
x.^3 + 2*x.^2 - 10*x
or are you passing in
@(x) x.^3 + 2*x.^2 - 10*x
?
Kategorien
Mehr zu Big Data Processing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!