(How) Can I (numerically) integrate u from z=0 to z=z in a=acoeffunction(location,state), when using PDE toolbox and a PDEModel for general PDE?
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
SAI SRUJAN
2024-3-16
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!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General PDEs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!