0% found this document useful (0 votes)
16 views70 pages

NMO LAB Manual - Merged

Uploaded by

kkyoto24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views70 pages

NMO LAB Manual - Merged

Uploaded by

kkyoto24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING

NUMERICAL METHODS AND OPTIMIZATION LAB


V SEMESTER

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 - 1 Start of the program.

Step - 2. Input the variable x1, x2 for the task.

Step - 3. Check f(x1)*f(x2)<0

Step - 4. If yes proceed

Step - 5. If no exit and print error message

Step - 6. Repeat 7-11 if condition not satisfied

Step - 7. X0=(x1+x2)/2

Step - 8. If f(x0)*f(x1)<0

Step - 9. X2=x0

Step - 10. Else

Step - 11. X1=x0

Step - 12. Condition:

Step - 13. if | (x1-x2)/x1) | < maximum possible error orf(x0)=0

Step - 14. Print output

Step - 15. End of program.


Exercise Problems:

1. Find the positive root of f(x)= x3-4x-9 by using bisection method.


2. Find the positive roots of f(x)=x3-x-1 by using bisection method.
3. Find the positive roots of f(x)= x-cos(x) by using bisection method.
4. Find the positive root of f(x)= x*sin(x)-1 by using bisection method.

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>

/*Uncomment the function u want to use or else add u r own*/

#define f(x) ((x*x*x)-(4*x)-9)


#define f(x) ((x*x*x)-(x)-1)
#define f(x) ((x)-(cos(x)))
#define f(x) ((x*sin(x))-1)
#define f(x) ((exp(x))-(3*x))
#define f(x) ((x*x*x)-(9*x)+1) //”range to be entered mannually 2,4”

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 interval exists
if (ch=='y'||ch=='Y')
{
printf("Enter value of A and B\n");
scanf("%f%f",&a,&b);
}
//For finding intervals automatically
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(" 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:

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

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:

To write a program in “C” Language to implement Newton’s Raphson method.

ALGORITHM :

Step 1. Start the program.

Step 2. Define the function f(x), f’(x)

Step 3. Enter the initial guess of the root , say x0

Step 4. Calculate xn+1 = xn – [f(xn)/ f’(xn)], n = 0, 1, 2, …

Step 5. If |xn+1 – xn| < ϵ, ϵ being prescribed accuracy then go to step 7.

Step 6. Set xn = xn+1 and go to step 4.

Step 7. Print the value of xn.

Step 8. Stop the program.


Exercise Problems:
1. Find the positive root of f(x)= 3x-cos(x)+1 using newton raphson method.
2. For the initial value x0 = 3, approximate the root of f(x)=x3+3x+1.
3. For the initial value x0 = 1, approximate the root of f(x)=x2−5x+1.
4. Find the root of the equation f(x) = x3 – 5x + 3 = 0, if the initial value is 3.
5. Find the root of the equation f(x) = x3 – 3 = 0, if the initial value is 2.

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:

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

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 – 2 Declare required variables

Step – 3 Read Order of Matrix (n)

Step – 4 Read Matrix A

Step – 5 Transform Augmented Matrix (A) to Upper Triangular Matrix by Row


Operations.

Step – 6 Obtain Solution by Back Substitution.

Step – 7 Print the result.

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:

1. Determine the mesh currents in the circuit shown below.

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");

printf("x = %0.3f\n", x[1]);


printf("y = %0.3f\n", x[2]);
printf("z = %0.3f\n", x[3]);

return(0);
}
INPUT/OUTPUT:

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

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 – 1 Start the program

Step – 2 Define 3 functions for 3 equations

Step – 3 Declare required variables

Step – 4 Assign values of x1, y1, z1 to x0, y0, z0

Step – 5 Assign values of f1(),f2(),f3() to x1, y1, z1

Step – 6 Print Values of x1, y1, z1

Step –7 Return to step 4 while x1, y1, z1not equal to x0, y0, z0

Step – 8 Print x1,y1,z1

Step – 9 End the program


Exercise Problems:

1. Solve by gauss seidal method 2x+y=8, x+2y=1


2. Solve by gauss seidal method 2x+5y=16, 3x+y=11
3. Solve by gauss seidal method 2x+y+z=5, 3x+5y+2z=15, 2x+y+4z=8
4. Solve by gauss seidal method x+y+z=7, x+2y+2z=13, x+3y+z=13

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>

