1 / 59

CHEE 412 Partial Differential Equations in MATLAB

CHEE 412 Partial Differential Equations in MATLAB. Hadis Karimi Queen’s University March 2011. Introduction. Parabolic partial differential equations are encountered in many chemical engineering applications MATLAB’s pdepe command can solve these

yered
Download Presentation

CHEE 412 Partial Differential Equations in MATLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CHEE 412Partial Differential Equations in MATLAB Hadis Karimi Queen’s University March 2011

  2. Introduction • Parabolic partial differential equations are encountered in many chemical engineering applications • MATLAB’s pdepe command can solve these • For partial dierential equations in two space dimensions PDE Toolbox can solve four types of equations: Elliptic, Parabolic, Hyperbolic and Eigenvalue

  3. Agenda • Solving a parabolic PDE in MATLAB using “pdepe” function • A mass transfer example • A heat transfer example • Solving a system of parabolic PDE’s in MATLAB using “pdepe” function • A mass transfer example • Solving other types of PDE’s using PDE toolbox • A heat transfer example using PDE toolbox

  4. PDE in One Space Dimension • The form of Parabolic PDE’s in MATLAB • Boundary conditions • Initial conditions m=0 for Cartesian, for cylindrical, 1 and for spherical 2

  5. Example 1: A Mass Transfer System X=L2

  6. Initial Conditions X=L2 @ t=0

  7. Boundary Conditions X=L3

  8. Steps to Solve PDE’s in MATLAB 1- Define the system 2- Specify boundary conditions 3- Specify initial conditions 4- Write System m-file 5-Write Boundary Conditions m-file 6- Write Initial condition m-file 7-Write MATLAB script M-file that solves and plots

  9. 1- Define the System

  10. 2-Specify Boundary Conditions

  11. 3- Specify Initial Conditions

  12. 4- Write System m-file function [c,b,s] = system(x,t,u,DuDx) c = 1; b =D1*DuDx; s = 0; end

  13. 5-Write Boundary Conditions m-file function [pl,ql,pr,qr] = bc1(xl,ul,xr,ur,t) pl = 0; ql = 1/D1; pr = 0; qr = (D2-D1)/D1; end

  14. 6- Write Initial Conditions m-file function value = initial1(x) value = C0; end

  15. 7-Write MATLAB script M-file that solves and plots m = 0; %Define the solution mesh x = linspace(0,1,20); t = linspace(0,2,10); %Solve the PDE u = pdepe(m,@system,@initial1,@bc1,x,t); %Plot solution surf(x,t,u); title('Surface plot of solution.'); xlabel('Distance x'); ylabel('Time t');

  16. Results

  17. Example 2: A Heat Transfer System L q” T=0 x

  18. Defining System

  19. Defining System function [c,b,s]=pdecoef(x,t,u,DuDx) global rho cp k c=rho*cp; b=k*DuDx; s=0; end

  20. Initial Conditions function u0=pdeic(x) u0=0; end

  21. Boundary Conditions x=0 p=q” q=1 or Remember x=L p=T=ur q=0

  22. Writing Boundary Condition m-file function[pl,ql,pr,qr]=pdebc(xl, ul,xr,ur,t) global q pl=q; ql=1; pr=ur; qr=0; end

  23. Calling the Solver tend=10; m=0; x=linspace(0,L,200); t=linspace(0,tend,50); sol=pdepe(m,@pdecoef,@pdeic,@pdebc,x,t);

  24. Plotting Temperature=sol(:,:,1); figure plot(t,Temperature(:,1))

  25. System of PDE’s in MATLAB

  26. Boundary Conditions

  27. Initial Conditions

  28. Example 3: Mass Transport in the Saliva Layer Mucosa Blood Stream Saliva Drug Transport Direction Lozenge RL RS RM

  29. Boundary Conditions Mucosa Blood Stream Saliva Drug Transport Direction Lozenge RL

  30. Boundary Conditions Mucosa Blood Stream Saliva Drug Transport Direction Lozenge RS

  31. Initial Conditions Mucosa Blood Stream Saliva Drug Transport Direction Lozenge Before any drug is released (at time = 0), the drug and glucose concentrations in the saliva are equal to zero: C1 =Cg =0

  32. System

  33. Boundary Conditions at RL

  34. Boundary Conditions at Rs

  35. System function [c,b,s] = eqn (x,t,u,DuDx) c = [1; 1]; b = [D1; Dg] .* DuDx; s = [-kv*u(1); -kv*u(2)]; end

  36. Boundary Conditions function [pl,ql,pr,qr] = bc2(xl,ul,xr,ur,t) pl = [D1*kd/D1g*(csolg-ul(2))*(rou1 -ul(1))); Dg*kd/Dgg*(csolg-ul(2))*(roug-ul(2)))]; ql = [-1; -1]; pr = [K1*ur(1)-c2Rs; Kg*ur(2)-cGRs]; qr = [0; 0]; end

  37. Initial Conditions function value = initial2(x); value = [0;0]; end

  38. Solving and Plotting m = 2; x = linspace(0,1,10); t = linspace(0,1,10); sol = pdepe(m,@eqn,@initial2,@bc2,x,t); u1 = sol(:,:,1); u2 = sol(:,:,2); subplot(2,1,1) surf(x,t,u1); title('u1(x,t)'); xlabel('Distance x'); ylabel('Time t'); subplot(2,1,2) surf(x,t,u2); title('u2(x,t)'); xlabel('Distance x'); ylabel('Time t');

  39. Plotting

  40. Single PDE in Two Space Dimensions 1. Elliptic 2. Parabolic 3. Hyperbolic 4. Eigenvalue

  41. Example 4 No Heat T=0 T=10 Laplace’s Equation No Heat

  42. Step 1 • Start the toolbox by typing in >> pdetool at the Matlab prompt

  43. Step 2 Select Heat Transfer Application

  44. Step 3 The Draw Menu

  45. Step 4 Create Rectangle

  46. Step 5 The Boundary Menu

  47. Step 6 Display Options

  48. Step 7 Select Boundary 4

  49. Step 8 Specify Boundary Condition Steps 9 - 10 Select Boundary 1 and specify condition

  50. Steps 11 - 14 Specify remaining boundary conditions

More Related