(How) Can I (numerically) integrate u from z=0 to z=z in a=acoeffun​ction(loca​tion,state​), when using PDE toolbox and a PDEModel for general PDE?

1 view (last 30 days)
I am in the process of figuring out if I can use either pdepe.m or the Partial Differential Equation Toolbox to solve a set of two partial differential equations,
and ,
where and .
The problem I'm having, is that the following integral needs to be evaluated in both and :
at each time-step and for each depth z in the "depth-mesh".
As far as I can tell, using pdepe.m is not feasible, since the input u in pdefun is a Nx1 vector, where N is the number of equations in your system.
I was hoping that using the Partial Differential Equation Toolbox, eventhough it's intended use is for PDEs with two or more spatial variables, would allow me to integrate numerically from z=0 to z= current depth.

Answers (1)

SAI SRUJAN
SAI SRUJAN on 16 Mar 2024
Hi Anita,
I understand that you are trying to integrate'u' from 'z=0' to 'z=z'.
Given that you are solving a set of two partial differential equations and need to perform an integral at each time step and for each depth ('z') in the depth mesh, here's a general approach to accomplish this:
% define model
model = createpde();
% specify PDE coefficients
specifyCoefficients(model, 'm',0, 'd',0, 'c',c_coeff, 'a',a_coeff, 'f',f_func);
% solve the PDE for the time span of interest.
result = solvepde(model, tlist);
% Assume 'z_values' are the z-coordinates and 'u_values' are the solution values
z_values = ...; % Extract from the mesh
u_values = ...; % Extract from 'result'
% Integrate from z=0 to z=z_current
z_current_index = find(z_values <= z_current, 1, 'last');
integral_value = trapz(z_values(1:z_current_index), u_values(1:z_current_index));
For numerical integration, MATLAB's 'trapz' function or the 'integral' function can be used. Please refer to the following documentation to understand more about the forementioned MATLAB functions.
I hope this helps!
  3 Comments
Torsten
Torsten on 12 Aug 2024
Edited: Torsten on 12 Aug 2024
If an answer is still of interest after 2 1/2 years:
You can use
This code is a variant of MATLAB's "pdepe", but the vector u is supplied in all grid points x for each time t. This makes it possible to use MATLAB's "trapz" to evaluate the integral.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!