Question: The Code from Last week and my attempt on that: index = 1; for n = [6,12,24,48,96] v = 1; u = ones(n+1,1); %Initialize the

The Code from Last week and my attempt on that:
index = 1; for n = [6,12,24,48,96] v = 1; u = ones(n+1,1); %Initialize the matrix we will needed. J = zeros(n+1); f = zeros(n+1,1);
h =(5-0); hlist(index) = h; x = linspace(0,5,n+1);
for iter = 1:10000 for i = 2:n f(i)= u(i)*((u(i+1)-u(i-1))/(2*h))- v*((u(i+1)-2*u(i)+u(i-1))/(h^2));
J(i,i)= ((u(i+1)-u(i-1))/(2*h)) + (2*v/(h^2)); J(i,i+1) = (u(i)/(2*h)) - (v/(h^2)); J(i,i-1) = (-u(i)/(2*h)) - (v/(h^2)); end
f(1)= u(1)- 1; f(n+1)= u(n+1)- 2; %Declare Initial conditions J(1,1) = 1; J(n+1,n+1) = 1;
Du = J \(-f); u = u + Du; %{ err = max(abs(f)); % Declare the definition of error if err
alpha = abs(log10((umid(2)-umid(3))/(umid(1)-umid(2)))/log10(2)) C =(umid(2)-umid(3))/(hlist(2)^alpha - hlist(3)^alpha) uexact = umid(3)-C*hlist(3)^alpha
1. Using your code from last week, set 1then calculate (and store in arn array) the value of u at the midpoint of the domain using 6, 12, 24, 48, and 96 segments. Also calculate and store the value of the flux -vd! at x 5 Then dr . Calculate and plot the changes in the solution between mesh sizes versus the mesh resolution from the coarser mesh using a loglog scale. Assuming you stored your midpoint values in an array called umid and your mesh resolutions in an array called hlist, this will be something like this for i-1:4 udiff(i) - umid(i)-umid(i+1) end loglog(hlist(1:4) ,udiff) Repeat the above for the values of the flux and plot the values on the same plot . Use Richardson extrapolation with the three midpoint values calculated with 24,48, and 96 segments to estimate the constants, umideract, C, and for the following expression umidi-umidezact-ch? Repeat the above for the fluxes. your expectations. Why/Why not? midpoint value and the flux. . Do the estimated convergence rates of the solution and fluxes agree with . Estimate the perce ntage error in the calculation of each solution for the 2. Repeat the above except with 1/10 Why does the Richardson extrapolation for the midpoint values give you weird results? Why does the Richardson extrapolation for the fluxes give you weird re- sults? (different reason) 1. Using your code from last week, set 1then calculate (and store in arn array) the value of u at the midpoint of the domain using 6, 12, 24, 48, and 96 segments. Also calculate and store the value of the flux -vd! at x 5 Then dr . Calculate and plot the changes in the solution between mesh sizes versus the mesh resolution from the coarser mesh using a loglog scale. Assuming you stored your midpoint values in an array called umid and your mesh resolutions in an array called hlist, this will be something like this for i-1:4 udiff(i) - umid(i)-umid(i+1) end loglog(hlist(1:4) ,udiff) Repeat the above for the values of the flux and plot the values on the same plot . Use Richardson extrapolation with the three midpoint values calculated with 24,48, and 96 segments to estimate the constants, umideract, C, and for the following expression umidi-umidezact-ch? Repeat the above for the fluxes. your expectations. Why/Why not? midpoint value and the flux. . Do the estimated convergence rates of the solution and fluxes agree with . Estimate the perce ntage error in the calculation of each solution for the 2. Repeat the above except with 1/10 Why does the Richardson extrapolation for the midpoint values give you weird results? Why does the Richardson extrapolation for the fluxes give you weird re- sults? (different reason)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
