Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1 ( c ) : Results a . Grid of 1 1 points b . Grid of 2 1 points c . Grid of

Problem 1(c): Results
a. Grid of 11 points
b. Grid of 21 points
c. Grid of 41 points
d. Grid of 81 points
Fig 1: Results for all grids
Following table is generated:
h error ratio observed order
0.300004.77973e-02 NaN NaN
0.150001.19896e-023.986541.99514
0.075003.00274e-033.992911.99744
0.037507.51011e-043.998261.99937
Write a python code to the following matlab code.
clc;clear;close all;
% Problem1(c)
a =0;
b =3;
sigma =1;
beta =3;
mplus1=[10204080];
f = @(x) exp(x);
% True solution
u_true = @(x) exp(x)+(beta-sigma+exp(a)-exp(b))/(b-a)*x ...
+(b*sigma-a*beta+a*exp(b)-b*exp(a))/(b-a);
% 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_1c(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_loglog(hvals,error); % produce log-log plot of errors and least squares
fit
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

Power Bi And Azure Integrating Cloud Analytics For Scalable Solutions

Authors: Kiet Huynh

1st Edition

B0CMHKB85L, 979-8868959943

More Books

Students also viewed these Databases questions

Question

Construct a series of cash flows with no IRR.

Answered: 1 week ago

Question

1. Identify three approaches to culture.

Answered: 1 week ago

Question

2. Define communication.

Answered: 1 week ago

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago