This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 14:440:127 Introduction to Computers for Engineers Notes for Lecture 11 Rutgers University, Fall 2008 Instructor Blase E. Ur Were going to begin with a corrected version of a section from Lecture 10 with 2 stupid and serious mistakes I had left in there, but noticed and corrected as I was giving the lecture: 1 Correction from last lecture: Fitting To More Compli cated Functions Oftentimes in engineering, youll want to find equations for functions that are not polynomial. However, youll sometimes be able to transform these functions into polynomials: 1.0.1 Power Functions A function such as y = bx m can be called a power function since x is raised to a power. Note that this is a polynomial, but you have no idea what degree it is, so it might be hard to choose which degree polynomial to specify for polyfit . Note that if you plot this function on a loglog plot using the loglog command, the data will appear in a straight line. Now, the key is that if you take the logarithm of both sides of this equation, youll get log ( y ) = log ( bx m ). Using log properties, you can rewrite this as log ( y ) = log ( b )+ log ( x m ), and then rewrite it as log ( y ) = m * log ( x ) + log ( b ). This has the form j = m * h + k if you define j = log ( y ), h = log ( x ), and k = log ( b ). This is perfectly analogous to y = mx + b , which is a linear equation. Now, find the coefficients using polyfit(log(x),log(y),1) , and call these coeffients [m k]. Now, go ing back to the original equation, you can realize that youve already found m . To find b , you can recall that k = log ( b ), so b = e k . You can now write an equation for your data as y = exp ( coeffs (2)) * x coeffs (1) . Thus, youve used a transformation, fit the log of the power function to a line, and then reversed your transformation to find the original coefficients. 1.0.2 Exponential Functions Lets say youre given an exponential function, such as y = b ( e ) mx . This function would be displayed as a straight line on a semilogy plot. This can be rewritten as log ( y ) = mx + log ( b ). Now, this has the form j = m * x + k if you set j = log ( y ) and k = log ( b ). Note that you do not have to transform x. Now, find the coefficients using polyfit(x,log(y),1) , and call these coeffients [m k]. Again, youve already found m from the original equation, and you can find b by recalling that i = log ( b ), so b = e k . You can now write an equation for your data as y = exp ( coeffs (2)) * ( e ) coeffs (1) * x . 2 Recursion Theres a very interesting technique in computer programming called recursion, in which you write a function that calls itself . Eventually, this string of functions calling itself stops at some base case , and the answers work their way back up. Of course, in order to understand recursion, you must understand recursion. (Thats a joke)....
View
Full
Document
This note was uploaded on 11/09/2011 for the course ENGINEERIN 127 taught by Professor Finch during the Fall '08 term at Rutgers.
 Fall '08
 Finch

Click to edit the document details