Homework 4 - Questions and answers PDF

Title Homework 4 - Questions and answers
Course Numerical Methods and Programming for Chemical Engineers
Institution Louisiana State University
Pages 10
File Size 465.2 KB
File Type PDF
Total Downloads 62
Total Views 142

Summary

Questions and answers...


Description

Assignment 4 function hw4lorenz clc %Number 1 - Lorenz Model %Lorenz Model is used for modeling convection problems %Part (i) for (a,b,c)=(5,12,2) a=5; b=12; c=2; [t,y]=ode45(@lorenz,[0:.05:25],[1 0 0],1e-5); figure subplot(2,1,1) plot(t,y(:,2)) %Time series plot title('Time Series Plot') xlabel('Time') ylabel('y(1)')

subplot(2,1,2) plot(y(:,1),y(:,2)) title('Projection of the Phase Space') xlabel('y(1)') ylabel('y(2)')

%Long term nature of the solution response is constant (straight line) %around 5

%Part (ii) for (a,b,c)=(3,220,1) a=3; b=220; c=1; [t2,y2]=ode45(@lorenz,[0:.05:25],[1 0 0],1.e-5);

figure subplot(2,1,1) plot(t2,y2(:,2),'r') %Time series plot title('Time Series Plot') xlabel('Time') ylabel('y(1)')

subplot(2,1,2) plot(y2(:,1),y2(:,2),'r') title('Projection of the Phase Space') xlabel('y(1)') ylabel('y(2)')

%Long term nature of the solution response fluctuates between -100 and 100

%Part (iii) for (a,b,c)=(5,17,1) a=5; b=17; c=1; [t3,y3]=ode45(@lorenz,[0:.05:100],[1 0 0],1.e-5);

figure subplot(2,1,1) plot(t3,y3(:,2),'r') %Time series plot title('Time Series Plot') xlabel('Time') ylabel('y(1)')

subplot(2,1,2) plot(y3(:,1),y3(:,2),'r') title('Projection of the Phase Space') xlabel('y(1)') ylabel('y(2)') %Long term nature of the solution response fluctuates between -15 and 15

function f=lorenz(t,y) %Calculates t and y f(1)=-a*y(1)+a*y(2); f(2)=b*y(1)-y(2)-y(3)*y(1); f(3)=-c*y(3)+y(1)*y(2); f=f'; end

end

Published with MATLAB® R2014a

function hw4bratu %Number 2 - Bratu's equation for combustion modeling problems %Part a eps=0.1; figure subplot(2,1,1); for i=1:5 %Run 5 times to cover epsilon=0.1-0.5 mu=5; solinit=bvpinit([-1:.1:1],[1 0]); %x guess/y guess sol=bvp4c(@bratu,@bc,solinit) hold on plot(sol.x,sol.y(1,:)) %Mesh selected by bvp4c and approx y(x) title('Bratu Equation, part a') xlabel('x') ylabel('u(x)') eps=eps+0.1; end

sol =

solver: 'bvp4c' x: [1x21 double] y: [2x21 double] yp: [2x21 double] stats: [1x1 struct]

sol =

solver: 'bvp4c' x: [1x21 double] y: [2x21 double] yp: [2x21 double] stats: [1x1 struct]

sol =

solver: 'bvp4c' x: [1x21 double] y: [2x21 double] yp: [2x21 double] stats: [1x1 struct]

sol =

solver: 'bvp4c' x: [1x21 double] y: [2x21 double] yp: [2x21 double] stats: [1x1 struct]

sol =

solver: 'bvp4c' x: [1x21 double] y: [2x21 double] yp: [2x21 double] stats: [1x1 struct]

%Part B eps=0.1; %Resetting epsilon for part b

subplot(2,1,2); for i=1:6 mu=0; solinit2=bvpinit([-1:.1:1],[1 0]); %x guess/y guess sol2=bvp4c(@bratu,@bc,solinit2) hold on plot(sol2.x,sol2.y(1,:)) %Mesh selected by bvp4c and approx y(x) title('Bratu Equation, part b') xlabel('x') ylabel('u(x)') eps=eps+0.1; end

sol2 =

solver: 'bvp4c' x: [1x21 double] y: [2x21 double] yp: [2x21 double] stats: [1x1 struct]

sol2 =

solver: 'bvp4c' x: [1x21 double] y: [2x21 double] yp: [2x21 double] stats: [1x1 struct]

sol2 =

solver: 'bvp4c' x: [1x21 double] y: [2x21 double] yp: [2x21 double] stats: [1x1 struct]

sol2 =

solver: 'bvp4c' x: [1x21 double]

y: [2x21 double] yp: [2x21 double] stats: [1x1 struct]

sol2 =

solver: 'bvp4c' x: [1x21 double] y: [2x21 double] yp: [2x21 double] stats: [1x1 struct]

sol2 = solver: 'bvp4c' x: [1x21 double] y: [2x21 double] yp: [2x21 double] stats: [1x1 struct]

%Part C eps=3;mu=0; solinit3=bvpinit([-1:.1:1],[-3 3]); %x guess/y guess sol3=bvp4c(@bratu,@bc,solinit3) figure plot(sol3.x,sol3.y(1,:)) title('Bratu Equation, part c') xlabel('x') ylabel('u(x)')

Warning: Unable to meet the tolerance without using more than 5000 mesh points. The last mesh of 2725 points and the solution are available in the output argument. The maximum residual is 0.0591363, while requested accuracy is 0.001.

sol3 =

x: [1x2725 double] y: [2x2725 double] yp: [2x2725 double] solver: 'bvp4c'

%Functions function f=bratu(x,y) f(1)=y(2); f(2)=-eps*exp(y(1)/(1+mu*y(1))); end

function b=bc(lb,rb) %left boundary, right boundary b=[lb(1); rb(1)]; end end

Published with MATLAB® R2014a...


Similar Free PDFs