How to include average of a variable in the equation setup of PDEPE

조회 수: 1 (최근 30일)
Jairaj Mathur
Jairaj Mathur 2021년 4월 30일
편집: Torsten 2024년 6월 6일
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!

답변 (1개)

Nipun
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
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 CenterFile Exchange에서 PDE Solvers에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by