필터 지우기
필터 지우기

how to output quantities within pdefun, bcfun, icfun in pdepe

조회 수: 3 (최근 30일)
feynman feynman
feynman feynman 2024년 2월 12일
이동: Torsten 2024년 2월 12일
How to output quantities within pdefun, bcfun, icfun in pdepe? e.g. in pdefun:
function [c,f,s] = heatcyl(x,t,u,dudx)
c = 1;
f = dudx;
s = 0;
end
e.g. I want to output an extra quantity ex related to some intermediate value in pdefun, sth like [c,f,s,ex]=heatcyl(x,t,u,dudx), but which I'm sure isn't allowed.
Also want to output ic, but don't know the syntax, because feval(@ic,x) or pdeval(m,x,ic,x) doesn't work.

채택된 답변

Torsten
Torsten 2024년 2월 12일
이동: Torsten 2024년 2월 12일
After pdepe has finished, call "heatcyl" at the output times.
x = linspace(0,1,25);
t = linspace(0,1,25);
m = 1;
sol = pdepe(m,@heatcyl,@heatic,@heatbc,x,t);
ex = zeros(numel(t),numel(x));
for i = 1:numel(t)
[~,dudx] = pdeval(m,x,sol(i,:,1),x);
for j = 1:numel(x)
[~,~,~,ex(i,j)] = heatcyl(x(j),t(i),sol(i,j,1),dudx(j));
end
end
function [c,f,s,ex] = heatcyl(x,t,u,dudx)
c = 1;
f = dudx;
s = 0;
ex = c+1;
end
%----------------------------------------------
function u0 = heatic(x)
n = 2.404825557695773;
u0 = besselj(0,n*x);
end
%----------------------------------------------
function [pl,ql,pr,qr] = heatbc(xl,ul,xr,ur,t)
n = 2.404825557695773;
pl = 0; %ignored by solver since m=1
ql = 0; %ignored by solver since m=1
pr = ur-besselj(0,n)*exp(-n^2*t);
qr = 0;
end

추가 답변 (1개)

recent works
recent works 2024년 2월 12일
In MATLAB's pdepe solver, the output arguments from pdefun, bcfun, and icfun are limited to the standard ones (c, f, s for pdefun, and pl, ql, pr, qr for bcfun). If you need to output additional quantities or evaluate the initial condition at specific points, you have to find alternative methods. To handle additional quantities within the pdefun, you can utilize global variables or nested functions to store and access these values. However, this approach is not very clean and can lead to potential issues with code readability and maintainability. Regarding evaluating the initial condition (ic), you can use pdeval after solving the PDE to evaluate the solution at any desired points. Here's how you can use pdeval to evaluate the initial condition at specific points:
% Define your PDE system
m = 0; % No of spatial variables
x = linspace(x_start, x_end, num_points);
t = linspace(t_start, t_end, num_time_points);
sol = pdepe(m,@pdefun,@icfun,@bcfun,x,t);
% Evaluate the solution at specific points
x_points_of_interest = [x1, x2, x3]; % Define the points where you want to evaluate the solution
t_points_of_interest = [t1, t2, t3]; % Define the time points where you want to evaluate the solution
u_at_points = pdeval(m, x, sol(end,:,:), x_points_of_interest);
u_at_time_points = pdeval(m, x, sol, t_points_of_interest);
  • x_points_of_interest and t_points_of_interest are the spatial and temporal points where you want to evaluate the solution.
  • sol(end,:,:) extracts the solution at the final time step.
  • pdeval is then used to evaluate the solution at these points.
Remember to replace x_start, x_end, num_points, t_start, t_end, num_time_points, x1, x2, x3, t1, t2, and t3 with appropriate values relevant to your problem.
If you need to access quantities calculated during intermediate steps of the PDE solving process, you might need to modify the solver itself
  댓글 수: 1
feynman feynman
feynman feynman 2024년 2월 12일
thank you! To extract x and t intrinsic solution data isn't hard, but what about extra quantities? e.g. does this work and if so, what's the syntax for extracting ex from heatcyl?
function [c,f,s,ex] = heatcyl(x,t,u,dudx)
c = 1;
f = dudx;
s = 0;
ex=c+1;
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Eigenvalue Problems에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by