Long Numerical Integration: Is this possible with MATLAB?

In summary, I'm trying to integrate Pressure response of a horizontal observation well at a distance xd, yd and zd from a producer and I am getting an error. I have tried 'quad', 'quad8', 'trapz' and even a sum approach but it returns either a not-a-number answer or mtimes error or mrdivide error message. What I want to do is this (Pressure response of a horizontal observation well at a distance xd, yd and zd from a producer) but it is not working. Can MATLAB perform this integration?
  • #1
Edgarg
3
0
Please, I am new in MATLAB and need some help as to whether MATLAB can perform this integration, and how to go about it. I have tried 'quad', 'quad8', 'trapz' and even a sum approach but it returns either a not-a-number answer or mtimes error or mrdivide error message. What I want to do is this (Pressure response of a horizontal observation well at a distance xd, yd and zd from a producer)
integral= (1/(sqrt(td)))*(exp(yd^2/(4*td)))*(erf((1+xd)/(2*sqrt(td)))+erf((1-xd)/(2*sqrt(td))))*(1+2*(exp((-n^2*pi^2*td)/hd^2)*cos(n*pi*zwd)*cos(n*pi*((zd/hd)+zwd))));
xd, yd, zd, hd and zwd are constants.
i am integrating from 0 to td for td values of 0.001 to 10000
for each of the integral segment, 0.001 to 10000, (exp((-n^2*pi^2*td)/hd^2)*cos(n*pi*zwd)*cos(n*pi*((zd/hd)+zwd))) will be summed for n=1 to infinity. ie Ʃ(exp((-n^2*pi^2*td)/hd^2)*cos(n*pi*zwd)*cos(n*pi*((zd/hd)+zwd))) for n=1 to ∞

This is my recent attempt: where I did td =1 to 10000; and n= 1 to 100 just for it to work first.
----------------------
clc
x=2800;
y=0;
z=50;
zw=50.165;
kx=300;
ky=300;
kz=100;
l=1000; %well half length
h=100;
% t=150;
% td=(0.0002637*ky*t)/(phi*mu*ct*xf.^2)
k=nthroot(kx*ky*kz,3);
xd = x/l*sqrt(k/kx);
yd = y/l*sqrt(k/ky);
zd = z/h;
zwd=zw/h;
hd = h/l*sqrt(k/kz);
for i = 1:1e+1:10000
for j=1:100
int(i,j)= (1./(sqrt(td(i)))).*(exp(yd.^2./(4.*td(i)))).*(erf((1+xd)./(2.*sqrt(td(i))))+erf((1-xd)./(2.*sqrt(td(i))))).*(1+2.*(exp((-n(j)^2.*pi^2.*td(i))./hd.^2).*cos(n(j)*pi*zwd).*cos(n(j)*pi*((zd./hd)+zwd))));
end
end
p=sum(int*10,3)

Error: ? Undefined function or method 'td' for input arguments of type 'double'.
**The attached document contains the equation.
 
Physics news on Phys.org
  • #2
I'm having trouble understanding this. Is this all of your code? You don't have a definition for td.
 
  • #3
Yes, I am integrating with respect to td. So, I did not define td.
Lower integral limit is zero, and I will have several upper limits of 0.001 to 10000 with varying intervals. The equation contains a sum series within.
Equation is:
integral= (1/(sqrt(td)))*(exp(yd^2/(4*td)))*(erf((1+xd)/(2*sqrt(td)))+erf((1-xd)/(2*sqrt(td))))*(1+2*Ʃ(exp((-n^2*pi^2*td)/hd^2)*cos(n*pi*zwd)*cos(n*pi*((zd/hd)+zwd))))
the sigma is for n=1 to infinity.
 
  • #4
If you're using it as a symbolic variable, you need to define it using
Code:
syms td;

I don't know if there are alternate syntaxes for integrating, but AFAIK it's normally

Code:
int(expr,var)

so your code would be

Code:
syms td
int((1./(sqrt(td(i)))).*(exp(yd.^2./(4.*td(i)))).*(erf((1+xd)./(2.*sqrt(td(i))))+erf((1-xd)./(2.*sqrt(td(i))))).*(1+2.*(exp((-n(j)^2.*pi^2.*td(i))./hd.^2).*cos(n(j)*pi*zwd).*cos(n(j)*pi*((zd./hd)+zwd)))),td)

or something like that. If you're trying to integrate numerically rather than symbolically, then you should evaluate the function first and then integrate it, and you would need to define td.
 
  • #5
Thanks, let me try it.
 

FAQ: Long Numerical Integration: Is this possible with MATLAB?

What is long numerical integration?

Long numerical integration is a method used to approximate the value of a definite integral over a large interval, often with a complex integrand. It involves breaking the interval into smaller subintervals and performing numerical integration on each subinterval.

Is it possible to perform long numerical integration with MATLAB?

Yes, MATLAB has built-in functions and tools for performing numerical integration, including long numerical integration. These tools are part of the core MATLAB software and can be accessed through the command window or by using the integral function.

What are the advantages of using MATLAB for long numerical integration?

MATLAB is a powerful and versatile software that allows for efficient and accurate numerical calculations. It has a wide range of built-in functions and tools specifically designed for numerical integration, making it a convenient choice for long numerical integration. Additionally, MATLAB's syntax and structure make it easy to write and modify code for different integration methods.

Are there any limitations to using MATLAB for long numerical integration?

While MATLAB is a popular and effective tool for numerical integration, it does have some limitations. One limitation is that it may not be the most efficient option for very large or complex integrals, as it relies on iterative methods that can be computationally intensive. Additionally, MATLAB may not be suitable for certain specialized integration techniques.

Can I customize the integration method when using MATLAB for long numerical integration?

Yes, MATLAB allows for customization of the integration method through its integral function. Users can specify the type of integration method (e.g. Simpson's rule, trapezoidal rule) and adjust parameters such as the number of subintervals and tolerance level. This allows for flexibility in finding the most accurate and efficient solution for a given integral.

Similar threads

Replies
1
Views
3K
Replies
3
Views
875
Replies
10
Views
2K
Replies
13
Views
2K
Replies
5
Views
2K
Back
Top