Record_Mudinjuduchu_nu_Nenaikuran

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

ALAGAPPA CHETTIAR GOVERNMENT

COLLEGE OF ENGINEERING AND


TECHNOLOGY
Karaikudi - 630 003

(An Autonomous Institution – Affiliated to


Anna University Chennai)

ME STRUCTURAL ENGINEERING

19STL21 - NUMERICAL ANALYSIS LAB

Submitted by

I YEAR / II SEMESTER
ALAGAPPA CHETTIAR GOVERNMENT
COLLEGE OF ENGINEERING AND TECHNOLOGY
(An Autonomous Institution Affiliated to Anna University, Chennai)
Karaikudi - 630 003

DEPARTMENT OF CIVIL ENGINEERING

Certified that this is the Bona-fide Record of Practical work done by


……………………………………………………………………. of M.E Structural Engineering
First Year (Second Semester) during the academic year 2020 – 2021 in the
19STL21 - NUMERICALANALYSIS LAB.

Staff In-Charge Head of the Department


Date:

Submitted for the Practical Examination Held on ……………

INTERNALEXAMINER EXTERNALEXAMINER
INDEX

EXPRIMENT
DATE NAME OF THE EXPRIMENT SIGNATURE
NO.

Finding the root of Non-Linear equation


1. using Bisection Method
Finding the root of Non-Linear equation
2. using Newton’s Method
Fitting a Straight line by the method of Least
3. Square Approximation
Solving the system of Linear Equation using
4. Gauss Elimination Method

Solving the system of Linear Equation using


5. Gauss Jordan Method

Solving the system of Linear Equation


6. using Gauss Seidal Iteration Method
Integrating numerically using Trapezoidal
7. Rule
Integrating numerically using Simpson’s
8. Rule
Numerical Solution of Ordinary Differential
9. equation by Euler’s Method
Numerical Solution of Ordinary Differential
10. equation by 4tℎ order Runge-Kutta Method
Ex. N0 : 1 MATLAB Program To Find The Root Of Non-Linear Equation
Using Bisection Method.
MATLAB Program:

y = input('Enter the function:');


x1 = input('Enter the assumed lower limit:');
x2 = input('Enter the assumed upper limit:');
e = input('Enter the allowable error:');

for i = 1:100;
xh = (x1 + x2)/2;
if y(x1)*y(xh) < 0;
x2 = xh;
else
x1 = xh;
end
if abs(y(x1)) < e
break
end
end
fprintf('The root: %f \n The number of bisections: %d \n', x1,i);
PROGRAM INPUT

Enter the function: @(x) x^3+x^2+x+7


Enter the assumed upper limit: -3
Enter the assumed lower limit: -2
Enter the allowable error: 0.2

PROGRAM OUTPUT

The root: -2.104873


The number of bisections: 23
Ex. N0 : 2 MATLAB Program To Find the roots of Non- Linear equation using
Newton’s Method.
MATLAB Program:

syms x
f = input(‘Enter the function:’);
df = diff(f,x);
dfx = inline(df);
e = input(‘Enter the allowable error: ’);
x0 = input(‘Enter the initial guess:’);
n = 100;
if dfx(x0) ~= 0

for i=1:n
x1=x0-(f(x0)/dfx(x0));
fprintf('x%d=%.6f\n',i,x1)
if abs(x1-x0)<e
break
end
if dfx(x1)==0
disp('failed')
end
x0=x1;
end
else
disp('Newtons Raphson method Failed')
end
PROGRAM INPUT

Enter the function: @(x) 5*x^3 + 6*x^2 + 8*x + 9.


Enter the allowable error: 0.05
Enter the initial guess: 1.5

PROGRAM OUTPUT

x1=0.200000
x2=-0.789091
x3=-1.293046
x4=-1.172211
x5=-1.159370
x6=-1.159237
x7=-1.159237
Ex. N0 : 3 MATLAB Program - Curve Fitting by Least Square Approximations.
MATLAB Program:

x= input('Enter the values of x:');


y= input('Enter the values of y:');
N=length (x);
A= [N sum(x); sum(x) sum(x.*x)];
b=[sum(y); sum(x.*y)];
X= inv(A)*b;
fprintf ('X(2) = %f \n X(1) = %f\n',X);
plot(X);
PROGRAM INPUT

Enter the values of x: [2 4 5 8 7 9]


'Enter the values of y: [7 2 6 9 7 5]

PROGRAM OUTPUT

The value of X(1) = 0.437492.


The value of X(2) = 0.46.

PLOTTED GRAPH
Ex. N0 : 4 MATLAB program for solving the System of Linear equations
using Gauss-Elimination Method
MATLAB Program:

