assempde: Passing parameters to coefficient files for a, b, and c

2 views (last 30 days)
I'm using assempde to solve a system of PDEs for which the coefficient matricies "a", "c" and "f" are functions of space. After reading through the PDE toolbox documentation, I've made a workable code in which the names of m-files defining these matricies (i.e. "coefficient files" in the Matlab lingo) are passed to assempde. The trouble is, these m-files (as described in the documentation) can only accept specific inputs e.g. "a = a_fun(p,t,u,t0)", such that any parameters defining how "a" should vary need to be either hard-wired into the a_fun.m function, or passed to it using a global variable.
I'd really like to avoid using globals - particularly because I want to scan my parameters in a parallel for-loop. Does anyone know another way???

Accepted Answer

Alex Degeling
Alex Degeling on 12 Oct 2012
(Finally!) I figured out a solution using function handles: The following works when solving a scalar pde problem. See below for the pde system case... Scalar pde: 1) Create a function for C (or A, or F, etc) which uses the additional parameters C = C_fun(p,t,u,time,additional_parameters)
2) In the code calling assempde, create function handles for the coefficients eg: C_h = @(p,t,u,time)C_fun(p,t,u,time,additional_params); A_h = @(p,t,u,time)A_fun(p,t,u,time,additional_params); bc_h = @(p,t,u,time)bc_fun(p,t,u,time,additional_params); f_h = @(p,t,u,time)f_fun(p,t,u,time,additional_params);
3) Call assempde using the above function handles: u = assempde(bc_h,p,e,t,C_h,A_h,f_h)
System of pde's: If the above steps are used when you have a system of PDE's, then an error is given by assema.m saying that the number of rows in C is incorrect. This is because the number of rows N is defined by the number of rows in f. However, there's a bug in this code: the number of rows in f is evaluated from the number of rows in input argument for f (line 100 in assema.m). Hence, if f_h in the above example contains a single row (as is the case for a function handle) then N is set to 1. The actual evaluation of the f in assema.m occurs at the end of the program (lines 234 and down), starting with f=pdetfxpd(p,t,uu,time,f); If this is section of the code is simply moved above line 100, then f has number of rows given to it by the evaluation of the input argument for f (which should be N) and the bug is fixed.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!