Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started