A = input('Enter your co-efficient matrix: ');


B = input('Enter source vector: ');
N = length(B);
X = zeros(N,1);
Aug = [A B]
fprintf('The echelon of the Augmented matrix is: \n')
disp(Aug);
for j=1: N-1
for i=j+1:N
m = Aug(i,j)/Aug(j,j);
Aug(i,:) = Aug(i,:) - m*Aug(j,:);
end
end
Aug
X(N) = Aug(N,N+1)/Aug(N,N);
for k=N-1:-1:1
X(k) = (Aug(k,N+1) - Aug(k,k+1:N)*X(k+1:N))/Aug(k,k);
end
fprintf('The unknown variables are given as; \n')

X
PROGRAM INPUT:
Enter your Co-efficient matrix: [33 56 12.7; 55.1 87 93; 22.7 18.3 9.81]
Enter your Source vector: [17
29

56]

PROGRAM OUTPUT:

The echelon of the augmented matrix is:

Aug =
33.0000 56.0000 12.7000 17.0000
0 -6.5030 71.7948 0.6152
0 0 -222.1726 42.3932

The unknown variables are given as;


X=
4.3240
-2.2012

-0.1908
Ex. N0 : 5 MATLAB program for solving the System of Linear equations
using Gauss Seidal Iteration Method
MATLAB Program:

A=input('Enter matrix A: ');


B=input('Enter the value B: ');
P=input('Enter initial gauss vector: ');
n=input('Enter no. of iterations:');
e=input('Error value:');
N=length(B);
X=zeros(N,1);
for j=1:n
for i=1:N
X(i)= (B(i)/A(i,i))-(A(i,[1:i-1,i+1:N])*P([1:i-1,i+1:N]))/A(i,i);
end
fprintf('iteration no %d\n',j)
X
if abs(X-P)<e
break
P=X
end
end
PROGRAM INPUT

Enter matrix A: [10 3 1;3 10 2;1 2 10]


Enter the value B: [19;29;35]
Enter initial gauss vector: [0;0;0]
Enter no. of iterations:3
Error value:0.01

PROGRAM OUTPUT

X=

1.9000
2.9000
3.5000

iteration no 2

X=

1.9000
2.9000
3.5000

iteration no 3

X=

1.9000
2.9000
3.5000
Ex. N0 : 6 MATLAB program for solving the System of Linear equations
using Gauss Jordan Method
MATLAB Program:

A=input('Enter matrix A: ');


B=input('Enter the value B: ');
Aug =[A B];
e=input('Error value:');
N=length(B);
X=zeros(N,1);
for j=1:N % for columns
Aug(j, :)=Aug (j, :)/Aug (j,j)
for i=1:N % for rows
if i~=j
m=Aug(i,j);
Aug(i,:)=Aug(i,:)-m*Aug(j,:);
end
end
end
fprintf('Solution for the given system of equation is\n')
disp(Aug(:,end))
PROGRAM INPUT

Enter matrix A: [10 3 1;3 10 2;1 2 10]


Enter the value B: [19;29;35]
Error value:0.001

PROGRAM INPUT

Aug =

1.0000 0.3000 0.1000 1.9000


3.0000 10.0000 2.0000 29.0000
1.0000 2.0000 10.0000 35.0000

Aug =

1.0000 0.3000 0.1000 1.9000


0 1.0000 0.1868 2.5604
0 1.7000 9.9000 33.1000

Aug =

1.0000 0 0.0440 1.1319


0 1.0000 0.1868 2.5604
0 0 1.0000 3.0000

Solution for the given system of equation is


1
2
3
Ex. N0 : 7 MATLAB program Integrate numerically using Trapezoidal rule.
MATLAB Program:

f=input('Enter the function with @(x): ');


a=input('Enter lower limit a: ');
b=input('Enter lower limit b: ');
n=input('Enter the number subinterval: ');;
h=(b-a)/n;
s=0.5*(f(a)+f(b));
for i=1:n-1
s=s+f(a+i*h);
end
I=h*s;
fprintf('I=%6.6f\n',I)
PROGRAM INPUT

Enter the function with @(x): @(x) 1+exp(-x)*sin(4*x);


Enter lower limit a: 0
Enter lower limit b: 1
Enter the number subinterval: 5

PROGRAM OUTPUT

I=1.292525
Ex. N0 : 8 MATLAB program Integrate numerically using Simpson’ rule.
MATLAB Program:

f=input('Enter the Function with @(x): ');


