Clc
clear all
close all
syms x;
a=input('enter lower
value')
b=input('upper value')
n=input('enter desired
intervals=')
h=b-a/n
g=input('enter
function=')
p=inline(g)
for i=1:n+1
x(i)=a+h*(i-1)
f(i)=p(x(i))
end
s=sum(f(2:n))
A=h/2*(f(1)+2*s+f(n+1))
Q) Solve the given function 1/x using
trapezoidal rule:
enter lower value1
a=1
upper value2
b=2
enter desired intervals=4
n =4
h = 1.7500
enter function=1/x
g =1/x
p =Inline function:
p(x) = 1.0./x
x =1
f = 1
x = [ 1, 11/4]
f =[ 1, 4/11]
x =[ 1, 11/4, 9/2]
f = [ 1, 4/11, 2/9]
x = [ 1, 11/4, 9/2, 25/4]
f =[ 1, 4/11, 2/9, 4/25]
x =[ 1, 11/4, 9/2, 25/4, 8]
f = [ 1, 4/11, 2/9, 4/25, 1/8]
s =1846/2475
A =362677/158400
No comments:
Post a Comment