Function Discovery Matlab Help

Function Discovery
Function discovery is the process of finding, or “discovering,” a function can describe a particular set of data. The following three function types often describe physical phenomena. For example, the linear function dU the voltage-current relation for a resistor (v =iR). The line are relation also describes the velocity versus time relation for an object with constant acceleration

a (v =at + vo). A power function describes the distance d traveled by a falling object versus time (d = 0.5gt2). An exponential function can describe the relative temperature t!.T of a cooling object (t!.T = t!.Toe-C1). The general forms of these functions are:

Capture

where e is the base of the natural logarithm (In e = 1). Note that y(O) = b for both forms. Each function gives a straight line when plotted using a specific set of axes: . 1. The linear function y = mx +b gives a straight line when plotted on rectilinear axes. Its slope is mand its intercept is b. 2. The power function y = bx” gives a straight line when plotted on log-log axes. 3. The exponential function y = b(lo)mx and its equivalent form y. = bemx give a straight line when plotted on a semilog plot whose y-axis is logarithmic. These properties were illustrated in Figure 5.3-8, which shows the power function y = 2x-o.s and the exponential function s= 101-x• We look for a straight line on the plot because it is relatively easy to recognize, and therefore we can easily tell whether the function will fit the data well. Using the following properties of base 10 logarithms, which are shared with natural logarithms, we have

Capture

This has the form

Y = B +m X

if we let Y = 10gIOy, X = 10gIOx, and B = \ogJOb. Thus if we plot Y versus X
on rectilinear scales, we will obtain a straight line whose slope is m and whose intercept is B. This is the same as plotting loglo y versus 10gJOx on rectilinear scales, so we will obtain a straight line whose slope is m and whose intercept is 10gJOb; This is equivalent to plotting y versus x on log-log axes. Thus if the data can be described by the power function, it will form a straight line when plotted on log-log axes. Taking the logarithm of both sides of the exponential equation y = b( IO)?” we obtain

10gIOY == 10glo[b(lO)mx] = 10gJOb +mx loglo 10 = log 10 b +mx
because 10glO 10 = 1. This has the form
Y = B +mx

if we let Y = 10glOY and B = log 10 b. Thus if we plot Y versus x on rectilinear scales, we will obtain a straight line whose slope is m and whose intercept is B. This is the same as plotting loglo y versus x on rectilinear scales, so we will obtain a straight line whose slope is m and whose intercept is 10glOb. This is equivalent to plotting y on a log axis and x on a rectilinear axis (that is, semilog axes). Thus if the data can be described by the exponential function, it will form a straight line when.plotted on semilog axes (with the log axis used for the ordinate). Taking the logarithm of both sides of the equivalent exponential form y = be'”‘ gives

10glOY = 10glO(bemx) = loglo b +mx loglo e

This has the form

Y=B+Mx

if we let Y = log 10 y, B = 10glOb, and M =m log 10 e. Thus if we plot Y versus x on rectilinear scales, we will obtain a straight line whose slope is M and whose intercept is B. This is the same as plotting log 10 y versus x on rectilinear scales, . so we will obtain a straight line whose slope is m 10glOe and whose intercept is’
10gIOb. This is equivalent to plotting y on a log axis and x on a rectilinear axis. Thus both equivalent exponential forms (5.5-3) and (5.5-4) will plot as a straight line on semilog axes

Steps for Function Discovery
. Here is a summary of the procedure to find a function that describes a given set of data. We assume that one of the function types (linear.exponential, or power) can describe the data. Fortunately, many applications generate data that these

functions can describe. We assume that there is enough data and that it is accurate enough to identify the function.
1. Examine the data near.the origin. The exponential function can never pass through the origin (unless of course b = 0, which is a trivial case). (See Figure 5.5-1 for examples with b = I.) The linear function can pass through the origin only if b = O. The power function can pass through the origin but only if m > O. (See Figure 5.5-2 for examples with
b·= I.)
2. Plot the data using rectilinear scales. If it forms a straight line, then it can be represented by the linear function and you are finished. Otherwise, if you have data at x = 0, then •
a. If y(O) = 0, try the power function.
b. If y(O) =I 0, try the exponential function.
If data is not given for x = 0, proceed to step 3.
3. If you suspect a power function, plot the data using log-log scales. Only a power function will form.a straight line on a log-log plot. If you suspect an exponential function, plot the data using the semilog scales. Only an exponential function will form a straight line on a semilog plot.

Examples of exponential functions

