ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 4 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 08 May 2017 My Price 11.00

GNG1106 – Fundamentals of Engineering

I am in GNG1106 and I have a final project to complete. I completed the lab last week on trapezoidal rule (shown below) and I was wondering how I was supposed to incorporate the equations and variables from the civil engineering project into the trapezoidal rule project. Also, how do I create a new file to replace the "gng1106plplot.h" 

The working lab code for the trapezoidal rule is: 

/*-------------------------------------------------
 File: TrapezoidShapeArea.c
 Description: Calculates the area of a shape
              using Trapazoidal rule for integration.
-------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "gng1106plplot.h"
// Define symbolic constant
#define MAX_SIZE 500  // maximum size of arrays
// Structure definitions
typedef struct
{
    // INPUT from the user
    double aStart;  // Initial value of dimension a for plotting
    double aEnd;    // Final value of dimension a for plotting
    double inc;     // incrementation for value of a
    int num_steps;  //  number of steps to determine h (Trapezoidal Rule)
    // Calculated values
    int n;       // number of points a/fA(a) to compute must
                 // be less than MAX_SIZE
    double a[MAX_SIZE];  // values  of dimension a
    double area[MAX_SIZE];  // area using analytical equation
    double areaTrap[MAX_SIZE]; // area using Trapezoidal Rule
}  SHAPE;

// function prototypes
void getUserInput(SHAPE *);
double getPositiveValue(char *);
void calculateAreaAnalytical(SHAPE *);
void calculateAreaTrapazoid(SHAPE *);
void plot(SHAPE *);
double getMin(double *, int);
double getMax(double *, int);

/*--------------------------------------------
Function: main
Description:  Overall control of the program.
Gets the input from the user, calculates areas
using analytical solution and using Trapazoidal rule,
and plot the 2 curves.
----------------------------------------------*/
void main()
{
    SHAPE shape;  // Input and output data

    // Get the user input
    getUserInput(&shape);
    // Calculations
    calculateAreaAnalytical(&shape);
    calculateAreaTrapazoid(&shape);
    // Plotting
    plot(&shape);
    printf("All done.");
}

/*----------------------------------------------------------
Function: getUserInput
Parameters:
    pPtr - reference to SHAPE structure variable.  Members used
            num_steps - number of steps for determining h
            aStart - starting value for a
            aEnd - end value for a
            inc - incrementation value for dimension a
            n - number of elements used in time/area arrays
Description: Gets from the user values for range of values for
             a, an incremetation value for and the number of steps
             to be used with the Trapezoidal rune (determines h)
             and stores in appropriate variables.
             Ensures that aStart is less than aEnd. Computes n
             and ensures that it is less than MAX_SIZE.
-------------------------------------------------------------*/
void getUserInput(SHAPE *pPtr)
{
    // Get input
    pPtr->num_steps = getPositiveValue("number of steps for defining h");
    do
    {
        pPtr->aStart = getPositiveValue("the start value for a");
        pPtr->aEnd = getPositiveValue("the end value for a");
        pPtr->inc = getPositiveValue("incrementation of a");
        pPtr->n = 1 + (pPtr->aEnd - pPtr->aStart)/pPtr->inc;
        if(pPtr->n > MAX_SIZE)
            printf("Incrementation too small for range of dimension a (%d)n", pPtr->n);
        if(pPtr->n < 0)
            printf("The end value for a must be larger than its start valuen");
    }
    while(pPtr->n > MAX_SIZE || pPtr->n <= 0);
}

/*----------------------------------------------------------
Function: getPositiveValue
Parameters:
    prompt - reference to string to include in the user prompt
Returns
    value: positive value obtained from the user.
Description: Prompt the user for a value (using the prompt string)
    and checks that the value is positive.
-------------------------------------------------------------*/
double getPositiveValue(char *prompt)
{
    double value; // Value entered by the user.
    do
    {
        printf("Please enter a value for %s: ", prompt);
        scanf("%lf",&value);
        if(value <= 0.0)
            printf("The value must be greater than zero.n");
    }
    while(value <= 0.0);
    return(value);
}

