Mark Wickens

5 ONERRORGOTO1000
10 DEFCHR$(255)="0000FE0000":MODE8:DIM:PRINTCHR$(15);
30 f$="":c$=CHR$(5):s=0:h=1e-5:e=1e-7:m=20:ANGLE1
50 CLS:PRINT"Newton's method  f(x)=0";TAB(0);"1:f(x),x0       2:h,šœ€,loop";
60 k=ASC(INPUT$(1,@)):IFk=13 ORk=49 THEN90 ELSEIFk=50 THEN150
80 GOTO60
90 CLS:PRINT"Define function";
100 LOCATE0,1:PRINTc$;"f(x) ?";f$;:LOCATE0,0:LOCATE6,1:INPUT@100;f$:LOCATE0,0:z=VALF(f$)
110 IFLEN(f$)<25 THENg$=f$ ELSEg$=LEFT$(f$,21)+"惻惻惻"
120 m$="f(x) = "+g$:s$="x0":z=s:GOSUB800:s=z:GOTO250
150 m$="f'(x)=(f(x+h)-f(x))/h  (h>0)":s$="h":z=h:GOSUB800:h=z:IFh=<0 THEN150
170 m$="Err  āžƒXn+1-Xnāžƒ<šœ€  (šœ€>0)":s$="šœ€":z=e:GOSUB800:e=z:IFe<1e-90 THEN170
200 m$="Max loop  (n>0)":s$="n":z=m:GOSUB800:m=z:IFm=<0 ORFRACm<>0 THEN200 ELSE50
250 CLS:PRINTm$;TAB(0);"x = .....";:t=s
310 FORi=1 TOm
320 x=t:g=VALF(f$):x=t+h:f=VALF(f$):x=t-g*h/(f-g)
350 IFABS(t-x)=<e THEN500
360 t=x:NEXT:GOSUB450
390 PRINTc$;"loop =";m;TAB(11);":Xn =";STR$(x);:LOCATE0,0:LOCATE1,1:z$=INPUT$(1,@):GOTO50
450 LOCATE0,1:PRINTc$;"not found";:z$=INPUT$(1,@):RETURN
500 x=ROUND(x,INTLOG(ABSe)-1):PRINTc$;"x =";x;:z$=INPUT$(1,@):GOTO50
800 CLS:PRINTm$;
810 LOCATE0,1:PRINTc$;s$"=";z;"?";:INPUT@10;z:LOCATE0,0:RETURN
1000 IFERR=1 THENCLS:ONERRORGOTO0
1010 IFERL=100 THENIFERR=2 THENRESUME100 ELSERESUMENEXT
1015 IFERL=810 THENRESUME810
1020 GOSUB450:RESUME50