Is there a possibility to calculate definite integrals of sum of products of sines/cosines with cosh/sinh with mp-objects?
Yes, of course. Toolbox provides full spectrum of numerical integration routines - from fixed Gauss quadrature to adaptive quadgk.
Or did you mean something else?
For example, I would like to calculate the definite integral "int(sin(b*x)*cosh(c*x)" in the variable x over the interval [0,L], in which b,c and L are constant values (which I defined as mp-objects).
Define your integrand as a function, call quadgk with corresponding parameters.
Make sure the values 0, L and tolerance are also of mp-type. Toolbox will detect the mp-objects and will call its own multiprecision version of quadgk.
Let me know how it works.
Here is simple example for demonstration:
f = @(x)sin(x);
[q,errbnd] = quadgk(f,mp(0),mp(1),'RelTol',100*mp.eps,'AbsTol',100*mp.eps, 'MaxIntervalCount', 1000000)
Can I also use this to create a matrix of solutions, since I need to calculate these integrals with varying coefficients b and c?
Yes, of course, toolbox follows standard Matlab syntax and rules.
If you can do something with standard Matlab - most likely it can be done with toolbox too.
I couldn't find your last comment (did you delete it?).
Just few comments on the code.
The function should be able to accept the vector-parameters (quadqk is a vectorized method). So instead of
f = @(x)(cos(p*x)+cosh(p*x)+q*sin(p*x)+q*sinh(p*x))*(cos(r*x)+cosh(r*x)+s*sin(r*x)+s*sinh(r*x));
use element-wise multiplication:
f = @(x)(cos(p*x)+cosh(p*x)+q*sin(p*x)+q*sinh(p*x)).*(cos(r*x)+cosh(r*x)+s*sin(r*x)+s*sinh(r*x));
Also be careful with precision and interval counts. My example shows extreme values, please use more reasonable at first, e.g.:
[q,errbnd] = quadgk(f,mp(0),L,'RelTol',100*mp.eps(),'AbsTol',100*mp.eps(), 'MaxIntervalCount', 650)
Quadgk will warn you if it needs more levels of recursion (MaxIntervalCount)
Thank you for your assistance! You've been of great help!
I can't seem to numerically stabilize my code (see below). I expect the diagonal elements in the matrix "Ortho" to be equal to L (here = 10) and the off-diagonal elements equal to zero. I'm trying to prove the orthogonality of the function f...
I am not sure, probably you need to use better precision (from numerical point of view).
But why don't you compute the integral analytically?
Try using Maple or Mathematica. I have just tried Maple - it gave long but sensible expression for the any r,p,q,s.
Customer support service by UserEcho