Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me create a vector R for my MATLAB code. See the question below code. n = 4; %sub intervals in the x

Can someone help me create a vector R for my MATLAB code. See the question below code. n = 4; %sub intervals in the x dimension dt = 0.1; %delta t tsteps = 30; alpha = 0.5; dx = 1; %delta x uL = @(t) t; %left boundary uR = @(t) t+1; %right boundary u0 = @(x) x.^2; %initial condition gamma = alpha*dt/(2*(dx^2)); %change beta to reflect average A = zeros(n+1,n+1); x = linspace(0,1,n+1); %start, finish, number of points t = linspace(0,tsteps*dt,tsteps+1); %Initial conditions %create a tridiagonal matrix for A A(1,:) = [1+2*gamma,-gamma,0,0,0]; A(2,:) = [-gamma,1+2&gamma,-gamma,0,0]; A(3,:) = [0,-gamma,1+2*gamma,-gamma,0]; A(4,:) = [0,0,-gamma,1+2*gamma,-gamma]; A(m-1,:) = [0,0,0,-gamma,1+2*gamma]; % % create a matrix for R(j,n) %R(j,n) = gamma*u(j-1,n) + (1-2*gamma)*u(j,n) + gamma*u(j+1,n) % R = zeros(n+1,1);%R matrix from notes % R(1) = R(1,n) + gamma*uL(t+1); % R(2) = R(2,n); % R(3) = R(3,n); % R(4) = R(4,n); % R(m-1) = R(m-1,n) + gamma*uR(t+1); %what the hell is m?? Confused me when he kept switching m and n %call tridfun %a = [1+2*gamma,1+2*gamma,1+2*gamma,1+2*gamma,1+2*gamma] %b = [-gamma,gamma,gamma,gamma,gamma,] %c = [-gamma,gamma,gamma,gamma,gamma,] %k = [R(1,n),R(2,n),R(3,n),R(4,n),R(m-1,n)] %u=tridfun(a,b,c,k) 

image text in transcribed

1) Write Matlab code to implement the Crank-Nicolson method to solve the one-dimensional heat equation u(t, 0) = a(t) u(t, 1) = (t) and initial condition u(0, g( Here c is a positive constant. Note that the boundary condition functions a and are not constant: they are functions of t. Employ the proper tridiagonal solving strategy. Use Matlab's contourf and colorbar commands to illustrate your results. 2) Repeat exercise 1) above, but this time use the boundary conditions a(t, 0) = a(t) u t, 1(t) Use the "fictitious node" technique for the Neumann boundary condition

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions