Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Maths

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

PAVENDAR BHARATHIDASAN COLLEGE OF ARTS AND SCIENCE

THANJAI NATARAJAN NAGAR,

MATHUR, PUDUKOTTAI ROAD, TIRUCHIRAPPALLI, PINCODE-622515.

DEPARTMENT OF MATHEMATICS

B.Sc., DEGREE EXAMINATION

NAME : ________________________________

REG.NO : ________________________________

SUBJECT : ________________________________

SEMESTER : ________________________________
PAVENDAR BHARATHIDASAN COLLEGE OF ARTS AND SCIENCE

THANJAI NATARAJAN NAGAR,

MATHUR, PUDUKOTTAI ROAD, TIRUCHIRAPPALLI, PINCODE-622515.

DEPARTMENT OF MATHEMATICS

Certified that this bonafide recorded for the _______________ practical work
done by ____________________ for ___________ semester in the subject
___________________________________ During the academic year ______________

Register No:___________________________

STAFF INCHARGE HEAD OF THE DEPARTMENT

Submitted for the practical examination held on ___________________

INTERNAL EXAMINER EXTERNAL EXAMINER


INDEX

S.NO DATE TITLE PAGE NO SIGNATURE

1 Linear Interpolation

2 Liner Regression

3 Curve Fitting

4 Trapezoidal Rule Of Integration

5 Simpson’s 1/3 Rule Of Integration

6 Newton-Raphson Method Of Solving


Equations

7 Gauss-Elimination Method Of Solving


Simultaneous Equations

8 Gauss- Seidal Method Of Solving


Simultaneous Equation

9 R-K Fourth Order Method Of Solving


Different Equations

10 Lagrange’s Method Of Interpolation


TRAPEZOIDAL RULE OF INTEGRATION

function[]=trapezoidal_Rule()

format compact

clc

y=inline('1/(1+x.*x)');

x0=input('enter x0:');

xn=input('enter xn:');

n=input('enter no of subinterval is:');

h=(xn-x0)/n;

s=y(x0)+y(xn);

for i=0:n-1

s=s+2.*y(x0+i.*h);

end

fprintf('the value of integral is: %f\n',h/2.*s)

end
TRAPEZOIDAL RULE OF INTEGRATION

OUTPUT

enter x0:0

enter xn:6

enter no of subinterval is:6

the value of integral is: 2.410799


SIMPSON’S 1/3 RULE OF INTEGRATION

function[]=simpson_rule()

clc

y=inline('1/(1+x.*x)');

x0=input('Enter x0:');

xn=input('enter xn:');

n=input('enter no of sub interval is:');

h=(xn=x0)/n;

s=y(x0)+y(xn)+4.*y(x0+h);

for i=3:2:n-1

s=s+4*y(x0+i.*h)+2.*y(x0+(i-1).*h);

end

fprintf('the value of integral is:%f\n',h/3*s);

end
SIMPSON’S 1/3 RULE OF INTEGRATION

OUTPUT

Enter x0:8

enter xn:9

enter no of sub interval is:7

the value of integral is:0.061297


NEWTON-RAPHSON METHOD OF SOLVING EQUATIONS

%program code for newton rapshon method

a=input('Enter the function in the form of variable x:','s');

x(1)=input('Enter the intial guess:');


error=input('Enter the allowed error:');
f=inline(a);
z=diff(str2sym(a));
d=inline(z);
for i=1:100
x(i+1)=x(i)-((f(x(i))/d(x(i))));
fprintf('iteration no %d x=%f\n',i,x(i+1))
err(i)=abs((x(i+1)-x(i))/x(i));
if err(i)<error
break
end
end
root=x(i)
NEWTON-RAPHSON METHOD OF SOLVING EQUATIONS

OUTPUT
Enter the function in the form of variable x:
x^3-x-1
Enter the intial guess:
1.5
Enter the allowed error:
0.0001
iteration no 1 x=1.347826
iteration no 2 x=1.325200
iteration no 3 x=1.324718
iteration no 4 x=1.324718

root =

