Integration of a vector with hyperbolic function

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

 Respuesta aceptada

David Goodmanson
David Goodmanson el 7 de Mayo de 2020
Editada: David Goodmanson el 7 de Mayo de 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 comentarios

Sunit Gupta
Sunit Gupta el 8 de Mayo de 2020
Hi David,
Thanks for the answer and helping me out. I really appreciate it. Yes, i completely missed the part that C1(2,3) and C(2,4) are positive and negative quantities and can be cancel out to simplify this expression. But in a general case when C1(2,3) and C1(2,4) are not negative how can I cancel out these terms. In this matlab code I was trying to round off these numbers to 6 significant digits but i was failing for that task. How should I add elements of b4_2 such that it will be give me a finite answer (for my future references).
Thanks for the help though. If you think that I need to post another question regarding that then please let me know.
Thanks a lot
With Regards
Sunit
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 el 1 de Mzo. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Productos

Versión

R2019a

Preguntada:

el 7 de Mayo de 2020

Comentada:

el 1 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by