How to include average of a variable in the equation setup of PDEPE
1 回表示 (過去 30 日間)
古いコメントを表示
Hi everyone!
I am using PDEPE to solve a set of partial differential equations over space (x) and time. My equation is
, where
is the average of all the values of G from 0 to x. G is also a variable in this set of partial differential equations. How can I add this G_avg function?


Edit: I wont be able to do it this way - One way I know is to run the solver from [t,t+Δt], obtain G(x) for that value of time, feed back the G_avg and then run the solver again. Can I do it without this method?
Thanks!
0 件のコメント
回答 (1 件)
Nipun
2024 年 6 月 6 日
Hi Jairaj,
I understand that you want to solve a PDE using "pdepe" in MATLAB where the equation involves an average function "G_avg". Here's a possible approach to include "G_avg" without iterating through time steps manually:
function sol = solvePDE()
% Define the PDE coefficients
m = 0; % Symmetry parameter for pdepe (0 for slab, 1 for cylindrical, 2 for spherical)
% Time and space discretization
x = linspace(0, 1, 100); % Spatial domain
t = linspace(0, 10, 50); % Time domain
% Solve the PDE
sol = pdepe(m, @pdefun, @icfun, @bcfun, x, t);
% Plot results
surf(x, t, sol(:,:,1));
title('Solution of the PDE');
xlabel('Space x');
ylabel('Time t');
zlabel('F(x,t)');
end
function [c, f, s] = pdefun(x, t, u, dudx)
% Calculate G_avg(x)
global G_values G_avg C;
G_avg = trapz(G_values(1:find(x==G_values,1)))/x; % Approximate integral
% Define PDE
c = 1;
f = dudx;
s = G_avg - C;
end
function u0 = icfun(x)
% Initial condition
u0 = 0;
end
function [pl, ql, pr, qr] = bcfun(xl, ul, xr, ur, t)
% Boundary conditions
pl = ul;
ql = 0;
pr = ur - 1;
qr = 0;
end
In this approach, "G_avg" is calculated within the "pdefun" function. This allows you to avoid iterating through time steps manually. Ensure you define "G_values" and "C" in your workspace before running the solver.
Hope this helps.
Regards,
Nipun
1 件のコメント
Torsten
2024 年 6 月 6 日
編集済み: Torsten
2024 年 6 月 6 日
This won't work since G is also a variable in the system of partial differential equations, thus a component of the u vector. And the solution u is input to "pdefun" separately for each grid point so that no average can be computed there over all grid points.
参考
カテゴリ
Help Center および File Exchange で PDE Solvers についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!