Limited-time offer! Save up to 50% Off | Solutions starting at \$6 each

# COMP 208: Computers in Engineering

Added on - 07 Nov 2021

• COMP 208

Course

• 4

Pages

• 660

Words

• 29

Views

• 0

• Save

Share

Showing pages 1 to 2 of 4 pages
/*
*COMP 208: COMPUTERS IN ENGINEERING
*WINTER 2018 ASSIGNMENT 4
* WHISKEY PRODUCTION USING A BATCH DISTILLATION COLUMN
*
*/
//PART ONE
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define ME 2.7182818284590452354E0 /* Euler's number */
float y(float x)
{
// Declaring the function f(x) = 1/(x) from integral(f(x)dx)
return 1/(x);
}
// Function to evalute the value of integral: Trapezoidal
float Part1trap(float a, float b, float n)
{
// Grid spacing
float h = (b-a)/n;
// Computing sum of first and last terms
// in above formula
float s = y(a)+y(b);
// Adding middle terms in above formula
int i;
for (i = 1; i < n; i++)
s += 2*y(a+i*h);
// h/2 indicates (b-a)/2n. Multiplying h/2
// with s.
return (h/2)*s;
}
/* Integration using Simpson's rule */
float simpson (int no, float x0, float xn)
{
int r;
float interval, sum=0., x;
interval = ((xn -x0) /(no-1));
for (r=2; r<no; r+=2) /* loop for odd points */
{
x = interval * (r-1);
sum += 4 * y(x);
}
for (r=3; r<no; r+=2) /* loop for even points */
{
x = interval * (r-1);
sum += 2 * y(x);
}
sum += y(x0) + y(xn);/* add first and last value */
sum *= interval/3.;/* then multilpy by interval*/
return (sum);
}
//function to find roots of a function
void Part2Bisect(float *x, float x0, float xn, int *itr)
/* this function performs and prints the result of one iteration */
{
*x=(x0+xn)/2;
++(*itr);