Examples of exponential functions

Examples of power functions

Examples of power functions

4. In function discovery applications, we use the log-log and semilog plots only to identify the function type, but not to find the coefficients b and m. The reason is that it is difficult to interpolate on log scales. We can find the-~values of band m.with the MATLAB poly fi t. function. This function finds the coefficients of a polynomial of specified degree n that best Jfits the data, in the so-called least squares sense. You will see what thisrneans in Section 5.6. The syntax appears in Table 5.5-1 Because we are assuming that our data will form a straight line on either a rectilinear, semilog, or log-log plot, we are interested only in a polynomial.that
corresponds to a straight line; that is, a first-degree polynomial, which we will denote as w = P t Z + P 2. Thus, referring to Table 5.5-1, we see that the vector p will be [Pt, P 2] if n is 1. This polynomial has a different interpretation in each of the three cases:
• The linear function: y = InX +b. In this case the variables wand Z in the polynomial w = P t Z +P 2 are the original data variables x and y, and we can find the linear function that fits the data by typing p = poly Ut (x ,y , 1) . The first element PI of the vector p will be m, and the second element P2 will be b.

Capture

Capture

where the polynomial variables w and Z are related to the original data variables x and y by w = 10glO Y and Z = log x. Thus we can find the power function that fits the data by typing p = poly fit (1ogl 0 (x) I log 10 (y) I 1) . The first element PI of the vector p will be m, and the second element P2 will be 10glOb.We can find b from b = 101’2.

Capture

where the polynomial variables w and Z are related to the original data variables x and y by w = log Y and Z =x. Thus we can find the
exponential function that fits the data by typing p = polyfi t (x ,
log10 (y) ,1). The first element PI of the vector p will be m,and the
second element P2 will be log lOb. We can find b from b = 101’2.

Applications
Function discovery is useful in all branches of engineering. Here we give three examples of applications in structural vibration, heat transfer, and fluid – mechanics. Civil, mechanical, and aerospace engineers frequently deal with  structures or machines that bend and vibrate. For such applications they need a model of the vibration. The following example illustrates a common problem-the estimation of the deflection characteristics of a cantilever support beam.

Heat Transfer
Civil, mechanical, and chemical engineers are often required to predict the temperatures that will occur in buildings and various industrial processes. Bio-engineers

and environmental engineers must develop models of temperature distribution and heat loss in living things and the environment. This area of study is called heat transfer. The next example illustrates how we can use function discovery to predict the temperature dynamics of a cooling object

Interpolation and Extrapolation
After we discover a functional relation that describes the data, we can use it to predict conditions that lie within the range of the original data. This process is called interpolation. For example, we can use the coffee cup model to estimate how long it takes for the coffee to cool to 120°F because we have data below and above 120°F. We can be fairly confident of this prediction because our model describes the temperature data very well. . Extrapolation is the process of using the model to predict conditions that lie outside the original data range. Extrapolation might be used in the beam example to predict how much force would be required to bend the beam 1.2 in. (The predicted value is found from the model to be f = 1079(1.2) = 1295 lb.) We must be careful when using-extrapolation because we often have no reason to believe that the mathematical model is valid beyond the range of the original data. For example, if we continue to bend the beam, eventually the force is no longer proportional to the deflection and becomes much greater than that predicted by the linear model f =kx. Extrapolation has a use in making tentative predictions, which must be backed up by testing. The Example 5.5-3 describes an application of extrapolation.
Hydraulic Engineering
Engineers in many fields, including c’vil, mechanical, bio, nuclear, chemical, and aerospace. engineers, often need models to predict the flow rate of fluids

An experiment to verify Torricelli's principle.

An experiment to
verify Torricelli’s principle.

under pressure. Torrice l/i’s principle of hydraulic resistance states that the volume flow rate f of a liquid through a restriction-such as an opening or a valve is proportional to the square root of the pressure drop p across the restriction; that is,

Capture

where c is a constant. In many applications the weight of liquid in a tank causes the pressure drop (see Figure 5.5-6). In such situations Torricelli ‘s principle states that the flow rate is proportional to the square root of the volume V of liquid in the tank. Thus

Capture

 where r is a constant. Torricelli’s principle is widely used to design valves and piping systems for many applications, including water-supply engineering, hydraulically powered machinery, and chemical-processing systems. Here we apply it to a familiar item,
a coffee pot. –

Posted on July 22, 2015 in advanced Plotting and Model Building

Share the Story

Back to Top
Share This