NMO LAB Manual - Merged
NMO LAB Manual - Merged
STUDENT NAME :
REGISTER NO :
YEAR/SEMESTER/SECTION :
BATCH :
TABLE OF CONTENTS
Marks Staff
S.No Date Title of the Exercises Page no
signature
ROOTS OF NON – LINEAR EQUATION USING
1
BISECTION METHOD
ROOTS OF NON – LINEAR EQUATION USING
NEWTON’S METHOD
2
SOLVE THE SYSTEM OF LINEAR EQUATIONS
USING GAUSS - ELIMINATION METHOD
3
SOLVE THE SYSTEM OF LINEAR EQUATIONS
USING GAUSS - SEIDAL ITERATION METHOD
4
SOLVE THE SYSTEM OF LINEAR EQUATIONS
USING GAUSS - JORDAN METHOD
5
TO FIND THE LARGEST EIGEN VALUE OF A
MATRIX BY POWER - METHOD
6
INTERPOLATION BY LAGRANGE POLYNOMIAL
7
INTERPOLATION BY NUWTON POLYNOMIAL
8
FIND AREA BY USING TRAPEZOIDAL RULE.
9
FIND AREA BY USING SIMPSON’S RULE.
10
OPTIMIZATION BY USING INTERPOLATION
11
METHOD
TO FIND THE MAXIMUM AND MINIMUM
12
ELEMENT OF THE ARRAY
REGULA FALSI (FALSE POSITION) METHOD
13
EX.NO:
DATE: ROOTS OF NON – LINEAR EQUATION USING BISECTION METHOD
AIM:
To write a program in “C” Language to find out the root of the Algebraic and Transcendental
equations using Bisection Method.
ALGORITHM:
Step - 7. X0=(x1+x2)/2
Step - 8. If f(x0)*f(x1)<0
Step - 9. X2=x0
Electrical Problems:
1. For a 10K3A Betatherm thermistor, A thermistor error of is acceptable. Find the range of the
resistance that is within the acceptable limit at 19ºC. Solve by using Bi-Section method.
2. For a 10K3A Betatherm thermistor, A thermistor error of is acceptable. Find the range of the
resistance that is within this acceptable limit at 20ºC. Solve by using Bi-Section method.
3. For a 10K3A Betatherm thermistor, A thermistor error of is acceptable. Find the range of the
resistance that is within this acceptable limit at 18ºC. Solve by using Bi-Section method.
PROGRAM:
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
float a=-1,b=-1,c,prv=-1;
int i;
char ch;
system("cls");
printf(" A\t\tB\t\tRoot\n");
//Iterration Table
while((ceil(10000*prv)/10000)!=(ceil(10000*c)/10000))
{
//Prv checks previous iteration value, loop terminates when root and
//prev are equal
prv=c;
c=((a+b)/2);
printf(" %.4lf\t\t%.4f\t\t%.4f\n",a,b,c);
if(f(a)>f(b)) //f(a)>f(b)
{
if(f(c)>0)
a=c;
else
b=c;
}
else //f(b)>f(a)
{
if(f(c)>0)
b=c;
else
a=c;
}
}
printf("\nThe Aproximate Root is %.4f",c);
getch();
}
INPUT/OUTPUT:
INFERENCE:
RESULT:
The roots of nonlinear equation are calculated using bi section method and the same is verified by the
execution of the program.
EX.NO:
DATE: ROOTS OF NON – LINEAR EQUATION USING NEWTON’S METHOD
AIM:
ALGORITHM :
Electrical Problem:
1. For a 10K3A Betatherm thermistor, A thermistor error of is acceptable. Find the range of the
resistance that is within this acceptable limit at 17ºC. Solve by using Newton raphson method.
2. For a 10K3A Betatherm thermistor, A thermistor error of is acceptable. Find the range of the
resistance that is within this acceptable limit at 21ºC. Solve by using Newton raphson method.
3. For a 10K3A Betatherm thermistor, A thermistor error of is acceptable. Find the range of the
resistance that is within this acceptable limit at 22ºC. Solve by using Newton raphson method.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define f(x) ((3*x)-cos(x)-1) //Function
#define f1(x) (3+sin(x)) //Derivative of the function
void main()
{
float a=-1,b=-1,c,prv=-1;
int i;
char ch;
system("cls");
printf("Do you want to choose interval (y/n)?: ");
scanf("%c",&ch);
if (ch=='y'||ch=='Y')
{
printf("Enter value of A and B\n");
scanf("%f%f",&a,&b);
}
else
{
for(i=0;a==-1||b==-1;i++)
{
if(f(0)<0)
{
if(f(i)<0)
a=i;
if(f(i)>0)
b=i;
}
else
{
if(f(i)>0)
a=i;
if(f(i)<0)
b=i;
}
}
printf("\nFinding values of A and B...\nA=%.f\nB=%.f\n",a,b);
}
printf(" Itt\t\t\tRoot\n");
c=(abs(f(a))<=abs(f(b)))?a:b;
i=0;
while((ceil(10000*prv)/10000)!=(ceil(10000*c)/10000))
{
prv=c;
c=(c-(f(c)/f1(c)));
printf(" %d\t\t%.4f\n",i,c);
i++;
}
printf("\nThe Aproximate Root is %.4f",c);
}
INPUT/OUTPUT:
INFERENCE:
RESULT:
The roots of nonlinear equation are calculated using newton raphson’s method and the same is verified by
execution of the program.
EX.NO: SOLVE THE SYSTEM OF LINEAR EQUATIONS USING GAUSS -
DATE: ELIMINATION METHOD
AIM:
To write a C program to implement the system of linear equations using gauss - elimination
method.
ALGORIHTM:
Step – 1 Start
Step – 8 Stop
Exercise Problem:
1. Solve the system of equation by gauss elimination method 2x+3y-z=5, 4x+4y-3z=3, 2x-3y+2z=2
2. Solve the following systems of linear equations by Gaussian elimination method 2x - 2 y + 3z = 2, x + 2 y - z =
3, 3x - y + 2z = 1
3. Solve the following systems of linear equations by Gaussian elimination method 2x + 4 y + 6z = 22, 3x + 8 y +
5z = 27, - x + y + 2z = 2
4. Use Gaussian elimination to find the solution for the given system of equations. 3x + y - z = 1, x - y + z = -3,
2x + y + z = 0
5. Use Gaussian elimination to find the solution for the given system of equations. 2x + 5y = 9, x + 2y - z = 3,
-3x - 4y + 7z = 1
Electrical Problem:
2. For the circuit shown below, determine the mesh currents and branch currents using mesh analysis.
3. For the circuit shown, determine the mesh currents and branch currents using mesh analysis.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int i,j,k,n;
float a[10][10], x[10], r;
system("cls");
printf("Enter order of the matrix: “);
scanf(“%d”,&n);
printf("Enter the values:\n\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
printf("a[%d][%d] = ",i,j);
scanf("%f", &a[i][j]);
}
}
for(i=1;i<=n-1;i++)
{
if(a[i][i] == 0.0)
{
printf("Error");
exit(0);
}
for(j=i+1;j<=n;j++)
{
r = a[j][i]/a[i][i];
for(k=1;k<=n+1;k++)
{
a[j][k] = a[j][k] - r*a[i][k];
}
}
}
x[n] = a[n][n+1]/a[n][n];
for(i=n-1;i>=1;i--)
{
x[i] = a[i][n+1];
for(j=i+1;j<=n;j++)
{
x[i] = x[i] - a[i][j]*x[j];
}
x[i] = x[i]/a[i][i];
}
printf("\nAnswer:\n");
return(0);
}
INPUT/OUTPUT:
INFERENCE:
RESULT:
The system of linear equation are solved using gauss elimination method and the results are obtained for
both theoretical calculation and program execution.
EX.NO: SOLVE THE SYSTEM OF LINEAR EQUATIONS USING GAUSS -
DATE: SEIDAL ITERATION METHOD
AIM:
To write a C program to implement the system of linear equations using gauss - seidal iteration
method.
ALGORITHM:
Step –7 Return to step 4 while x1, y1, z1not equal to x0, y0, z0
Electrical Problem:
1. Find the value of the currents I1, I2 and I3 flowing clockwise in the first, second and third mesh respectively.
2. Find the value of the currents I1 and I2 flowing clockwise in the first and second mesh respectively.
3. For the given electrical circuit. Write the loop equations and obtain the loop current using Gauss – seidel iterative
method.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
INFERENCE:
RESULT:
The system of linear equation are solved using gauss seidal iteration method and the results are obtained for both theoretical
calculation and program execution.
EX.NO: SOLVE THE SYSTEM OF LINEAR EQUATIONS USING GAUSS -
DATE: JORDAN METHOD
AIM:
To write a C program to implement the system of linear equations using Gauss – Jordan method.
ALGORITHM:
Step – 1 Start
Step – 7 Stop
Exercise Problem: Solve by using Gauss Jordan Method
1. Example 2x+5y=21, x+2y=8
2. Example 2x+5y=16, 3x+y=11
3. Example 2x+3y-z=5, 3x+2y+z=10, x-5y+3z=0
4. Example x+y+z=3, 2x-y-z=3, x-y+z=9
Electrical Problems:
1. Find the current flowing through 1 Ω resistance by using Kirchhoff’s voltage law / Mesh analysis.
2. By using Kirchhoff’s voltage law (KVL) / Mesh analysis find the current flowing through a 4 Ω resistor.
3. Set up and solve the system of equations for the currents i1, i2 and i3 in the branches of the given electrical
network using Gauss- Jordan elimination method.
PROGRAM:
#include<stdio.h>
#include<math.h>
int main()
{
float a[10][ 10], x[10], ratio;
int i,j,k,n;
printf("Enter number of unknowns: ");
scanf("%d", &n);
printf("Enter coefficients of Augmented Matrix:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
printf("a[%d][%d] = ",i,j);
scanf("%f", &a[i][j]);
}
}
for(i=1;i<=n;i++)
{
if(a[i][i] == 0.0)
{
printf("Mathematical Error!");
exit(0);
}
for(j=1;j<=n;j++)
{
if(i!=j)
{
ratio = a[j][i]/a[i][i];
for(k=1;k<=n+1;k++)
{
a[j][k] = a[j][k] - ratio*a[i][k];
}
}
}
}
for(i=1;i<=n;i++)
{
x[i] = a[i][n+1]/a[i][i];
}
/* Displaying Solution */
printf("\nSolution:\n");
for(i=1;i<=n;i++)
{
printf("x[%d] = %0.3f\n",i, x[i]);
}
getch();
return(0);
}
INPUT/OUTPUT:
INFERENCE:
RESULT:
The system of linear equation are solved using gauss Jordan method and the results are obtained for
both theoretical calculation and program execution.
.
EX.NO: TO FIND THE LARGEST EIGEN VALUE OF A MATRIX BY POWER -
DATE: METHOD
AIM:
To write a C program to implement the largest Eigen value of a matrix by power - method.
ALGORITHM:
Electrical Problem:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
void main()
{
int i,j,n;
float A[40][40],x[40],z[40],p[40],max;
system("cls");
printf("\nEnter the order of matrix:");
scanf("%d",&n);
printf("\nEnter matrix elements row-wise\n");
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
printf("A[%d][%d]=", i,j);
scanf("%f",&A[i][j]);
}
}
printf("\nEnter the column vector\n");
for(i=1; i<=n; i++)
{
printf("X[%d]=",i);
scanf("%f",&x[i]);
}
while(1)
{
for(i=1; i<=n; i++)
{
p[i]=z[i];
}
for(i=1; i<=n; i++)
{
z[i]=0;
for(j=1; j<=n; j++)
{
z[i]=z[i]+A[i][j]*x[j];
}
}
max= z[1];
for(i=2; i<=n; i++)
{
if((z[i])>max)
max= z[i];
}
for(i=1; i<=n; i++)
{
z[i]=z[i]/max;
}
RESULT:
The largest eigen value is obtained by power method and that is verified both theoretically and by
execution of the program.
EX.NO:
INTERPOLATION BY LAGRANGE POLYNOMIAL
DATE:
AIM:
To write a C program to implement by using. interpolation by Lagrange polynomial
ALGORITHM:
STEP 1: Read x, n
prodfunc <- 1
for j := 1 to (n + 1) in steps of 1 do
If (j ≠ i) then
endfor
endfor
STEP 7: Stop
Exercise Problem:
1. Interpolate the value of the function corresponding to X= 4 using Lagrange’s interpolation formula from the
following set of data:
x 2 3 5 8 12
f(x) 10 15 25 40 60
2. The population of Mississippi during three census periods was as follows: Interpolate the population during 1966.
3. Using Lagrange’s interpolation formula find y (10) from the following table:
Electrical Problem:
1. A generating station has the following daily load cycle apply lagrange interpolation and find out the load
demand.
Time (Hours) 4 6 8 10 12
Load (Mw) 40 50 60 50 70
2. A power station has the following daily load cycle apply lagrange interpolation and find out the load
demand.
Time (Hours) 6 8 12 16 20
Load (Mw) 20 40 60 80 20
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
int i,j,n;
/* Input Section */
scanf("%d", &n);
printf("Enter data:\n");
for(i=1;i<=n;i++)
scanf("%f", &x[i]);
scanf("%f", &y[i]);
scanf("%f", &xp);
for(i=1;i<=n;i++)
{
p=1;
for(j=1;j<=n;j++)
if(i!=j)
yp = yp + p * y[i];
}
INPUT/OUTPUT:
RESULT:
The given problem is solved by Lagrange polynomial method both theoretically and practically.
EX.NO:
INTERPOLATION BY NEWTON POLYNOMIAL
DATE:
AIM:
To write a C program to implement by using. Interpolation by Newton Polynomial
ALGORITHM:
STEP 1: Start the Program
FUNCTION PROTERM
float pro := 1;
for j := 0 to i then
endfor
return pro;
FUNCTION DIVIDEDDIFFTABLE
for i := 1 to n then
endfor
endfor
FUNCTION APPLYFORMULA
for i := 1 to n then
endfor
return sum;
FUNCTION PRINTDIFFTABLE
printDiffTable(float y[][10],int n)
for i := 0 to n then
write(y[i][j])
endfor
write(" ")
endfor
1. The following supply schedule gives the quantities supplied (S) in hundreds of a product at prices (P) in rupees:
Interpolate the quantity of the product supplied at the price dollar 85.
S 25 30 42 50 68
2. The production of vegetable oil is recorded on a fiscal year basis in alternate years: Estimate the production during
1997 – 98.
3. Find the first two derivative of x1/3 when x=50 and 56, given the table below:
X 50 51 52 53 54 55 56
Electrical Problem:
1. A generating station has the following daily load cycle find the load demand using netwon polynomial
method.
Time (Hours) 2 4 6 8 10
Load (Mw) 40 60 70 80 70
2. A power station has the following daily load cycle find the load demand using newton polynomial
method.
Time (Hours) 3 5 7 9 10
Load (Mw) 20 40 60 80 20
PROGRAM:
#include<stdio.h>
float pro = 1;
return pro;
return sum;
printf(" ");
// Driver Function
int main()
int n ;
float x[10];
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%f",&x[i]);
for(int i=0;i<n;i++)
scanf("%f",&y[i][0]);
dividedDiffTable(x, y, n);
printDiffTable(y,n);
scanf("%f",&value);
return 0;
}
INPUT AND OUTPUT:
RESULT:
The given problem is solved by Newton polynomial method both theoretically and practically.
EX.NO:
FIND AREA BY USING TRAPEZOIDAL RULE
DATE:
AIM:
To write a C program to implement find area by using trapezoidal rule.
ALGORITHM:
Step – 1 Start
Step – 3 Read lower limit of integration, upper limit of integration and number of sub
interval
Step – 4 Calculate: step size = (upper limit - lower limit)/number of sub interval
Step – 6 Set: i = 1
1. Find the area enclosed by the function f(x) between x = 0 to x = 4 with 4 intervals. f(x) = 4
2. Find the area enclosed by the function f(x) between x = 0 to x = 3 with 3 intervals. f(x) = x
3. Find the area enclosed by the function f(x) between x = 0 to x = 2 with 2 intervals. f(x) = 2x
4. Find the area enclosed by the function f(x) between x = 0 to x = 3 with 3 intervals. f(x) = x2
Electrical Problem:
1. The high voltage transmission line runs to 2km length with radius 2cm. Find the cross sectional area by trapezoidal
rule.
2. A short transmission line runs to 8km length with radius 4cm. Find the cross sectional area by trapezoidal rule.
3. A Medium transmission line runs to 10km length with radius 3cm. Find the cross sectional area by trapezoidal rule.
4. The high voltage transmission line runs to 3km length with radius 2cm. Find the cross sectional area by trapezoidal
rule.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
/* Define function here */
#define f(x) 1/(1+pow(x,2))
int main()
{
float lower, upper, integration=0.0, stepSize, k;
int i, subInterval;
clrscr();
/* Input */
printf("Enter lower limit of integration: ");
scanf("%f", &lower);
printf("Enter upper limit of integration: ");
scanf("%f", &upper);
printf("Enter number of sub intervals: ");
scanf("%d", &subInterval);
/* Calculation */
/* Finding step size */
stepSize = (upper - lower)/subInterval;
RESULT:
The area for the given problem is found out using trapezoidal rule both theoretically and practically.
EX.NO:
FIND AREA BY USING SIMPSON’S RULES
DATE:
AIM:
ALGORITHM:
Step – 1 Start
Step – 3 Read lower limit of integration, upper limit of integration and number of sub
interval
Step – 4 Calculate: step size = (upper limit - lower limit)/number of sub interval
Step – 6 Set: i = 1
Electrical Problem:
1. The transmission ASCI conductor has the radius of 6 cm. Find the cross sectional area of the conductor by
simpson’ s rule.
2. The transmission ASCI conductor has the radius of 8 cm. Find the cross sectional area of the conductor by
simpson’s rule.
3. The transmission ASCI conductor has the radius of 10 cm. Find the cross sectional area of the conductor
by simpson’s rule .
4. The transmission ASCI conductor has the radius of 12 cm. Find the cross sectional area of the conductor
by simpson’s rule.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
/* Define function here */
#define f(x) 1/(1+x*x)
int main()
{
float lower, upper, integration=0.0, stepSize, k;
int i, subInterval;
clrscr();
/* Input */
printf("Enter lower limit of integration: ");
scanf("%f", &lower);
printf("Enter upper limit of integration: ");
scanf("%f", &upper);
printf("Enter number of sub intervals: ");
scanf("%d", &subInterval);
/* Calculation */
/* Finding step size */
stepSize = (upper - lower)/subInterval;
RESULT:
The area for the given problem is found out using simpsons rule both theoretically and practically .
.
EX.NO:
OPTIMIZATION BY USING INTERPOLATION METHOD
DATE:
AIM:
ALGORITHM:
Step 1: Start
Step 4: Read value of independent variables say xp whose corresponding value of dependent say
yp is to be determined.
Step 5: Initialize: yp = 0
Step 6: For i = 1 to n
Set p = 1
For j =1 to n
If i ≠ j then
Calculate p = p * (xp - Xj)/(Xi - Xj)
End If
Next j
Calculate yp = yp + p * Yi
Next i
Step 7: Stop
Exercise Problem:
1. Interpolate the value of the function corresponding to X= 4 using Lagrange’s interpolation formula from
the following set of data:
x 2 3 5 8 12
f(x) 10 15 25 40 60
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
float x[100], y[100], xp, yp=0, p;
int i,j,n;
clrscr();
/* Input Section */
printf("Enter number of data: ");
scanf("%d", &n);
printf("Enter data:\n");
for(i=1;i<=n;i++)
{
printf("x[%d] = ", i);
scanf("%f", &x[i]);
printf("y[%d] = ", i);
scanf("%f", &y[i]);
}
printf("Enter interpolation point: ");
scanf("%f", &xp);
/* Implementing Lagrange Interpolation */
for(i=1;i<=n;i++)
{
p=1;
for(j=1;j<=n;j++)
{
if(i!=j)
{
p = p* (xp - x[j])/(x[i] - x[j]);
}
}
yp = yp + p * y[i];
}
printf("Interpolated value at %.3f is %.3f.", xp, yp);
getch();
}
INPUT/OUTPUT:
Enter number of data: 5 ↲
Enter data:
x[1] = 5 ↲
y[1] = 150 ↲
x[2] = 7 ↲
y[2] = 392 ↲
x[3] = 11 ↲
y[3] = 1452 ↲
x[4] = 13 ↲
y[4] = 2366 ↲
x[5] = 17 ↲
y[5] = 5202 ↲
Enter interpolation point: 9 ↲
Interpolated value at 9.000 is 810.000.
RESULT:
AIM:
To write a C program to find the maximum and minimum element of the array.
ALGORITHM:
Step 1: Let maxE and minE be the variable to store the minimum and maximum element of the array.
Step 2: Initialise minE as INT_MAX and maxE as INT_MIN.
Step 3: Traverse the given array arr[].
Step 4: If the current element is smaller than minE, then update the minE as current element.
Step 5: If the current element is greater than maxE, then update the maxE as current element.
Step 6: Repeat the above two steps for the element in the array.
PROGRAM:
#include <limits.h>
#include <stdio.h>
return;
}
// Driver Code
int main()
{
// Given array
int arr[] = { 1, 2, 4, -1 };
// Function call
findMinimumMaximum(arr, N);
return 0;
}
CONTENTS MAX.MARKS MARKS OBTAINED
MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25
RESULT:
The given problem is solved and the maximum and minimum point on array is found out.
EX.NO:
REGULA FALSI (FALSE POSITION) METHOD
DATE:
AIM:
To write a C program to implement regula falsi method
ALGORITHM:
Step 1: Start
Step :9 Stop
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
/* Defining equation to be solved.
Change this equation to solve another problem. */
#define f(x) x*log10(x) - 1.2
int main()
{
if(f0*f2 < 0)
{
x1 = x2;
f1 = f2;
}
else
{
x0 = x2;
f0 = f2;
}
step = step + 1;
}while(fabs(f2)>e);
Step x0 x1 x2 f(x2)
1 2.000000 3.000000 2.721014 -0.017091
2 2.721014 3.000000 2.740206 -0.000384
3 2.740206 3.000000 2.740636 -0.000009
4 2.740636 3.000000 2.740646 -0.000000
RESULT: