+ All Categories
Home > Documents > Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf ·...

Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf ·...

Date post: 30-Jan-2018
Category:
Upload: dotruc
View: 230 times
Download: 3 times
Share this document with a friend
29
Solving PDES in MATLAB PEER 2013 Sept 6, 2013
Transcript
Page 1: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Solving PDES in MATLAB

PEER 2013 Sept 6, 2013

Page 2: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

One-Dimensional Heat Equation

Page 3: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Discretizing the Domain

Page 4: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Discretizing the Equations

Page 5: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Discretizing the Equations

Page 6: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Programming Heat Equation in MATLAB

% This is the finite difference implementation % for the heat equation on the domain (0,1) % u_t = u_xx, u(0,t)=0, u(1,t)=0, u(x,0)= x(1-x) clear all a = 0; % Left point b = 1; % Right point N = 10; % Number of intervals in x M = 10000; % Number of intervals in t T = 50; % Final Time del_x = (b - a)/N; % Step size in x del_t = T/M; % Step size in t x=a:del_x:b; % x grid t=0:del_t:T; % t grid lambda = del_t/del_x^2; % Defining Lambda

Page 7: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

if lambda > 0.5 disp('Your lambda value is too big') else A = diag((1-2*lambda)*ones(N-1,1),0); A = A + diag(lambda*ones(N-2,1),1); A = A + diag(lambda*ones(N-2,1),-1); u_initial = x.*(1-x); Sol_mat(:,1) = u_initial(2:N)'; for i=1:10 Sol_mat(:,i+1) = A*Sol_mat(:,i); end u(1,:)=zeros(1,11); u(2:N,:)=Sol_mat; u(N+1,:)=zeros(1,11); for i=1:10 plot(x,u) hold on end end

Page 8: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

PDE Toolbox MATLAB

Page 9: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Rectangular Plate with a circular Hole

( ) 0=∇− Tdiv

Page 10: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

PDETOOL BOX

>> pdetool

Page 11: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Change generic scalar in the drop down menu to heat transfer.

Page 12: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Change generic scalar in the drop down menu to heat transfer.

Page 13: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Click the PDE button and select PDE Specification.

Page 14: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

By default Type of PDE is Elliptic. Change values of h and Q to 0. Click OK.

Page 15: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Rectangle with a hole

• Click on one of the rectangle button on the main menu and use your mouse to define a rectangle.

Page 16: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Creating a Rectangle

Page 17: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Changing Rectangle Parameters

Page 18: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Click on the Rectangle and change the dimensions

Page 19: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Click the circle (ellipse) button and position a circle outside the rectangle

Page 20: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Create a Circle by changing radius

Page 21: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Drag the circle into the square R1 + E1

Page 22: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Set Formula Box R1 – E1

Page 23: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Click the Ω∂

Page 24: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Select Specify Boundary Conditions from the Boundary menu

Page 25: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Select Specify Boundary Conditions from the Boundary menu

Page 26: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Select the big

Page 27: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Select the big =

Page 28: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Refine by clicking

Page 29: Solving PDES in MATLAB - George Mason Universitymath.gmu.edu/.../PEER_GMU_NMAIST_PDES_MATLAB.pdf · Programming Heat Equation in MATLAB % This is the finite difference implementation

Push = again


Recommended