1.3247
GAUSS – ELIMINATION METHOD OF SOLVING SIMULTANEOUS
EQUATIONS

function[]=gauss_elimination_method()
clc
N=4
a=input('Enter the element of matrics:\n')
for j=1:N-1
for i=j+1:N
t=a(i,j)/a(j,j);
for k=1:N+1
a(i,k)=a(i,k)-a(j,k)*t;
end
end
end
for i=1:N
for j=1:N+1
fprintf('%8.4f',a(i,j));
end
fprintf('\n');
end
for i=N:-1:1
s=0;
for j=i+1:N
s=s+a(i,j+1).*x(j);
end
x(i)=(a(i,N)-s)/a(i,i);
end
for i=1:N
fprintf('x(%d)=%6.4f\n',i,x(i))
end
GAUSS – ELIMINATION METHOD OF SOLVING SIMULTANEOUS
EQUATIONS

OUTPUT

N=

Enter the element of matrics:


[ 10 -7 3 5 6; -6 8 -1 -4 5; 3 1 4 11 2; 5 -9 -2 4 7]

a=

10 -7 3 5 6
-6 8 -1 -4 5
3 1 4 11 2
5 -9 -2 4 7

10.0000 -7.0000 3.0000 5.0000 6.0000


0.0000 3.8000 0.8000 -1.0000 8.6000
0.0000 0.0000 2.4474 10.3158 -6.8158
0.0000 0.0000 0.0000 9.9247 9.9247
x(1)=-3.3947
x(2)=-0.6842
x(3)=7.0000
x(4)=1.0000
GAUSS –SEIDAL METHOD OF SOLVING SIMULTANEOUS
EQUATIONS

function[]=Gauss_Seidal_method()
clc
a=input('enter the element of matrix:\n');
aerr=input('enter the allowed error');
maxitr=input('enter the maximum no of iterations:');
N=4;
x=zeros(1,N);
fprintf('iterations x[1] x[2] x[3]\n');
for itr=1:maxitr
maxerr=0;
for i=1:N-1
s=0;
for j=1:N-1
if(j~=i)
s=s+a(i,j)*x(j);
end
end
end
end
t=(a(i,N)-s)/a(i,i);
err=abs(x(i)-t);
if(err>maxerr)
maxerr=err;
end
GAUSS –SEIDAL METHOD OF SOLVING SIMULTANEOUS
EQUATIONS

OUTPUT

enter the element of matrix:\n[10 -5 -2 3;4 -10 3 -3; 1 6 10 -3]


enter the allowed error0.0001
enter the maximum no of iterations:7
iterations x[1] x[2] x[3]
R-K FOURTH ORDER METHOD OF SOLVING DIFFERENT
EQUATIONS

function[]=Gauss_Kutta_Method()
clc
format compact
format short g
f=inline('x+y*y');
x0=input('enter the value x0:');
y0=input('enter the value y0:');
h=input('enter the value h:');
xn=input('enter the value xn:');
x=x0;
y=y0;
while(1)
if(x==xn)
break
end
k1=h*f(x,y);
k2=h*f(x+h/2,y+k1/2);
k3=h*f(x+h/2,y+k2/2);
k4=h*f(x+h,y=k3);
k=(k1+(k2+k3)*2+k4)/6;
x=x+h;
y=y+h;
fprintf('when x=%f y=%f\n',x,y)
end
end
R-K FOURTH ORDER METHOD OF SOLVING DIFFERENT
EQUATIONS

OUTPUT
enter the value x0:0
enter the value y0:1
enter the value h:0.2
enter the value xn:0.2
when x=0.200000 y=0.475832
LAGRANGE’S METHOD OF INTERPOLATION

function[]=lagrange_interpolation_formula
clc
max=100;
n=input('enter value of n:');
ax=input('enter value of x:');
ay=input('enter value of y:');
x=input('enter value of x for which y is wanted:');
y=0;
for i=1:n+1
dr=1;
nr=1;
for j=1:n+1
if(j~=i)
nr=nr*(x-ax(j));
dr=dr*(ax(i)-ax(j));
end
end
y=y+((nr/dr)*ay(i));
end
fprintf('when x=%4.1fy=%4.1f\n',x,y);
end
LAGRANGE’S METHOD OF INTERPOLATION

