I have a nice function whose graph is approximately quadratic; the plot shows the area under it should be around 1.6
However, it seems Maple thinks the area is 0.1465
Presumably there is something simple I am doing wrong, but I can't see it.
What follows may seem strange -- it is certainly strange to me -- but I need to be able to make integration work with my functions as apposed to the built-in functions one sees in examples...
with(Student[Calculus1]);
Digits:= 64;
erfy := (x) -> piecewise(x < -5, -1+(-1/Pi^(1/2)/x+1/2/Pi^(1/2)/x^3-3/4/Pi^(1/2)/x^5)/exp(x^2), And(-5 <= x, x <= 5), erf(x), x > 5, (1+(-1/Pi^(1/2)/x+1/2/Pi^(1/2)/x^3-3/4/Pi^(1/2)/x^5)/exp(x^2)));
h:= (u,a,b,g,d) -> exp(-(1/d)^2)*d*g*exp(-(u-a)^2/b^2)*exp(((d-u)/(d*u))^2)*(1-erfy((d-u)/(d*u)))/u;
core := proc(n,t0,t1,a,b,g,d)
local x,y,f;
x := 2*t0/(d*g);
y := 2*t1/(d*g);
f := unapply(h(u,a,b,g,d), u);
[ApproximateInt(f, x..y, method = simpson),x,y];
end proc;
core(3,.5, 2.1, .5, 3, 3.14, 2.4);
MAPLE responds with an integral of about 0.1465...
HOWEVER:
show := proc(n,t0,t1,a,b,g,d)
local x,y,f;
x := 2*t0/(d*g);
y := 2*t1/(d*g);
f := unapply(h(u,a,b,g,d), u);
plot(f, x..y);
end proc;
show(3,.5, 2.1, .5, 3, 3.14, 2.4);
MAPLE responds with the nice quadratic graph whose area should be about 1.6...
Is it possible that Maple can be so wrong?!? More likely would be that I have no clue as to how one somehow manages to cajole Maple into preforming an integral.
Please help.
1.6366587497074052272870953240180323794215383 ...
Have not stepped through the problem in detail, but you do not need
to approximate the error function on your own (it makes the function
non-analytic) and there is no need to use Simpson (playing with your
approach I see a 'discontinuity' at ~ 1.6 for your task, but do not
want to look closer).
After converting to rationals you want the following:
Int(169858969913624935089195720356683/26813033068808184917956157510272*
(1-erf(5/12*(12/5-u)/u))/u*exp(-1/9*(u-1/2)^2+25/144*(12/5-u)^2/u^2),
u = 125/942 .. 175/314);
Using simplify(%); expand(%); combine(%,exp); normal(%); evalf(%);
gives the value in the title (astonishingly not 64 digits ...)
ApproximateInt
ApproximateInt works correctly if you use an expression instead of a function, i.e.
ApproximateInt(f(t),t=x..y,method=simpson)
However, the syntax ApproximateInt(f, x..y) does not work. In fact, the result does not depend on f at all.
[ The <maple> tag is acting up again: that should be 1/2*b^2 - 1/2*a^2 ]
What seems to be happening is that Maple interprets this input as
ApproximateInt(f, f=a..b)
To be fair, the help page ?ApproximateInt does not mention this syntax at all, so ApproximateInt(f, x..y) is an error on the part of the user. However, this is definitely something that should be caught (either returning the same result as ApproximateInt(f(t), t=x..y) or an error message). I'm submitting an SCR.
evalf/Int
The more or less standard way is to use evalf/Int. Somehing like
It is interesting that the answer is different than in Axel Vogt's post above.
Another bug related to this is
Digits:=10: core2 := (t0,t1,a,b,g,d,dig)-> evalf(Int(h(u,a,b,g,d), u=2*t0/(d*g)..2*t1/(d*g),digits=dig)): core2(.5, 2.1, .5, 3, 3.14, 2.4, 6); 14 0.304448 10(But I am not submitting the SCR.)
Alec
looking closer
Mills' ratio
Thanks to all!
Thanks to all!