/*----------------------------------------------------------
Function: calculateAreaAnalytical
Parameters:
    sPtr - reference to SHAPE structure variable.  Members used
            aStart - starting value for a
            inc - incrementation value for dimension a
            n - number of elements used in time/area arrays
            a - array for saving values of a
            area - array for saving area values
Description: Fills in the arrays with n points of
    a/fA(a) values using the analytical solution for the
    area fA(a).
-------------------------------------------------------------*/
void calculateAreaAnalytical(SHAPE *sPtr)
{
    double aValue;
    int ix;
    aValue = sPtr->aStart;
    for(ix = 0; ix < sPtr->n; ix = ix +1)
    {
        sPtr->a[ix] = aValue;
        sPtr->area[ix] = 4.0*pow(aValue,3)/exp(1);
        aValue = aValue + sPtr->inc;
    }
}

/*----------------------------------------------------------
Function: calculateAreaTrapazoid
Parameters:
    sPtr - reference to SHAPE structure variable.  Members used
            num_steps - number of steps for determining h
            aStart - starting value for a
            inc - incrementation value for dimension a
            n - number of elements used in time/area arrays
            a - array for saving values of a
            areaTrap - array for saving area values
Description: Fills in the arrays with n points of
    a/area values using the Trapezoidal rule for the
    distance.
-------------------------------------------------------------*/
void calculateAreaTrapazoid(SHAPE *sPtr)
{
    double aValue;
    int ix;
    double fx;
    double h;
    double xi;
    double sum;
    int i;

    // Initialise values at time 0
    aValue = sPtr->aStart;


    for (ix = 0; ix < sPtr->n; ix = ix +1)
        {
            sPtr->a[ix] = aValue;
            h = 2*aValue/sPtr->num_steps;
            sum = 0.0;
        xi= -aValue+h;
        for(i = 1; i <= sPtr->num_steps-1; i = i +1)
        {
            fx = (aValue*aValue - xi*xi)*exp(-xi/aValue);
            sum= sum+ fx;
            xi = xi+h;
        }

        sPtr->areaTrap[ix] = h*sum;
        aValue = aValue + sPtr->inc;
        sPtr->a[ix] = aValue;
        }

}
/*----------------------------------------------------------
Function: plot
Parameters:
    sPtr - reference to SHAPE structure variable.  Members used
            aStart - starting value for dimension a
            aEnd - end value for dimension a
            n - number of elements used in time/area arrays
            a - array for saving values of a
            areaTrap - array for saving area values
Description: Initilialises the plot device, pen width,
             and plots both cuvers for the analytical and the
             Euler method.
----------------------------------------------------------------*/
void plot(SHAPE *sPtr)
{
    double maxArea;   // maximum area
    double temp;
    char plotLabel[100];

    // Find the maximum distance to scale the distance axis
    maxArea = getMax(sPtr->area, sPtr->n);
    temp = getMax(sPtr->areaTrap, sPtr->n);
    if(temp > maxArea) maxArea = temp;
    maxArea = 1.1*maxArea;
    // Initiliaise the PLplot page
    plsdev("wingcc");  // Sets device to wingcc - CodeBlocks compiler
    // Initialise the plot
    plinit();
    plwidth(2);    // pen width
    plenv(sPtr->aStart, sPtr->aEnd, 0, maxArea, 0, 0);
    plcol0(GREEN);           // Select color for labels
    sprintf(plotLabel, "Part area (num steps = %d)",
            sPtr->num_steps);
    pllab("Dimension a", "Area fA(a)", plotLabel);
    // Plot the analytical curve
    plcol0(RED);
    pllsty(SOLID);
    plline(sPtr->n, sPtr->a, sPtr->area);
    plptex(0.1*(sPtr->aEnd - sPtr->aStart) + sPtr->aStart, 0.9*maxArea,
           0, 0, 0, "Analytical");
    // Plot the Trapezoidal curve
    plcol0(BLUE);
    pllsty(LNGDASH_LNGGAP);
    plline(sPtr->n, sPtr->a, sPtr->areaTrap);
    plptex(0.3*(sPtr->aEnd - sPtr->aStart) + sPtr->aStart, 0.9*maxArea,
           0, 0, 0, "Trapazoid");
    plend();
}


