> | restart; Digits := 6; nicelog := z -> if z < 10.0^(-Digits) then -Digits else log[10](z) fi; |
> | nTerms := 150; Eerror := vector(nTerms): Erelerr := vector(nTerms): Lerror := vector(nTerms): Lrelerr := vector(nTerms): Serror := vector(nTerms): Srelerr := vector(nTerms): for x in [0.01,0.1,0.2,0.5,1.0,2.0,5.0,10.0,100.0] do Es := 1: Eterm := 1: Ls := (x-1)/(x+1): Ltop := (x-1)/(x+1): Ss := x: Sterm := x: for k from 1 to nTerms do Eterm := x * Eterm / k: Es := Es + Eterm: Eerror[k] := abs(exp(x) - Es): Erelerr[k] := Eerror[k]/abs(exp(x)): Ltop := Ltop*((x-1)/(x+1))^2: Lterm := Ltop/(2*k+1): Ls := Ls + Lterm: Lerror[k] := abs(log(x) - 2*Ls): Lrelerr[k] := Lerror[k]/abs(log(x)): Sterm := Sterm*(-x^2)/(4*k^2+2*k): Ss := Ss + Sterm: Serror[k] := abs(sin(x) - Ss): Srelerr[k] := Serror[k]/abs(sin(x)): od: print("x" = x); Elog:=-log10(Erelerr[nTerms]): Slog:=-log10(Srelerr[nTerms]): Llog:=-log10(Lrelerr[nTerms]): plot( [seq([j,nicelog(Erelerr[j])], j=1..nTerms)], axes=FRAME, labels = ["Order of Partial Sum", "Relative Error of Partial Sum"] ); plot( [seq([j,nicelog(Lrelerr[j])], j=1..nTerms)], axes=FRAME, labels = ["Order of Partial Sum", "Relative Error of Partial Sum"] ); plot( [seq([j,nicelog(Srelerr[j])], j=1..nTerms)], axes=FRAME, labels = ["Order of Partial Sum", "Relative Error of Partial Sum"] ); od; |
Plotting error, empty plot
> |