#define f1(x,y,z) (85-6*y-z)/27


#define f2(x,y,z) (72-6*x-2*z)/15
#define f3(x,y,z) (110-x+y)/54
int main()
{
float x0, y0, z0, x1, y1, z1;
int count=1;
system("cls");
printf("\nCount\tx\ty\tz\n");
do
{
x0 = x1;
y0 = y1;
z0 = z1;
x1 = f1(x1,y1,z1);
y1 = f2(x1,y1,z1);
z1 = f3(x1,y1,z1);
printf("%d\t%0.4f\t%0.4f\t%0.4f\n",count, x1,y1,z1);
count++;
}while(x0!=x1 && y0!=y1 && z0!=z1);
printf("\nSolution: x=%0.3f, y=%0.3f and z = %0.3f\n",x1,y1,z1);
getch();
return 0;
}
INPUT AND OUTPUT:

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

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 – 2 Read Number of Unknowns: n

Step – 3 Read Augmented Matrix (A) of n by n+1 Size

Step – 4 Transform Augmented Matrix (A) to Diagonal Matrix by Row Operations.

Step – 5 Obtain Solution by Making All Diagonal Elements to 1.

Step – 6 Display Result.

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:

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

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:

Step – 1 Start the program

Step – 2 Declare required variables

Step – 3 Read Order of Matrix (n)

Step – 4 Read Matrix A

Step – 5 Read Initial Guess Vector x of Size n x 1

Step – 6 Assign values of matrix z to matrix p

Step – 7 Multiply matrix: z = A * x

Step – 8 Assign first element of matrix z to max

Step – 9 Find the highest value of matrix z using max

Step – 10 Divide matrix z by max

Step – 11 Round matrix z and assign its values to matrix x

Step – 12 Call function cp() if 1 is not returned, return to Step – 5

Step – 13 Print Eigen vector and values

Step – 14 End the program


Exercise Problem:

1. Find the numerically largest eigen value of by power method.

2. Find the largest eigenvalue of by using Power method.

3. Find, by power method, the largest eigenvalue

Electrical Problem:

1. Solve the given circuit using nodal analysis

2. Solve the give circuit using nodal analysis


PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>

int cp(float z[],float p[],int n)


{
if (n==0)
return 0;
else if(z[n]==p[n])
{
n--;
cp(z,p,n);
return 1;
}
else
return 0;
}

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;
}

for(i=1; i<=n; i++)


{
z[i]=round(10*z[i])/10;
x[i]=z[i];
}
if(cp(z,p,n)==1)
break;
}
printf("\n The required eigen value is %f",round(max));
printf("\n\nThe required eigen vector is :\n");
for(i=1; i<=n; i++)
{
printf("%f\t",z[i]);
}
getch();
}
INPUT/OUTPUT:

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

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

STEP 2: for i := 1 to (n + 1) in steps of 1 do Read xi, fi end for sum <- 0

STEP 3: for i =1 to (n + 1) in steps of 1 do

prodfunc <- 1

for j := 1 to (n + 1) in steps of 1 do

If (j ≠ i) then

prodfunc <- prodfunc * (x - xj)/(xi - xj)

endfor

STEP 5: sum <- sum + fi * prodfunc

endfor

STEP 6: Write x, sum

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.

Year 1951 1961 1971


Population 2.8 3.2 4.5
(Million)

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()

float x[100], y[100], xp, yp=0, p;

int i,j,n;

