Assignment - 7 Chinky

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Table of Contents

Title .................................................................................................................................. 1
Problem-1 .......................................................................................................................... 1
Problem-2 .......................................................................................................................... 1
Problem-3 .......................................................................................................................... 2

Title
disp('Porika Sushma Chand')
disp('Assignment-7')

Porika Sushma Chand


Assignment-7

Problem-1
f=@(x) exp(x)*cos(x);
a=0;
b=1;
h=0.1;
n=(b-a)/h;
trapez(f,a,b,n)
m=fminbnd(f,a,b);
Et=m*(b-a)^3/12*n^2;
fprintf('The Error Bound is %f',Et)

_______________________________________________
i xi f(xi) h=0.1
_______________________________________________
0 0.0000 1.000000
1 0.1000 1.099650
2 0.2000 1.197056
3 0.3000 1.289569
4 0.4000 1.374062
5 0.5000 1.446889
6 0.6000 1.503860
7 0.7000 1.540203
8 0.8000 1.550549
9 0.9000 1.528914
10 1.0000 1.468694

The intergral of f(x) is = 1.37650983


The Error Bound is 0.000551

Problem-2
f=@(x) exp(x)*cos(x);
a=0;
b=1;

1
h=(b-a)/n;
n=10;
simpson(f,a,b,n)
m=fminbnd(@(x) exp(x)*cos(x),a,b);
Et=m*(b-a)^5/180*n^4;
fprintf('The Error Bound is %f',Et)

______________________________________________
i xi f(xi) h=0.1
______________________________________________
0 0.0000 1.000000
1 0.1000 1.099650
2 0.2000 1.197056
3 0.3000 1.289569
4 0.4000 1.374062
5 0.5000 1.446889
6 0.6000 1.503860
7 0.7000 1.540203
8 0.8000 1.550549
9 0.9000 1.528914
10 1.0000 1.468694

The intergral of f(x) is = 1.37802155


The Error Bound is 0.003673

Problem-3
format long
simpson(@(x)1/(1+x^2), 0, 1, 10)
disp('Actual Integral is 0.785398163')

______________________________________________
i xi f(xi) h=0.1
______________________________________________
0 0.0000 1.000000
1 0.1000 0.990099
2 0.2000 0.961538
3 0.3000 0.917431
4 0.4000 0.862069
5 0.5000 0.800000
6 0.6000 0.735294
7 0.7000 0.671141
8 0.8000 0.609756
9 0.9000 0.552486
10 1.0000 0.500000

The intergral of f(x) is = 0.78539815


Actual Integral is 0.785398163

Published with MATLAB® R2015a

You might also like