0% found this document useful (0 votes)
5 views4 pages

Trapezoidal Rule

The document details the approximation of integrals using the Trapezoidal rule for various functions over specified intervals. It includes examples for the functions f(x)=1/x, f(x)=sin(x), f(x)=e^(-x), and f(x)=atan(x), with corresponding intervals and calculated results. Each example also includes warnings about passing floating-point values to symbolic functions.

Uploaded by

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

Trapezoidal Rule

The document details the approximation of integrals using the Trapezoidal rule for various functions over specified intervals. It includes examples for the functions f(x)=1/x, f(x)=sin(x), f(x)=e^(-x), and f(x)=atan(x), with corresponding intervals and calculated results. Each example also includes warnings about passing floating-point values to symbolic functions.

Uploaded by

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

# Approximate the value of the following integral using the Trapezoidal's rule

# f(x)=1/x in the interval [1,2]

clc

syms x

f=input('Enter the value of the function:')

a=input('Enter the value of initial point of the interval a:')

b=input('Enter the value of the end point of the interval b:')

%trapezoidal rule

L=vpa(((b-a)/2)*(subs(f,a)+subs(f,b)),8)

Enter the value of the function:1/x

f = (sym)

Enter the value of initial point of the interval a:1

a=1

Enter the value of the end point of the interval b:2

b=2

warning: passing floating-point values to sym is dangerous, see "help sym"

warning: called from

double_to_sym_heuristic at line 50 column 7

sym at line 379 column 13

mtimes at line 63 column 5

trapezoidalrule at line 9 column 2

L = (sym) 0.75000000
# Approximate the value of the following integral using the Trapezoidal's rule

# f(x)=sin(x) in the interval [0,pi/2]

clc

syms x

f=input('Enter the value of the function:')

a=input('Enter the value of initial point of the interval a:')

b=input('Enter the value of the end point of the interval b:')

%trapezoidal rule

L=vpa(((b-a)/2)*(subs(f,a)+subs(f,b)),8)

Enter the value of the function:sin(x)

f = (sym) sin(x)

Enter the value of initial point of the interval a:0

a=0

Enter the value of the end point of the interval b:pi/2

b = 1.5708

warning: passing floating-point values to sym is dangerous, see "help sym"

warning: called from

double_to_sym_heuristic at line 50 column 7

sym at line 379 column 13

subs at line 226 column 9

trapezoidalrule at line 9 column 2

warning: passing floating-point values to sym is dangerous, see "help sym"

warning: called from

double_to_sym_heuristic at line 50 column 7

sym at line 379 column 13

mtimes at line 63 column 5

trapezoidalrule at line 9 column 2


L = (sym) 0.78539816

# Approximate the value of the following integral using the Trapezoidal's rule

# f(x)=e^(-x) in the interval [0,1]

clc

syms x

f=input('Enter the value of the function:')

a=input('Enter the value of initial point of the interval a:')

b=input('Enter the value of the end point of the interval b:')

%trapezoidal rule

L=vpa(((b-a)/2)*(subs(f,a)+subs(f,b)),8)

Enter the value of the function:exp(-x)

f = (sym)

-x

Enter the value of initial point of the interval a:0

a=0

Enter the value of the end point of the interval b:1

b=1

warning: passing floating-point values to sym is dangerous, see "help sym"

warning: called from

double_to_sym_heuristic at line 50 column 7

sym at line 379 column 13

mtimes at line 63 column 5

trapezoidalrule at line 9 column 2

L = (sym) 0.68393972
# Approximate the value of the following integral using the Trapezoidal's rule

# f(x)=tan^(-1)(x) in the interval [0,1]

clc

syms x

f=input('Enter the value of the function:')

a=input('Enter the value of initial point of the interval a:')

b=input('Enter the value of the end point of the interval b:')

%trapezoidal rule

L=vpa(((b-a)/2)*(subs(f,a)+subs(f,b)),8)

Enter the value of the function:atan(x)

f = (sym) atan(x)

Enter the value of initial point of the interval a:0

a=0

Enter the value of the end point of the interval b:1

b=1

warning: passing floating-point values to sym is dangerous, see "help sym"

warning: called from

double_to_sym_heuristic at line 50 column 7

sym at line 379 column 13

mtimes at line 63 column 5

trapezoidalrule at line 9 column 2

L = (sym) 0.39269908

You might also like