# How can I solve PDE with boundary condition?

2 views (last 30 days)
Riyadh Muttaleb on 17 Aug 2017
Commented: Riyadh Muttaleb on 30 Aug 2017
Hi All, I do have Ws dC/dz + Kc d2C/dz2 - X=0 where Ws and X are constant Z from (0 to 5 step 0.5) and I do have Kc values each 0.5 m,
How can I solve this PDE with Matlab, using B.C. (C at 0= 10) and (C at 5 =0)
Kuifeng on 18 Aug 2017
Example answer, Ref to Chap 5, Part 5.2 Steady 1D Convection and diffusion of 'An introduction to computational fluid dynamics 2nd edition' by Versteeg and Malalasekera

Torsten on 18 Aug 2017
Use "bvp4c".
By the way: this is a second-order ODE, not a PDE.
Best wishes
Torsten.
Riyadh Muttaleb on 19 Aug 2017
Thank you

Precise Simulation on 24 Aug 2017
Alternatively, if you still prefer to solve it as a PDE, you can quite easily input and solve it with the FEATool Multiphysics FEM Finite Element toolbox directly in Matlab. The small m-script below shows how this can be achieved
% FEATool FEA problem definition.
fea.sdim = {'z'}; % Space coordinate/dimension name.
fea.dvar = {'C'}; % Dependent variable name.
fea.sfun = {'sflag1'}; % 1st order P1 FEM shape function.
s_eqn = 'Ws*Cz + Kc*Cz_z - X = 0'; % String equation definition.
fea.eqn = parseeqn( s_eqn, fea.dvar, fea.sdim );
fea.grid = linegrid( 10, 0, 5 ); % Line grid/mesh.
fea.coef = { 'Ws' 1; 'Kc' '2*z'; 'X' '3' }; % Equation coefficents/expressions.
fea.bdr.d = {10 0}; % Dirichlet BCs.
fea.bdr.n = {[] []}; % (Optional) Neumann BCs.
% Check, parse, and solve FEA problem.
fea = parseprob( fea );
fea.sol.u = solvestat( fea );
% Postprocess and visualize solution.
postplot( fea, 'surfexpr', 'C' )
Riyadh Muttaleb on 30 Aug 2017
Sorry for late response, In was in small vacation, I tried to implement the m-script, but an error says that "Undefined function or variable 'parseeqn'"
Thank you,