how to output quantities within pdefun, bcfun, icfun in pdepe
4 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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
0 件のコメント
その他の回答 (1 件)
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
参考
カテゴリ
Help Center および File Exchange で Eigenvalue Problems についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!