/*----------------------------------------------------------
Function: getMin
Parameters:
    array - reference to an array with double values
    n - number of elements in the array
Returns
    min:  the minimum value found in the array
Description: Traverses the array to find its minimum value.
----------------------------------------------------------------*/
double getMin(double *array, int n)
{
    int ix;
    double min = array[0];
    for(ix = 1; ix < n; ix = ix +1)
        if(min > array[ix]) min = array[ix];
    return(min);
}

/*----------------------------------------------------------
Function: getMax
Parameters:
    array - reference to an array with double values
    n - number of elements in the array
Returns
    max:  the maximum value found in the array
Description: Traverses the array to find its maximum value.
----------------------------------------------------------------*/
double getMax(double *array, int n)
{
    int ix;
    double max = array[0];
    for(ix = 1; ix < n; ix = ix +1)
        if(max < array[ix]) max = array[ix];
    return(max);
}

 

GNG1106 – Fundamentals of Engineering ComputationCourse ProjectCivil EngineeringWater Pressure Exerted on a DamWater in a river channel exerts pressure on the upstream face of a dam as shown in Figure 1. Thepressure can be characterized by( )()p zg dz(Equation 1)wherep(z) = pressure in pascals (or N/m2) exerted at an elevationzmeters above the channelbottom;g=acceleration due to gravity (9.8 m/s2);ρ= density of water which can be assumed to be a constant 103 kg/m3;d= elevation (in m) of the water above the channel bottomAccording to equation 1, pressure increases linearly with depth, as depicted in Figure 1 (a).(a)(b)Figure 1 – Pressure of Water Exerted on a Dam.(a) Side view showing that pressure increaseswith depth (b) Front view showing how width of canal varies with depth.Omitting atmospheric pressure (because it works against both sides of the dam face andessentially cancels out), the total forceftcan be determined by multiplying pressure with the areaof the canal (as shown in Figure 1 (b)). Because both pressure and area vary with elevation, thetotal force for the depth d is obtained by evaluating00( )( ) ( )( )()dtdf dp z w z dzgw z dz dz(Equation 2)wherew(z)=width of the dam face (m) at elevationz(Figure 1 (b)). The channel bank ismodelled using a 2ndorder polynomial, such that thew(z)varies as follows:222()aw zzbD(Equation 3)whereais the distance from the edge of the channel base to the bank of the channel,bis the width of the channel base;Dis the depth of the channel.dDbaElevation zz = Dz = 0a

GNG1106 Fall 2016 – Project Deliverable 2Available: Nov 20, 2016Due: Nov 27, 2016InstructionsThis project deliverable is to be done in teams of 2. Follow the instructions in the GNGBlackboard document that describeshow to submit assignments through the Blackboard. The following are specific instructions for these deliverables:You will need to submit your deliverable electronically to Blackboard.The project document is provided in both PDF and Word file (Word, Rich Text Format).For deliverable 2, completeSection 3 (added to your sections from the first deliverable). Submit the complete document that is the title page andsections 1 to 3.You must submit a type written document.Hand written documents are not allowed.Submit the PDF document (other versions, including Word files shall not be accepted).Do start the deliverable soon and donotwait until the last minute.You will be more efficient with a number of smallerefforts over a few weeks before the deadline than one large effort just before the deadline.Coordinate and share the work with your partner.Communicate regularly.Meet to discuss the work.Review yourpartner’s work.It is important that you know the complete design, not only the part you completed.Marking SchemeSee the Rubrics marking scheme provided separately.The marking of each deliverable is based on 30 total marks.Each of the two deliverables count for 5 marks of the total project mark (i.e. 5/25).Thus both deliverables whichare used to develop the software design count for 10 marks of the total project mark (i.e. 10/25).The following shows how each deliverable contributes to the final project mark.DeliverableProblem Methodology StepProject Document SectionsMarkDeliverable 1Step 1 (Problem Identificationand Statement)/Step 2(Gathering of Information andInput/Output Description)Sections 1/Sections 25Deliverable 2Step 3 (Test Cases andSoftware Design)Section 3, Revision ofSections 1 to 310Deliverable 3Step 4 (Implementation)/Step5 (Software Testing andVerification)C Source Code, Sections 4/5,Revision of Sections 1 to 310Total Mark25

Attachments:

Answers

(11)
Status NEW Posted 08 May 2017 03:05 AM My Price 11.00

-----------

Not Rated(0)