Bisec
Bisec
Output:
Enter list of abscissa:[5 10 15 20]
% Date: 08.02.2024
Code:
X=input('Enter list of abscissa:');
Y=input('Enter list of ordinates:');
F=input('Enter 1 for linear fit, 2 for parabolic and so on:');
n=length(X);
N=F+1; %For dimension of matrix A
A= zeros(N,N);
for i=1:N
for j=1:N
A(i,j)=sum(X.^(i+j-2));
end
end
B=zeros(N,1);
for k=1:N
B(k)=sum((X.^(k-1)).*Y);
end
U=A\B;
disp('Your polynomial is:')
for k=N:-1:2
fprintf('+(%.2fx^%d)',U(k),k-1)
end
fprintf('(%.4f)\n',U(1))
%plotting
P= flip(U);
X= linspace (X (1),X (n),100);
Y= polyval(P,X);
plot (X, Y, 'r')
hold on
plot(X,Y,'o')
Output:
+(1.73x^2)+(0.06x^1)(0.5871)
% Experiment No: 4.1
1 1
% Experiment Name: Evaluate I=∫0 1+𝑥 𝑑𝑥 by Trapezoidal Rule.
% Date: 29.02.2024
Code:
f= input('Enter your function: f(x)=');
a= input('Enter your lower limit a=');
b= input('Enter your upper limit b=');
n= input('Enter your number of stripe n=');
h= (b-a)/n;
y= zeros(1,n-1);
for i=1:1:n-1
y(i)=f(a+i*h);
end
i= 1:1:n-1;
I= h/2*(f(a)+2*(sum(y(i)))+f(b));
fprintf('the value of integral is %0.3f\n',I);
Output:
Enter your function: f(x)=@(x) 1/(1+x)
Enter your lower limit a=0
Enter your upper limit b=1
Enter your number of stripe n=4
the value of integral is 0.697
% Experiment No: 4.2
7
% Experiment Name: Evaluate I=∫3 x 2 log10 (x) 𝑑𝑥 by Simpson's 1/3
Rule.
% Date: 29.02.2024
Code:
f= input('Enter your function: f(x)=');
a= input('Enter your lower limit a=');
b= input('Enter your upper limit b=');
n= input('Enter your number of stripe n=');
h= (b-a)/n;
y= zeros(1,n-1);
for i=1:1:n-1
y(i)=f(a+i*h);
end
i= 2:2:n-2;
k=1:2:n-1;
I= h/3*(f(a)+2*(sum(y(i)))+4*(sum(y(k)))+f(b));
fprintf('the value of integral is %0.3f\n',I);
Output :
Enter your function: f(x)=@(x) (x^2)*log10(x)
Enter your lower limit a=3
Enter your upper limit b=7
Enter your number of stripe n=4
the value of integral is 77.079
% Experiment No: 05
7
% Experiment Name: Evaluate I=∫3 x 2 log10 (x) 𝑑𝑥 by Simpson's 3/8
Rule.
% Date: 07.03.2024
Code:
f= input('Enter your function: f(x)=');
a= input('Enter your lower limit a=');
b= input('Enter your upper limit b=');
n= input('Enter your number of stripe n=');
h= (b-a)/n;
y= zeros(1,n-1);
for i=1:1:n-1
y(i)=f(a+i*h);
end
i= 3:3:n-3;
k= 1:1:n-1;
I= 3*h/8*(f(a)+2*(sum(y(i)))+3*((sum(y(k)))-
(sum(y(i))))+f(b));
fprintf('the value of integral is %0.3f\n',I);
Output:
Enter your function: f(x)=@(x) (x^2)*log10(x)
Enter your lower limit a=3
Enter your upper limit b=7
Enter your number of stripe n=4
the value of integral is 79.150
% Experiment No: 6.1
% Experiment Name: Runge-Kutta 2nd order method.
% Date: 14.03.2024
Code:
Output:
Output: