The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
Program NEWT2
03-19-2018, 02:58 PM
Post: #1
Program NEWT2
Hi,

The program below is to my opinion an improved working variation on the program provided by Han. The original version led to an error message.

Original version

EXPORT NEWT2()
BEGIN LOCAL n, xold, xnew, err, N, f;

N := 100; err := .00001; xnew := 1;

IF INPUT(
{f, xnew, err, N},
"Newton's Method",
{"f(X) = ", "Guess = ", "Error = ", "Max Iter. = "},
{
"Enter the function surrounded by single quotes",
"Enter the initial guess",
"Enter the tolerance",
"Enter the maximum number of iterations"
},
{f, xnew, err, N}
) THEN F1 := f;

CAS("F0 := id-F1/F1'");
L1 := {}; L1(1) := xnew;
FOR n FROM 2 TO N+1 DO xold := xnew;
xnew := F0(xold);
L1(n) := xnew;
IF ABS(xnew-xold) < err THEN break; END;
END;
EDITLIST(L1);

END;

Improved version


EXPORT NEWT2

BEGIN

LOCAL n, xold, xnew, err, N, f;

N := 100; err := .00001; xnew := 1;
f:='X';

// By defining f as'X' as a default value
// the program works

IF INPUT(
{f, xnew, err, N},
"Newton's Method",
{"f(X) = ", "Guess = ", "Error = ", "Max Iter. = "},
{
"Enter the function surrounded by single quotes",
"Enter the initial guess",
"Enter the tolerance",
"Enter the maximum number of iterations"
},
{f, xnew, err, N}
) THEN F1 := f;

CAS("F0 := id-F1/F1'");
L1 := {}; L1(1) := xnew;
FOR n FROM 2 TO N+1 DO xold := xnew;
xnew := F0(xold);
L1(n) := xnew;
IF ABS(xnew-xold) < err THEN break; END;
END;
EDITLIST(L1);

END;
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Program NEWT2 - KarelPostulart - 03-19-2018 02:58 PM



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