/* 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);

}
INPUT/OUTPUT:

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

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

STEP 2: Functions for Call

FUNCTION PROTERM

proterm(int i, float value, float x[])

float pro := 1;

for j := 0 to i then

pro := pro * (value - x[j])

endfor

return pro;

FUNCTION DIVIDEDDIFFTABLE

dividedDiffTable(float x[], float y[][10], int n)

for i := 1 to n then

for j := 0 to n-i then

y[j][i] := (y[j][i - 1] - y[j + 1][i - 1]) / (x[j] - x[i + j])

endfor

endfor

FUNCTION APPLYFORMULA

applyFormula(float value, float x[],float y[][10], int n)


{

float sum := y[0][0]

for i := 1 to n then

sum := sum + (proterm(i, value, x) * y[0][i]);

endfor

return sum;

FUNCTION PRINTDIFFTABLE

printDiffTable(float y[][10],int n)

for i := 0 to n then

for j := 0 to (n-i) then

write(y[i][j])

endfor

write(" ")

endfor

STEP 3: Call FUNCTION DIVIDEDDIFFTABLE

STEP 4: Call FUNCTION PRINTDIFFTABLE

STEP 5: Call APPLYFORMULA

->IN APPLYFORMULA PROTERM function is called.

STEP6: Print the Output.

STEP 7: End the Program.


Exercise Problem:

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.

P 80 90 100 110 120

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.

Year 1990-91 1992-93 1994-95 1996-97 1998-99

Production 35.5 42.8 45.8 46.5 50.3

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

Y 3.6840 3.7084 3.7325 3.7563 3.7798 3.8030 3.8259

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>

// Function to find the product term

float proterm(int i, float value, float x[])

float pro = 1;

for (int j = 0; j < i; j++) {

pro = pro * (value - x[j]);

return pro;

void dividedDiffTable(float x[], float y[][10], int n)

for (int i = 1; i < n; i++) {

for (int j = 0; j < n - i; j++) {

y[j][i] = (y[j][i - 1] - y[j + 1]

[i - 1]) / (x[j] - x[i + j]);

// Function for applying Newton's

// divided difference formula

float applyFormula(float value, float x[],

float y[][10], int n)

float sum = y[0][0];


for (int i = 1; i < n; i++) {

sum = sum + (proterm(i, value, x) * y[0][i]);

return sum;

// Function for displaying

// divided difference table

void printDiffTable(float y[][10],int n)

for (int i = 0; i < n; i++) {

for (int j = 0; j < n - i; j++) {

printf("%.4f ", y[i][j]);

printf(" ");

// Driver Function

int main()

// number of inputs given

int n ;

float value, sum, y[10][10];

float x[10];

printf("Enter No of variables: ");

scanf("%d",&n);

printf("Enter the value of x: \n");

for(int i=0;i<n;i++)

{
scanf("%f",&x[i]);

printf("Enter the value of y:\n");

for(int i=0;i<n;i++)

scanf("%f",&y[i][0]);

// calculating divided difference table

dividedDiffTable(x, y, n);

// displaying divided difference table

printDiffTable(y,n);

printf("\nEnter the value to be interpolated: ");

scanf("%f",&value);

// printing the value

printf("Value at %f is %f\n",value,applyFormula(value, x, y, n));

return 0;

}
INPUT AND OUTPUT:

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

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 – 2 Define function f(x)

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 – 5 Set: integration value = f(lower limit) + f(upper limit)

Step – 6 Set: i = 1

Step – 7 If i > number of sub interval then goto

Step – 8 Calculate: k = lower limit + i * h

Step – 9 Calculate: Integration value = Integration Value + 2* f(k)

Step – 10 Increment i by 1 i.e. i = i+1 and go to step 7

Step – 11 Calculate: Integration value = Integration value * step size/2

Step – 12 Display Integration value as required answer

Step – 13 Stop the Program


Exercise Problem:

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;

/* Finding Integration Value */


integration = f(lower) + f(upper);
for(i=1; i<= subInterval-1; i++)
{
k = lower + i*stepSize;
integration = integration + 2 * f(k);
}
integration = integration * stepSize/2;
printf("\nRequired value of integration is: %.3f", integration);
getch();
return 0;
}
INPUT AND OUTPUT:

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

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:

To write a C program to implement find area by using Simpson’s 1/3 rule.

ALGORITHM:

Step – 1 Start

Step – 2 Define function f(x)

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 – 5 Set: integration value = f(lower limit) + f(upper limit)

Step – 6 Set: i = 1

Step – 7 If i > number of sub interval then go to 8

Step – 8 Calculate: k = lower limit + i * h

Step – 9 If i mod 2 =0 then


Integration value = Integration Value + 2* f(k)
Otherwise
Integration Value = Integration Value + 4 * f(k)
End If

Step – 10 Increment i by 1 i.e. i = i+1 and go to step 7

Step – 11 Calculate: Integration value = Integration value * step size/3

Step – 12 Display Integration value as required answer

Step – 13 Stop the program


Exercise Problem:
2

