0% found this document useful (0 votes)
21 views3 pages

Name: BAGARAGAZA Romuald Student Number: M2014028 Assagnment 4 Numerical Analysis

This document contains the solutions to numerical analysis exercises using different numerical integration techniques like the composite trapezoidal rule, modified Euler method, and Runge-Kutta method of order four. It provides the name, student number, assignment details, questions, mathematical formulas, code solutions, output values, true values, and errors for approximating integrals and solving initial value problems at different values of n (the number of intervals).

Uploaded by

Karen Johnson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Name: BAGARAGAZA Romuald Student Number: M2014028 Assagnment 4 Numerical Analysis

This document contains the solutions to numerical analysis exercises using different numerical integration techniques like the composite trapezoidal rule, modified Euler method, and Runge-Kutta method of order four. It provides the name, student number, assignment details, questions, mathematical formulas, code solutions, output values, true values, and errors for approximating integrals and solving initial value problems at different values of n (the number of intervals).

Uploaded by

Karen Johnson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: BAGARAGAZA Romuald

Student number: M2014028


Assagnment 4
Numerical Analysis
P203, EXERCISE SET 4.4, 2, f

QUESTION
Use the Composite Trapezoidal rule with the indicated values of n to
approximate the following integrals.

, n=8
Solution
clear
S=0;
a=1;
b=3;
n=32
h=(b-a)/n;
for i=1:n-1
x(i)=a+i*h;
end
S=f(a)+f(b);
for i=1:n/2-1
S=S+2*f(x(2*i))+4*f(x(2*i-1));
end
S=S+4*f(x(n-1));
S=h/3*S
TRUEVALUE=(log(13)-log(5))/2
S-TRUEVALUE
f.m
function ff=f(x)
ff=x/(x*x+4);
n=
4
S =
0.47772983114447
TRUEVALUE =
0.47775572251372
ans =
-2.589136925290614e-005
n =
8
S =
0.47775464628479
TRUEVALUE =
0.47775572251372
ans =
-1.076228928031942e-006
n =
16
S =
0.47775566285229

TRUEVALUE =
0.47775572251372
ans =
-5.966143212798869e-008
n =
32
S =
0.47775571889878
TRUEVALUE =
0.47775572251372
ans =
-3.614939236840087e-009

P281, EXERCISE SET 5.4 10 (b)


QUESTION
Use the Modified Euler method to approximate the solution to each of the
following initial-value problems, and compare the results to the actual
values.

Using the Runge-Kutta method of order four.

SOLUTION
a=2;
b=3;
N=2;
h=(b-a)/N;
t=a;
w(1)=1;
for i=1:N+1
t(i)=a+(i-1)*h;
end
for i=1:N
K1=h*f(t(i),w(i));
K2=h*f(t(i)+h/2,w(i)+K1/2);
K3=h*f(t(i)+h/2,w(i)+K2/2);
K4=h*f(t(i)+h,w(i)+K3);
w(i+1)=w(i)+(K1+2*K2+2*K3+K4)/6;
end
for i=1:N+1
ww(i)=t(i)+1/(1-t(i));
end
for i=1:N+1

error(i)=w(i)-ww(i);
end
w
ww
error
f.m
function ff=f(t,y)
ff=1+(t-y)^2;

You might also like