a=input('Enter the lower limit:');
b=input('Enter the upper limit: ');
n=input('Enter the number of sub intervals:');
h=(b-a)/n;
if rem(n,2)==1
fprintf('\n Please enter valid n!!!');
n = input('\n Enter n as even number ');
end
k = 1:1:n-1;
S = f(a+k.*h);
Se = sum(S(2:2: n-1));
So = sum(S(1:2: n-1));
out= (h/3).*(f(a)+f(b)+2.* Se+4.* So);
fprintf('The value of integration is %f \n',out)
PROGRAM INPUT

Enter the Function with @(x): @(x) cos(x)-log(x)+exp(x);

Enter the lower limit:1

Enter the upper limit: 2

Enter the number of sub intervals: 20

PROGRAM OUTPUT
The value of integration is 4.195460
Ex. N0 : 9 MATLAB program to find the numerical solution of Ordinary
Differential equation using Euler's Method.
MATLAB Program:

f = input ('Enter function:');%right hand side of the equation


x0 = input ('Enter initial value of independent variable: ');
y0 = input ('Enter initial value of dependent variable: ');
h = input ('Enter step size: ');
xn = input ('Enter point at which you want to evaluate solution: ');
n = (xn-x0)/h;
x(1) = x0; y(1) = y0;
for i=1:n
y(i+1) = y(i) + h*f(x(i),y(i));
x(i+1) = x0 + i*h;
fprintf('y(%d) = %.4f\n' ,x(i+1),y(i+1))
end
PROGRAM INPUT:
Enter function :@(x,y)-20*y+7*exp(-0.5*x)
Enter initial value of independent variable: 0
Enter initial value of dependent variable: 5
Enter step size: 0.1
Enter point at which you want to evaluate solution: 2

PROGRAM OUTPUT:
y(1.000000e-01) = -4.3000
y(2.000000e-01) = 4.9659
y(3.000000e-01) = -4.3325
y(4.000000e-01) = 4.9350
y(5.000000e-01) = -4.3619
y(6.000000e-01) = 4.9070
y(7.000000e-01) = -4.3884
y(8.000000e-01) = 4.8817
y(9.000000e-01) = -4.4125
y(1) = 4.8588
y(1.100000e+00) = -4.4343
y(1.200000e+00) = 4.8381
y(1.300000e+00) = -4.4540
y(1.400000e+00) = 4.8194
y(1.500000e+00) = -4.4718
y(1.600000e+00) = 4.8024
y(1.700000e+00) = -4.4879
y(1.800000e+00) = 4.7871
y(1.900000e+00) = -4.5025
y(2) = 4.7732
Ex.N0 :10 MATLAB program to find the numerical solution of Ordinary
Differential equation using Runge – Kutta Method.
MATLAB Program:

f = input ('Enter function:');


%right hand side of the equation
x0 = input('Enter initial value of independent variable: ');
y0 = input ('Enter initial value of dependent variable: ');
h = input ('Enter step size: ');
xn = input('Enter point at which you want to evaluate solution: ');
n = (xn-x0)/h;
x(1) = x0; y(1) = y0;
for i=1:n
x(i+1) =x0 + i*h;
k1 = h*f(x(i),y(i));
k2 = h*f(x(i)+(h/2),y(i)+(k1/2));
k3 = h*f(x(i)+(h/2),y(i)+(k2/2));
k4 = h*f(x(i)+h,y(i)+(k3));
y(i+1) = y(i) +(1/6)*(k1+2*k2+2*k3+k4);
fprintf('y(%d) = %.4f\n' ,x(i+1),y(i+1))
end
PROGRAM INPUT:
Enter function: @(x,y)-20*y+7*exp(-0.5*x)
Enter initial value of independent variable: 0
Enter initial value of dependent variable: 5
Enter step size: 0.1
Enter point at which you want to evaluate solution: 2

PROGRAM OUTPUT:
y(1.000000e-01) = 1.8914
y(2.000000e-01) = 0.8443
y(3.000000e-01) = 0.4848
y(4.000000e-01) = 0.3551
y(5.000000e-01) = 0.3024
y(6.000000e-01) = 0.2758
y(7.000000e-01) = 0.2585
y(8.000000e-01) = 0.2445
y(9.000000e-01) = 0.2322
y(1) = 0.2207
y(1.100000e+00) = 0.2099
y(1.200000e+00) = 0.1996
y(1.300000e+00) = 0.1899
y(1.400000e+00) = 0.1806
y(1.500000e+00) = 0.1718
y(1.600000e+00) = 0.1634
y(1.700000e+00) = 0.1555
y(1.800000e+00) = 0.1479
y(1.900000e+00) = 0.1407
y(2) = 0.1338

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy