13.07.2015 Views

Analysis of Structures - Baustatik-Info-Server

Analysis of Structures - Baustatik-Info-Server

Analysis of Structures - Baustatik-Info-Server

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.9. FUNCTIONS Page 29t = type(z)if t == str:print zelse:print "Absolute Value <strong>of</strong> %f = %f" % (y,z)# second version to check the type# print error message# print resultEnd <strong>of</strong> CodingThe following example shows, how to pass a function asa functions parameter. Within the Newton’s algorithma root <strong>of</strong> an equation should be calculated. So we haveto specify the function <strong>of</strong> interest. This function can beconsidered as an input parameter. This function nameis passed to the derivative calculator and to the newtonmain routine. Further we see, that it’s recommended touse standard parameter, to configure the algorithm. Weintroduce the precision parameter e, which sets up thethreshold for a zero compare. Further we need the stepwidth to calculate the derivative <strong>of</strong> the function <strong>of</strong> ourinterest.Figure 2.3: Scheme <strong>of</strong> the Newton AlgorithmThe derivative - it’s called fs in the code - is calculated numerical as follows.f ′ (x) = dfdx ≈ (f (x + h 2 ) − f (x − h 2 ) )/h(2.9)The Newton scheme can be described as follows.x i+1 = x i − f (x)f ′ (x)(2.10)There are three possible situations to handle within the iteration loop.• The function value is vanishing with respect to our selected precision. The iteration loop will bebroken and the found result is passed back to the caller.• The slope <strong>of</strong> the function is vanishing. This situation can not be handled by the simple iterationscheme. The iteration will be broken with an error message.• During the iteration each cycle is counted. So the iteration loop will be broken, if the maximumavailable iterations are reached. The actual values and an error message is passed bake to the caller.The code consists <strong>of</strong> the following functions.• Myf, the function <strong>of</strong> our interest.• fs, the function which calculates the slope <strong>of</strong> a given function numerically.2.12.2011

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!