Question: Problem 1 ( c ) : Results a . Grid of 1 1 points b . Grid of 2 1 points c . Grid of
Problem c: Results
a Grid of points
b Grid of points
c Grid of points
d Grid of points
Fig : Results for all grids
Following table is generated:
h error ratio observed order
e NaN NaN
e
e
e
Write a python code to the following matlab code.
clc;clear;close all;
Problemc
a ;
b ;
sigma ;
beta ;
mplus;
f @x expx;
True solution
utrue @x expxbetasigmaexpaexpbbax
bsigmaabetaaexpbbexpaba;
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
errorlogloghvalserror; produce loglog plot of errors and least squares
fit
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
