Question: Problem 2 c - a . with 1 1 grid points c . with 4 1 grid points b . with 2 1 grid points
Problem c
a with grid points
c with grid points
b with grid points
d with grid points
Fig Results for all grid points for approach
Write a python code of the following matlab code. clc;clear;close all;
Problem cfirst approach
a ;
b ;
sigma ;
beta ;
mplus;
f @x expx;
True solution
utrue @x expxsigmaexpaxbetaexpb
bexpabsigma;
True solution on fine grid for plotting
xfine linspaceab;
ufine utruexfine;
Solve for multiple grids
hvals zerosnumelmplus;
error zerosnumelmplus;
for i :numelmplus
run routine for finite diff solve
xhvalsiu finitedifferencecabsigma,beta,mplusif;
get error at grid points
uhat utruex;
err u uhat;
errori maxabserr;
disp
dispsprintfError with i points is emplusierrori
clf
plotxus plot computed solution
titlesprintfComputed solution with i grid points',mplusi;
hold on
plotxfineufine plot true solution
xlabelx
ylabelU
hold off
drawnow
inputHit to continue ;
clear x u
end
errortablehvalserror; print tables of errors and ratios
Error with points is e
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