1. Estimate the integral ∫ e d x using Simpson's method by taking n = 4.
1
3
2. Evaluate ∫ x4 dx by using Simpson’s rule.
-3
2
3. Approximate the integral ∫ sin √ x d x using Simpson's rule formula when n = 8.
0

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;

/* Finding Integration Value */


integration = f(lower) + f(upper);
for(i=1; i<= subInterval-1; i++)
{
k = lower + i*stepSize;
if(i%2==0)
{
integration = integration + 2 * f(k);
}
else
{
integration = integration + 4 * f(k);
}
}
integration = integration * stepSize/3;
printf("\nRequired value of integration is: %.3f", integration);
getch();
return 0;
}
INPUT/OUTPUT:

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

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:

To write a C program to implement the optimization by using interpolation method

ALGORITHM:

Step 1: Start

Step 2: Read number of data (n)

Step 3: Read data Xi and Yi for i=1 ton n

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 6: Display value of yp as interpolated value.

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.

Note: ↲ indicates ENTER is pressed.

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

RESULT:

Thus the optimization is carried out using interpolation method


EX.NO:
TO FIND THE MAXIMUM AND MINIMUM
DATE: ELEMENT OF THE ARRAY

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>

// Function to find the minimum and


// maximum element of the array
void findMinimumMaximum(int arr[], int N)
{
int i;

// variable to store the minimum


// and maximum element
int minE = INT_MAX, maxE = INT_MIN;

// Traverse the given array


for (i = 0; i < N; i++) {

// If current element is smaller


// than minE then update it
if (arr[i] < minE) {
minE = arr[i];
}

// If current element is greater


// than maxE then update it
if (arr[i] > maxE) {
maxE = arr[i];
}
}

// Print the minimum and maximum element


printf("The minimum element is %d", minE);
printf("\n");
printf("The maximum element is %d", maxE);

return;
}

// Driver Code
int main()
{

// Given array
int arr[] = { 1, 2, 4, -1 };

// length of the array


int N = sizeof(arr) / sizeof(arr[0]);

// 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 2: Define function f(x)

Step 3: Choose initial guesses x0 and x1 such that f(x0)f(x1) < 0

Step 4: Choose pre-specified tolerable error e.

Step 5: Calculate new approximated root as:

x2 = x0 - ((x0-x1) * f(x0))/(f(x0) - f(x1))

Step 6: Calculate f(x0)f(x2)


a. if f(x0)f(x2) < 0 then x0 = x0 and x1 = x2
b. if f(x0)f(x2) > 0 then x0 = x2 and x1 = x1
c. if f(x0)f(x2) = 0 then goto (8)

Step 7: if |f(x2)|>e then goto (5) otherwise goto (8)

Step 8: Display x2 as root.

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()
{

float x0, x1, x2, f0, f1, f2, e;


int step = 1;
clrscr();
/* Inputs */
up:
printf("\nEnter two initial guesses:\n");
scanf("%f%f", &x0, &x1);
printf("Enter tolerable error:\n");
scanf("%f", &e);
/* Calculating Functional Values */
f0 = f(x0);
f1 = f(x1);
/* Checking whether given guesses brackets the root or not. */
if( f0*f1 > 0.0)
{
printf("Incorrect Initial Guesses.\n");
goto up;
}
/* Implementing Regula Falsi or False Position Method */
printf("\nStep\t\tx0\t\tx1\t\tx2\t\tf(x2)\n");
do
{
x2 = x0 - (x0-x1) * f0/(f0-f1);
f2 = f(x2);
printf("%d\t\t%f\t%f\t%f\t%f\n",step, x0, x1, x2, f2);

if(f0*f2 < 0)
{
x1 = x2;
f1 = f2;
}
else
{
x0 = x2;
f0 = f2;
}
step = step + 1;
}while(fabs(f2)>e);

printf("\nRoot is: %f", x2);


getch();
return 0;
}
INPUT AND OUTPUT:

Enter two initial guesses:


2
3
Enter tolerable error:
0.000001

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

Root is: 2.740646

CONTENTS MAX.MARKS MARKS OBTAINED


MANUAL CALCULATION 10
EXECUTION & OUTPUT 10
VIVA 5
TOTAL 25

RESULT:

The given problem is solved by Regula Falsi method.

You might also like