Uploaded by Syed Mujtaba Ali

ITC CEP

advertisement
DEPARTMENT OF CIVIL
ENGINERRING
COMPLEX ENGINEERING PROBLEM
INTRODUCTION TO COMPUTING FOR CIVIL ENGINEERS
COURSE CODE: CE-111
GROUP MEMBERS:
1.
2.
3.
4.
HAIDER ALI KHAN
(CN-21029)
SYED MUJTABA ALI
(CN-21009)
HASAN ALI GHAURI
(CN-21028)
MUHAMMAD AAMASH (CN-21010)
OBJECTIVE:
i)
DRAW A FLOW CHART THAT IMPLEMENTS THE NEWTON RAPHSON
METHOD TO DETERMINE THE WAVELENGTH,L
ii)
WRITE PYTHON CODE THAT IMPLEMENTS THE NEWTON RAPHSON
METHOD TO DETERMINE THE WAVELENGTH,L FOR CONSTANT
DEPTH,h AND TIMEPERIOD T.
iii)
PLOT GRAPH BY USING matplotlib FOR GIVEN DEPTH(10<=h<=300)
EQUATION USED FOR NEWTON RAPHSON/BISECTION
METHOD:
L=(gT^2/2π)tanh(2πh/L)
WHERE,
g=Acceleration due to Gravity
T=Time period
h=Depth
L=Wavelength
PRINT() FUNCTION :
The print() function prints the specified message to the screen, or other
standard output device. The message can be a string, or any other object, the
object will be converted into a string before written to the screen.
IMPORT MATH FUNCTION:
Python has also a built-in module called math , which extends the list of
mathematical functions. To use it, you must import the math module: import math.
When you have imported the math module, you can start using methods and
constants of the module.
Def() FUNCTION:
def is the keyword for defining a function. The function name is followed by
parameter(s) in (). The colon : signals the start of the function body, which is marked
by indentation. Inside the function body, the return statement determines the value to
be returned.
WHILE LOOP FUNCTION:
The while loop in Python is used to iterate over a block of code as long as the
test expression (condition) is true. We generally use this loop when we don't know
the number of times to iterate beforehand.
INPUT() FUNCTION:
we use input() function to take input from the user. Whatever you enter as input,
the input function converts it into a string. If you enter an integer value still input()
function convert it into a string.
FOR LOOP FUNCTION:
A "For" Loop is used to repeat a specific block of code a known number of
times. For example, if we want to check the grade of every student in the class, we
loop from 1 to that number. When the number of times is not known before hand, we
use a "While" loop.
FLOAT FUNCTION:
The float() function converts the specified value into a floating point number.
LIBRARY :
A (software) library is a collection of files (called modules) that
contains functions for use by other programs. May also contain data values
(e.g., numerical constants) and other things.
cmath FUNCTION:
Python has a built-in module that you can use for mathematical tasks for
complex numbers. The methods in this module accepts int , float , and complex
numbers. It even accepts Python objects that has a __complex__() or __float__()
method.
Sympy FUNCTION:
sympy. Function is for undefined functions. Like if f = Function('f') then f(x)
remains unevaluated in expressions. If you want an actual function (like if you do f(1)
it evaluates x**2 + 1 at x=1 , you can use a Python function def f(x): return x**2 + 1.
MATPLOT LIBARARY FUNCTION:
Matplotlib is a library in Python and it is numerical – mathematical extension for
NumPy library. Pyplot is a state-based interface to a Matplotlib module which
provides a MATLAB-like interface. There are various plots which can be used in
Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, etc.
FLOW CHART FOR CALCULATING WAVELENGTH:
PSEUDOCODE
ALGORITHM
DEFINE f(L) and df(L)
INPUT CONSTANT VALUE i-e
g,h,T
AND
ENTER INITIAL GUESS AS IGUESS
def f(L) and df(L)
CALCULATE d=h/IGUESS
IF 0.05<=d<=0.5
YES THEN PUT LOOP
FOR ITER
AND CALCULATE WAVELENGTH
BY
NEWTON RAPHSON
PRINT WAVELENGTH
AT ITERATION,ITER
NO THEN PRINT
ENTER DEPTH AND
IGUESS AGAIN
START
Input g,h,T and IGUESS
d=h/IGUESS
If 0.05<=d<=0.5
DEFINE f(L) AND df(L)
YES THEN LOOP FOR ITER
LGUESS=IGUESS-f(IGUESS)/df(IGUESS)
print LGUESS AT ITER
NO THEN PRINT
ENTER DEPTH AND
IGUESS AGAIN
INPUT CONSTANT VALUE i-e g,h,T
AND
ENTER INITIAL GUESS AS IGUESS
CALCULATE d=h/IGUESS
IF 0.05<=d<=0.5
YES
NO
PRINT AGAIN ENTER DEPTH AND
INITIAL GUESS
LOOP FOR ITER=1 TO MAX ITER
CALCULATE LGUESS=IGUESS -f(IGUESS)/df(IGUESS)
PRINT WAVELENGTH IS ,LGUESS AT
ITERATION ,ITER
END
PYTHON CODING OF NEWTON RAPHSON METHOD:
RESULTS OF PYTHON CODING:
GRAPH:
PYTHON CODING OF BISECTION METHOD:
RESULTS OF BISECTION METHOD:
THANKS
Download