Processing math: 100%
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

(Not an answer, but a note needing more space than one allowed in a comment. I'll update this answer if necessary)

What version of Sage do you use ? At least with Sagemath 9.4.rc1, piecewise functions seem problematic :

sage: var("a, j, k, L")
(a, j, k, L)
sage: int1(a, j, k, L) =  piecewise([[[0, 1/4], 1 * cos(pi * (j + 1) * a/L) * cos(pi * (k + 1) * a/L)], [(1/4, 3/4), 2 * cos(pi * (j + 1) * a/L) * cos(pi * (k + 1) * a/L)], [[3/4, 1], 1 * cos(pi * (j + 1) * a/L) * cos(pi * (k + 1) * a/L)]])

So far so good. but :

sage: int1(a, j, k, L)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-162-c48732677c56> in <module>
----> 1 int1(a, j, k, L)

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression._eval_on_operands.new_f (build/cythonized/sage/symbolic/expression.cpp:70643)()
  13102         new_args = list(ex._unpack_operands())
  13103         new_args.extend(args)
> 13104         return f(ex, *new_args, **kwds)
  13105     return new_f
  13106 

TypeError: __call__() takes from 3 to 4 positional arguments but 7 were given

Ditto when calling with numerical arguments. This could be a newly-introduced bug...

BTW, I do not see the point of using numerical integration in this specific case : your function f1 can be described as :

f0:(a,j,k,L)  cos(πajL+πaL)cos(πakL+πaL)

f1:{f0(a,j,k,L)a<142f0(a,j,k,L)a14a34f0(a,j,k,L)a>34

Your integral 10f1(a,j,k,l)da is simply 140f0(a,j,k,l)da+34142f0(a,j,k,l)da+134f0(a,j,k,l)da.

Since

f0(a,j,k,l)=(LjLk)sin(πajL+πakL+2πaL)(Lj+Lk+2L)sin(πajL+πakL)2(πj2πk2+2πj2πk)

your (definite) integral, which is a function of j, k and L, has an explicit (closed form) expression (which my laziness leaves to the reader as an exercise...).

HTH,