How to correctly code the expression with Ei function?

In summary: You can fix this by separating the for loop into two lines:for i=1:1:st(1)rd=r(1:nr)/wb*td=0.0036*k*t(i)/(phi*mu*c*wb^2)pd=((pi*h*k)/(1.842*q*1.1*mu))*(IP-p(i,1:nr))endforfor i=1:1:st(1)rd=r(1:nr)/wb*td=0.0036*k*t(i)/(phi*mu*c*wb^2
  • #1
Ein Krieger
34
0
Hi,

I am trying to incorporate the following equation into Matlab in the red:

http://http://www.radikal.ru][PLAIN]http://s018.radikal.ru/i518/1305/16/1cc0d2a72d38.jpg

The following data is to be used:
t=3000000
nr=nx=161
q=0.02
k=5e-13
mu=0.00035
c=1.5e-8
phi=0.25
rw=0.1
h=4.5


My code is below:
st=size(t)
nr=nx;
for i=1:1:st(1)
rd=r(1:nr)/wb
td=0.0036*k*t(i)/(phi*mu*c*wb^2)
pd=((pi*h*k)/(1.842*q*1.1*mu))*(IP-p(i,1:nr))
Ei_from_mfun=mfun('Ei',1,-rd^2/(4*td))
pd=1/2*Ei_from_mfun
plot(time,pd,'bo')
end

But it gives the following command :
"? Index exceeds matrix dimensions."

Can you please help to fix the problem for every time, t and pressure,p?

Thanks
 
Physics news on Phys.org
  • #2
Provide the analytic formulation and tidy your code a little, pls.
E.g. comments and indentation would not hurt; there a "code tags" button in the editor widget you can use to preserve indentation blanks in the code block.
 
  • #3
Solkar said:
Provide the analytic formulation and tidy your code a little, pls.
E.g. comments and indentation would not hurt; there a "code tags" button in the editor widget you can use to preserve indentation blanks in the code block.

Here is the equation to be solved :

ff5083bd4721.jpg


The red equation belowi the analytical solution I want to get solution for.

The data to be used:
The following data is to be used:
t=3000000
r=nr=nx=161
q=0.02
k=5e-13
mu=0.00035
c=1.5e-8
phi=0.25
rw=0.1
h=4.5

My code is below:

Code:
st=size(t)
nr=nx;
for i=1:1:st(1)
rd=r(1:nr)/wb
td=0.0036*k*t(i)/(phi*mu*c*wb^2)
pd=((pi*h*k)/(1.842*q*1.1*mu))*(IP-p(i,1:nr))
Ei_from_mfun=mfun('Ei',1,-rd^2/(4*td))
pd=1/2*Ei_from_mfun
plot(time,pd,'bo')
end

But it gives the following command :
"? Index exceeds matrix dimensions."
 
Last edited:
  • #4
t is a constant.

st=size(t) is then equal to [1 1]

the for loop runs through for i=1, but then halts on i=2 because you have t(i), and t(2) doesn't exist.
 
  • #5
for reaching out! I can definitely help you with your code.

First, let's take a look at the equation that you are trying to code:

http://s018.radikal.ru/i518/1305/16/1cc0d2a72d38.jpg

This equation involves several variables, including t, nr, q, k, mu, c, phi, rw, and h. It also includes the Ei function, which is the exponential integral function.

To correctly code this expression, you will need to first define all of the variables and their corresponding values, as you have already done in your code. Then, you will need to use the Ei function to calculate the value of pd for each time step.

Here is an example of how you can code this expression in Matlab:

% Define variables
t = 3000000; % time
nr = 161; % number of points
q = 0.02; % flow rate
k = 5e-13; % permeability
mu = 0.00035; % viscosity
c = 1.5e-8; % compressibility
phi = 0.25; % porosity
rw = 0.1; % well radius
h = 4.5; % height

% Calculate pd for each time step
for i = 1:length(t)
rd = (1:nr)/wb;
td = 0.0036*k*t(i)/(phi*mu*c*wb^2);
pd = ((pi*h*k)/(1.842*q*1.1*mu))*(IP - p(i,1:nr));
pd = 1/2*expint(-rd.^2/(4*td));
plot(time,pd,'bo');
end

Note that I have used the "expint" function in place of the "Ei" function, as it is the equivalent in Matlab. Also, I have used the "length" function to determine the number of time steps instead of "size", as it returns the total number of elements in the vector t.

I hope this helps and please let me know if you have any further questions or if you encounter any other issues with your code.
 

1. What is the Ei function and what does it represent?

The Ei function, also known as the exponential integral function, is a mathematical function that is used to evaluate integrals of the form ∫ex/xndx. It is used in various scientific fields, such as physics, engineering, and statistics.

2. How do I correctly code the Ei function in my program?

The Ei function is typically coded using the notation "Ei(x)" or "expint(x)" in most programming languages. Make sure to check the specific syntax and parameters for your programming language to ensure accurate coding.

3. Can the Ei function be used to solve equations with complex numbers?

Yes, the Ei function can be used to solve equations with complex numbers. However, the result may also involve complex numbers, so it is important to understand the properties and limitations of the function before using it in complex equations.

4. Are there any alternative functions that can be used instead of the Ei function?

Yes, there are alternative functions that can be used instead of the Ei function, such as the Dawson function or the incomplete gamma function. These functions may have different properties and may be more suitable for certain types of equations.

5. Can the Ei function be graphed or visualized?

Yes, the Ei function can be graphed or visualized using mathematical software or programming languages. The graph of the function will show the relationship between the input and output values, allowing for a better understanding of its behavior and properties.

Back
Top