Post Reply 
How to evaluate a function in a given point
10-05-2019, 02:54 PM
Post: #1
How to evaluate a function in a given point
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
Find all posts by this user
Quote this message in a reply
10-06-2019, 06:06 AM (This post was last modified: 10-06-2019 06:09 AM by Tyann.)
Post: #2
RE: How to evaluate a function in a given point
Bonjour

Le problème semble venir de F0 qui si j'ai bien compris doit contenir la fonction entrée dans f.
Je vous propose les modifications suivantes :

IF INPUT({f,[8]},..... <-> IF INPUT({f,[2]},......
F0:=expr(f); <-> F0:=f;

Suite à ces corrections je n'obtiens plus d'erreur d'argument.
Espérant avoir pu vous aider.

Hello

The problem seems to come from F0 which if I understood correctly must contain the function entered in f.
I propose the following changes:

IF INPUT({f,[8]},..... <-> IF INPUT({f,[2]},......
F0:=expr(f); <-> F0:=f;

Following these corrections I no longer get an argument error.
Hoping to have been able to help you.

Sorry for my english
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)