Integration of a vector with hyperbolic function

4 views (last 30 days)
Hi,
I am trying to integrate a symbolic vector containing hyperbolic sin and cosine functions in a range of 0.05 to1. However, on doing so I get some very high values of the order of 10^193, 10^144 and 10^44 and a finite value of the order 1. Also, these higher order terms appear with positive and negative pair, but on summing up the vector elements to get the final value of integration I get a very high value of the order of 10^(178). It is happening because of difference between these higher order terms after 15 or 16 significant digits. I know that the sum of the elements have a finite value (checked on Maple), however, it is not happening in Matlab. I really appeciate if someone can help me out. I am attaching matlab file for reference.
With regards
Sunit

Accepted Answer

David Goodmanson
David Goodmanson on 7 May 2020
Edited: David Goodmanson on 7 May 2020
Hi Sunit,
Thanks for annotating the code and providing the expressions as comments.
The key here is with the C1 coefficients
C1(2,3:4)
ans = 0.951325686847860 -0.951325686847860
Since these are exact negatives of each other, you can rewrite the last half of y2,
C1(2,3) * sinh(beta * x) + C1(2,4) * cosh(beta * x))
as
-C1(2,3) * exp(-beta * x)
that is, a decreasing exponential only. The resulting code does not have to subtract monstrously large increasing exponentials from each other.
Since you are interested in a numerical result I did the calculations numerically so as to avoid syms expressions whose length can get out of control and are generally not the best for trying to find intermediate results.
%numerical values of parameters
coeff1 = [1.000000000000000, 0, -0.22069165109e-4, 0, ...
0.764799945371359, 0.36674613077895e-1, 0.95132568684786 -.95132568684786];
C1=zeros(2,4);
C1(1,:)=coeff1(1:4);
C1(2,:)=coeff1(5:8);
omega_y=351.5546;
s=80.33
alpha=sqrt(-s ^ 2 + sqrt(s ^ 4 + omega_y ^ 2));
beta=sqrt(s ^ 2 + sqrt(s ^ 4 + omega_y ^ 2));
% expressions
y1 = @(x) ((C1(1,1) * sin(alpha * x) + C1(1,2) * cos(alpha * x) ...
+ C1(1,3) * sinh(beta * x) + C1(1,4) * cosh(beta * x)));
y14 = @(x) y1(x).^4;
Int1 = integral(y14,0,1/20)
y2 = @(x) (C1(2,1) * sin(alpha * x) + C1(2,2) * cos(alpha * x) ...
- C1(2,3) * exp(- beta * x));
y24 = @(x) y2(x).^4;
Int2 = integral(y24,1/20,1)
Int1 = 5.402540320261473e-06
Int2 = 0.130888580616070
  3 Comments
David Goodmanson
David Goodmanson on 8 May 2020
Hi Sunit,
if by "when C1(2,3) and C1(2,4) are not negative" you mean that they are not equal with opposite sign, then in general you may not be able to do the integral because the integrand will become too large. Abbreviating the two constants involved by C3 and C4, for the second part of y2 you have
C3* (exp(beta*x)- exp(-beta*x))/2 + C4* (exp(beta*x)+ exp(-beta*x))/2
= ((C3+C4)/2)*exp(beta*x) + ((-C3+C4)/2)*exp(-beta*x)
The importance of C3+C4 = 0 is not really that it simplifies the expression but rather that it eliminates the exp(beta*x) term which can become really large, especially when it's part of an expression taken to the fourth power. There is cancellation if and only if C3+C4=0
Farhad Azad
Farhad Azad on 1 Mar 2021
Dear David,
I'm going to calculate conductivity of graphene. so I forced to calculate an infinite integral containing hyperbolic sin and cos. I wrote a matlab code to do that, But it diverged. would you please check my matlab code, and give me your advices to correct it's errors.
my m-file has been attached.
Best Regards
Farhad Azadpour

Sign in to comment.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!