OUTPUT

enter value of n:4


enter value of x:[5 7 11 13 17]
enter value of y:[150 392 1452 2366 5202]
enter value of x for which y is wanted:9
when x= 9.0y=810.0
LINEAR REGRESSION

function[y0,a,b]=linear_regression(x,y,x0)
x=[71 73 64 65 61 70 65 72 63 67 64]
y=[160 183 154 168 159 180 145 210 132 168 141]
[y0,a,b]=linear_regression(x,y,70)
%number of known points
n=lenght(x);
%intialization
j=0;k=0;l=0;p=0;
%accumulate intermediate sums
j=sum(x);
k=sum(y);
l=sum(x.^2);
p=sum(x.*y);
%compute cure co-effiecients
b=(n*p-k*j)/(n*l-j^2);
a=(k-b*j)/n;
%interpolation value
y0=a+b*x0;
LINEAR REGRESSION

COMMAND:

x=[71 73 64 65 61 70 65 72 63 67 64];
y=[160 183 154 168 159 180 145 210 132 168 141];
[y0,a,b]=linear_regression(x,y,70)

RESULT:

y0=176.5139
a=-106.7917
b=4.0472

COMMAND:

[y0]=linear_regression(x,y,72)

RESULT:

y0=184.6083
CURVE FITTING

clear all
clc
format compact
%define coordinates
x=[1 2 3 4 5.5 7 10];
y=[3 7 9 15 22 21 21]
%plot given data in red
plot(x,y,'ro','linewidth',2)
hold on
%find polynominal fits of different orders
p1=polyfit(x,y,1)
p2=polyfit(x,y,2)
p4=polyfit(x,y,4)
p5=polyfit(x,y,5)
%see interpolated values of fits
xc=1:.1:10;
%plot the first order polynominal
y1=polyval(p1,xc);
plot(xc,y1,'m.-')
%plot the second order polynominal
y1=polyval(p2,xc);
plot(xc,y2,'g.-')
%plot the 4th order polynominal
y1=polyval(p4,xc);
plot(xc,y4,'linewidth',2)
%plot the 4th order polynominal
y1=polyval(p5,xc);
plot(xc,y5,'k.','linewidth',2)
grid
title('cure fitting')
legend('original data','1st order fit','2nd order fit','4th order','5th
order','location','north west')
CURVE FITTING

OUTPUT
CURVE FITTING

COMMAND WINDOW

y=
3 7 9 15 22 21 21
p1 =
2.1763 3.8960
p2 =
-0.3863 6.3983 -4.1596
p4 =
0.0334 -0.7377 5.0158 -8.4137 7.5779
p5 =
0.0213 -0.5022 4.1330 -14.5708 25.3233 -11.3510
LINEAR INTERPOLATION

clear all

clc

format compact

x=0:1.0:5;

y=[1.0 -0.6242 -1.4707 3.2406 -0.7366 -6.3717];

xi=0:0.1:5;

yi=interp1(x,y,xi,'linear');

subplot(1,2,1)

plot(x,y,'ro',xi,yi,'g.-');

title('liner interpolation using data');

legend('y','yi');

x=[0:10];

y=cos(x);

xj=[0:.25:10];

subplot(1,2,2)

yj=interp1(x,y,xj,'linear');

plot(x,y,'ro',xj,yj,'b.-');

title('linear interpolation using function');

legend('y','yj');

x(i)=t;
fprintf('%5d\t\t',itr)

for i=1:N-1

fprintf('%f\t',x(i))

end

fprintf('\n')

if(maxerr<aerr)

fprintf('Converges in %d iteration \n', itr)

for i=0:N-1

fprintf('x(%d)=%2.4f\n',i,x(i))

end

return

end

fprintf('Solution does not converge, iteration not suficient \n')

return
LINEAR INTERPOLATION

OUTPUT
LINEAR INTERPOLATION
LINEAR INTERPOLATION

You might also like