Answered step by step
Verified Expert Solution
Link Copied!

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 2c-
a. with 11 grid points
c. with 41 grid points
b. with 21 grid points
d. with 81 grid points
Fig 3. Results for all grid points for approach 1
Write a python code of the following matlab code. clc;clear;close all;
% Problem 2(c)-first approach
a =0;
b =3;
sigma =-5;
beta =3;
mplus1=[10204080];
f = @(x) exp(x);
% True solution
u_true = @(x) exp(x)+(sigma-exp(a))*x+beta-exp(b)...
+ b*exp(a)-b*sigma;
% True solution on fine grid for plotting
xfine = linspace(a,b,101);
ufine = u_true(xfine);
% Solve for multiple grids
hvals = zeros(numel(mplus1),1);
error = zeros(numel(mplus1),1);
for i =1:numel(mplus1)
% run routine for finite diff solve
[x,hvals(i),u]= finite_difference_2c1(a,b,sigma,beta,mplus1(i),f);
% get error at grid points
u_hat = u_true(x);
err = u - u_hat;
error(i)= max(abs(err));
disp('')
disp(sprintf('Error with %i points is %9.5e',mplus1(i)+1,error(i)))
clf
plot(x,u,'s')% plot computed solution
title(sprintf('Computed solution with %i grid points',mplus1(i)+1));
hold on
plot(xfine,ufine)% plot true solution
xlabel('x')
ylabel('U')
hold off
drawnow
input('Hit to continue ');
clear x u
end
error_table(hvals,error); % print tables of errors and ratios
Error with 11 points is 6.14966e-01
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Visualization A Practical Introduction

Authors: Kieran Healy

1st Edition

0691181624, 978-0691181622

More Books

Students also viewed these Databases questions

Question

State the uses of job description.

Answered: 1 week ago

Question

Explain in detail the different methods of performance appraisal .

Answered: 1 week ago