I think the mathematical portion of my algorithm is correct, but I don't really know the mathematica syntax.
How do I get the actual function to be evaluated?
Code:
Simpson[a_, b_, count_] := Module[{},
Return[(b - a)/6 (f[a] + 4 f[(a + b)/2] + f[b])]];
Adaptive[a_, b_, tol_, count_] := Module[{c},
c = (a + b)/2;
Sab = Simpson[a, b, count];
Sac = Simpson[a, c, count];
Scb = Simpson[c, b, count];
If[Abs[Sab - Sac - Scb] < tol,
Return[Sac + Scb],
Return[count],
Return[Adaptive[a, c, tol/2] + Adaptive[c, b, tol/2]]];];
f[x_] = Cos[x^2];
Print["f[x] = ", f[x]];
tol1 = 0.001;
count = 0;
Print[Adaptive[0.0, 2.0, tol1, count]];
This ends up returning:
f[x] = Cos[x^2]
0
ìfthat has three expressions within, the last of which is only returned ifAbs[Sab-Sac-Scb]doesn't return True or False. Are you sure this is what you wanted? – AndreasP Oct 10 '16 at 11:21