Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a . with 1 1 grid points c . with 4 1 grid points v . Will ? ? 1 gilu puilis d . with

a. with 11 grid points
c. with 41 grid points
v. Will ??1 gilu puilis
d. with 81 grid points
Fig 5. Results for all grid points for approach 3
Write a Python code of the following matlab code.
clc;clear;close all;
% Problem 2(c)-third 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_2c3(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 5.08091e-02
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_2

Step: 3

blur-text-image_3

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

Entity Alignment Concepts Recent Advances And Novel Approaches

Authors: Xiang Zhao ,Weixin Zeng ,Jiuyang Tang

1st Edition

9819942527, 978-9819942527

More Books

Students also viewed these Databases questions

Question

Are you creative? Hardworking? Ambitious?

Answered: 1 week ago