On Fri, 9 Oct 2009, Stanislav Maslovski wrote:
< Hello,
<
< I am trying to plot this simple Fourier integral in Maxima 5.17.1:
<
< (%i1) display2d : false$
<
< (%i2) f(k):=integrate(exp(%i*k*x)*sin(x)/x,x,minf,inf)$
<
< (%i3) [f(0), f(1), f(3/2)];
<
< (%o3) [%pi,%pi,0]
<
< So far so good.
<
< (%i4) plot2d(f,[x,-3,3]);
<
< (%o4)
< (%i5) Warning: empty y range [0:0], adjusting to [-1:1]
<
< Theoretically, f(k) must be equal to %pi for k in [-1;1] and 0
< outside. The plot does not show anything in [-1;1].
<
< Moreover, if I try this plotting command
<
< plot2d(f(k),[k,-3,3]);
<
< I get a stupid question about the sign of k-1.
<
< Can anyone explain what is wrong here?
There are a few things. The integral, f(k), is a piece-wise constant
function. At the moment, Maxima lacks the ability to return an answer in
this form. Work is being done to correct this.
I would suggest that you try the following definition:
(%i2) f(t) ::= buildq([k:t],
integrate(exp(%i*k*x)*sin(x)/x,x,minf,inf));
(%o2) f(t)::=buildq([k:t],integrate(exp(%i*k*x)*sin(x)/x,x,minf,inf))
This will avoid any calls to 'asksign' (which is asking about the sign
of k) when t is a constant. I have also set ratprint to false to avoid
the annoying warnings about floats being converted to rationals.
(%i3) l : makelist(i/10,i,-20,20)$
(%i4) fl : float(map(f,l));
(%o4) [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,3.141592653589793,
3.141592653589793,3.141592653589793,3.141592653589793,
3.141592653589793,3.141592653589793,3.141592653589793,
3.141592653589793,3.141592653589793,3.141592653589793,
3.141592653589793,3.141592653589793,3.141592653589793,
3.141592653589793,3.141592653589793,3.141592653589793,
3.141592653589793,3.141592653589793,3.141592653589793,
3.141592653589793,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
(%i5) plot2d([discrete,l,fl]);
This plots what you want.
Incidentally, you will find that this is very slow. The problem is that
the integral is being recomputed each time f is evaluated. What you
would really want to do is to compute the integral once, as a symbolic
facility is under development.
Note that you can also use 'assume':
(%i35) [ (map(forget,facts()), assume(k<-1),f(k)) , (forget(k<-1),
assume(k>1),f(k)) , (forget(k>1), assume(k>-1,k<1),f(k)), f(-1), f(1) ];
(%o35) [0,0,%pi,0,%pi]
Leo
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.