restart: # EULER'S ALGORITHM 5.1 # # TO APPROXIMATE THE SOLUTION OF THE INITIAL VALUE PROBLEM: # Y' = F(T,Y), A<=T<=B, Y(A) = ALPHA, # AT N+1 EQUALLY SPACED POINTS IN THE INTERVAL [A,B]. # # INPUT: ENDPOINTS A,B: INITIAL CONDITION ALPHA: INTEGER N. # # OUTPUT: APPROXIMATION W TO Y AT THE (N+1) VALUES OF T. print(`This is Euler's Method.`): print(`Input the function f(t,y) in terms of t and y`): print(`For example: y-t^2+1`): F := scanf(`%a`)[1]:print(`your function f(t,y) = `):print(F): F := unapply(F,t,y): OK := FALSE: while OK = FALSE do print(`Input left and right endpoints separated by blank`): A := scanf(`%f`)[1]:print(`a = `):print(A): B := scanf(`%f`)[1]:print(`b = `):print(B): if A >= B then print(`Left endpoint must be less than right endpoint`): else OK := TRUE: fi: od: print(`Input the initial condition`): ALPHA := scanf(`%f`)[1]:print(`y(a) = `):print(ALPHA): OK := FALSE: while OK = FALSE do print(`Input a positive integer for the number of subintervals`): N := scanf(`%d`)[1]:print(`N = `):print(N); if N <= 0 then print(`Number must be a positive integer`): else OK := TRUE: fi: od: if OK = TRUE then print(`Choice of output method:`): print(`1. Output to screen`): print(`2. Output to text file`): print(`Please enter 1 or 2`): FLAG := scanf(`%d`)[1]:print(`Your choice is `):print(FLAG): if FLAG = 2 then print(`Input the file name in the form - drive:\134\134name.ext`): print(`For example A:\134\134OUTPUT.DTA`): NAME := scanf(`%s`)[1]:print(`File name is `):print(NAME): OUP := fopen(NAME,WRITE,TEXT): else OUP := default: fi: fprintf(OUP, `EULERS METHOD\134n\134n`): fprintf(OUP, ` t w\134n\134n`): # Step 1 H := (B-A)/N: T := A: W := ALPHA: fprintf(OUP, `%5.3f %11.7f\134n`, T, W): # Step 2 for I1 from 1 to N do # Step 3 # Compute W(I) W := W+H*F(T, W): # Compute T(I) T := A+I1*H: # Step 4 fprintf(OUP, `%5.3f %11.7f\134n`, T, W): od: # Step 5 if OUP <> default then fclose(OUP): print(`Output file`,NAME,` created successfully`): fi: fi: SThUaGlzfmlzfkV1bGVyJ3N+TWV0aG9kLkc2Ig== SU5JbnB1dH50aGV+ZnVuY3Rpb25+Zih0LHkpfmlufnRlcm1zfm9mfnR+YW5kfnlHNiI= STVGb3J+ZXhhbXBsZTp+eS10XjIrMUc2Ig== STh5b3VyfmZ1bmN0aW9ufmYodCx5KX49fkc2Ig== LChJInlHNiIiIiIqJEkidEdGJCIiIyEiIkYlRiU= SVJJbnB1dH5sZWZ0fmFuZH5yaWdodH5lbmRwb2ludHN+c2VwYXJhdGVkfmJ5fmJsYW5rRzYi SSVhfj1+RzYi JCIiIUYj SSVifj1+RzYi JCIiIyIiIQ== STxJbnB1dH50aGV+aW5pdGlhbH5jb25kaXRpb25HNiI= SSh5KGEpfj1+RzYi JCIiJiEiIg== SVhJbnB1dH5hfnBvc2l0aXZlfmludGVnZXJ+Zm9yfnRoZX5udW1iZXJ+b2Z+c3ViaW50ZXJ2YWxzRzYi SSVOfj1+RzYi IiM1 STlDaG9pY2V+b2Z+b3V0cHV0fm1ldGhvZDpHNiI= STQxLn5PdXRwdXR+dG9+c2NyZWVuRzYi STcyLn5PdXRwdXR+dG9+dGV4dH5maWxlRzYi STRQbGVhc2V+ZW50ZXJ+MX5vcn4yRzYi STBZb3VyfmNob2ljZX5pc35HNiI= IiIi EULERS METHOD t w 0.000 0.5000000 0.200 0.8000000 0.400 1.1520000 0.600 1.5504000 0.800 1.9884800 1.000 2.4581760 1.200 2.9498112 1.400 3.4517734 1.600 3.9501281 1.800 4.4281538 2.000 4.8657845 JSFH