Question: I need help with my MATLAB code to answer question (2) on this Homework. I beleive my code answers part (1) but now I need
I need help with my MATLAB code to answer question (2) on this Homework. I beleive my code answers part (1) but now I need to use it to answer part (2) which asks for th fictitious node technique. Can someone help me use my code below to answer (2)? Also, don't worry about the tridiagonal code. I have that already. clear; 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)

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
Get step-by-step solutions from verified subject matter experts
