10-05-2019, 02:54 PM

Hello everyone,

I have just acquired my HP Prime, and this weekend I decided to spend some time learning how to implement some basic numeric methods on it.

While doing so with Regula Falsi, despite my code is apparently correct, I am continuously being given the message 'Incorrect argument type' when running it on my device. You can find it attached below:

EXPORT REGULA_FALSI()

BEGIN

LOCAL n,a,b,xnew,tol,N,f;

N := 100;

tol := .001;

IF INPUT(

{{f,[8]},{a,[0]},{b,[0]},{tol,[0]},{N,[0,1]}},

"Regula falsi's method",

{"f(X)=", "Left guess=", "Right guess=", "Tolerance=", "Max iter.="},

{

"Enter the function surrounded by single quotes",

"Enter the initial left guess",

"Enter the initial right guess",

"Enter the tolerance",

"Enter the maximum number of iterations"

},

{f,a,b,tol,N}

) THEN

F0 := expr(f);

L1 := {};

L1(1) := a;

FOR n from 2 to N+1 DO

xnew := a - F0(a)*(b-a)/(F0(b)-F0(a));

IF F0(a)*F0(xnew) < 0

THEN b := xnew;

ELSE a := xnew;

END;

L1(n) := xnew;

IF F0(a) < tol

THEN BREAK;

END;

END;

editlist(L1);

END;

END;

Do you have any clue about why isn't it correct?

Thank you so much in a advance, and may you have a nice day.

With kind regards,

Aitor

I have just acquired my HP Prime, and this weekend I decided to spend some time learning how to implement some basic numeric methods on it.

While doing so with Regula Falsi, despite my code is apparently correct, I am continuously being given the message 'Incorrect argument type' when running it on my device. You can find it attached below:

EXPORT REGULA_FALSI()

BEGIN

LOCAL n,a,b,xnew,tol,N,f;

N := 100;

tol := .001;

IF INPUT(

{{f,[8]},{a,[0]},{b,[0]},{tol,[0]},{N,[0,1]}},

"Regula falsi's method",

{"f(X)=", "Left guess=", "Right guess=", "Tolerance=", "Max iter.="},

{

"Enter the function surrounded by single quotes",

"Enter the initial left guess",

"Enter the initial right guess",

"Enter the tolerance",

"Enter the maximum number of iterations"

},

{f,a,b,tol,N}

) THEN

F0 := expr(f);

L1 := {};

L1(1) := a;

FOR n from 2 to N+1 DO

xnew := a - F0(a)*(b-a)/(F0(b)-F0(a));

IF F0(a)*F0(xnew) < 0

THEN b := xnew;

ELSE a := xnew;

END;

L1(n) := xnew;

IF F0(a) < tol

THEN BREAK;

END;

END;

editlist(L1);

END;

END;

Do you have any clue about why isn't it correct?

Thank you so much in a advance, and may you have a nice day.

With kind regards,

Aitor