ENGR 1181 | MATLAB 16: Modeling and Simulation Preparation Material Learning Objectives 1. Perform simulations using MATLAB programming skills that have been learned thus far 2. Identify the limitations of computer based solutions Topics ο· ο· Non-linear equations Formulating models through curve fitting 1. Non-Linear Models and Non-Linear Equations There are many phenomena that exhibit complex behaviors that cannot be approximated by linear representations. For those situations, scientists and engineers apply one or more non-linear models to approximate that behavior. Building such models requires an understanding of the causes of system changes and their effects through observation and experimentation. The data gathered from experiments can then be examined and fitted as closely as possible to an appropriate mathematical representation. We will do some of that fitting later on in the course. In this section, we will first examine various kinds of non-linear functions and observe some of their mathematical behavior. Then, we will use those functions to represent real phenomena. Quadratic Functions The basic form of a quadratic function can be written as: π(π)=π∗ππ +π∗π+π Real-World Examples of Quadratic Functions There are many everyday examples of phenomena that can be represented by a quadratic function. One set of examples relates to the physics of thrown objects. Newton's second law of motion and the acceleration due to gravity govern those movements. There are several places where you can see illustrations of these phenomena, one will be shown at the beginning of class. 1 ENGR 1181 MATLAB 16: Modeling and Simulation Preparation Material Exponential Functions The basic form of an exponential function is: π(π) = π ∗ ππ Real-World Examples of Exponential Functions Exponential functions are can be applied to the growth of microorganisms, the spread of a highly contagious disease, the processing power of computers, the compound growth of investments, and human population growth. Mathematically, an exponential function can be expressed as a function with a rate of change over time. The quantity then compounds over time in the form of the exponential function. The table below illustrates this for an example of compound interest on $1000 per month over a number of years. Another way of representing the function is as a difference equation: x ο· ο· t=1 = x te k , where X is the value of the function at times t and t-1 k is the growth constantβ¨e is the base of the natural logarithm More generally, the exponential function is written in this way: x(t) = x0ekt ο· where X0 is the initial base value The exponential function was most famously used to project the human population as a result of unrestrained growth, leading to the prediction that disease, famine, and war were unavoidable consequences of such growth. There have been many subsequent discussions of the real limits on growth associated with natural systems that have resulted in adjustments to exponential models. 2 ENGR 1181 MATLAB 16: Modeling and Simulation Preparation Material Table 1: Compound Interest on $1,000 at 5% per month Month 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Amount $ 1,000.00 $ 1,050.00 $ 1,102.50 $ 1,157.63 $ 1,215.51 $ 1,276.28 $ 1,340.10 $ 1,407.10 $ 1,477.46 $ 1,551.33 $ 1,628.89 $ 1,710.34 $ 1,795.86 $ 1,885.65 $ 1,979.93 $ 2,078.93 $ 2,182.87 $ 2,292.02 $ 2,406.62 $ 2,526.95 $ 2,653.30 $ 2,785.96 $ 2,925.26 $ 3,071.52 $ 3,225.10 $ 3,386.35 $ 3,555.67 $ 3,733.46 $ 3,920.13 Interest $ 50.00 $ 52.50 $ 55.13 $ 57.88 $ 60.78 $ 63.81 $ 67.00 $ 70.36 $ 73.87 $ 77.57 $ 81.44 $ 85.52 $ 89.79 $ 94.28 $ 99.00 $ 103.95 $ 109.14 $ 114.60 $ 120.33 $ 126.35 $ 132.66 $ 139.30 $ 146.26 $ 153.58 $ 161.25 $ 169.32 $ 177.78 $ 186.67 $ 196.01 Total $ 1,050.00 $ 1,102.50 $ 1,157.63 $ 1,215.51 $ 1,276.28 $ 1,340.10 $ 1,407.10 $ 1,477.46 $ 1,551.33 $ 1,628.89 $ 1,710.34 $ 1,795.86 $ 1,885.65 $ 1,979.93 $ 2,078.93 $ 2,182.87 $ 2,292.02 $ 2,406.62 $ 2,526.95 $ 2,653.30 $ 2,785.96 $ 2,925.26 $ 3,071.52 $ 3,225.10 $ 3,386.35 $ 3,555.67 $ 3,733.46 $ 3,920.13 $ 4,116.14 3 ENGR 1181 MATLAB 16: Modeling and Simulation Preparation Material 2. Curve Fitting Curve fitting is often done to provide a mathematical function that explains the overall form of experimental data, allowing the analyst to use the mathematical function within a model. Before you use a curve fitted to data in a model, it is critical that the implied cause and effect relationships between variables be confirmed along with the empirical results of the related experiments or data gathering. Otherwise, there is the potential for deriving a model that does not make logical sense and results in erroneous forecasts. Here is an example from my experience. I was analyzing the relationships between neighborhood characteristics such as income, housing value, and other population characteristics along with the mortgage lending trends for a bank. By accident, I left the variable for zip code in the preliminary correlation analysis that was done with a statistical program. As a result, I received a correlation that showed that there was a strong correlation between zip codes and income – as zip codes went up, so did the income of the population in those neighborhoods. If this correlation were taken seriously, it would imply that all we need to do to solve problems for low-income families is to move them into neighborhoods with higher zip codes. Do you agree that this would work? You may already remember that the correlation coefficient takes on values from -1.0 to 1.0. As it approaches 1.0, it means that increases in one variable can explain nearly all of the increases in another variable – a perfect correlation. A negative correlation implies a near perfect correlation where an increase in one variable explains a decrease in another variable. Linear regression is a statistical technique for measuring the strength of a linear relationship between a dependent variable (Y) and one or more independent variables (X1, X2, X3, ... Xn). The dependent variable is the one being impacted (the effect) and the independent variables are the causes of that effect. The concept of regression is similar to that of correlation except that regression explicitly assumes a cause and effect relationship and correlation does not. The general form of the linear equation for regression is the same as the general linear equation: Y = aX + b ο· ο· ο· , where: Y = the dependent variable, a = a coefficient equivalent to the slope of the line, and b = the Y intercept of the line (the place where it crosses the Y axis). In the case of a multiple regression with three variables: Y=a1X1 +a2X2 +a3X3 +b 4 ENGR 1181 MATLAB 16: Modeling and Simulation Preparation Material The graph below illustrates a simple regression line and how the line approximates a single distribution. Note that not all of the real data points for Y fall on the regression line, much like the illustration for correlation In order to judge the degree of fit between the line and data points, calculations are done based on the vertical distance between the line and each of the observations as shown below. Vertical offsets are used rather than perpendicular offsets. That is so the fitting function focuses on an estimate of Y for a given value of X. Because negative and positive differences would offset one another, the differences are squared and the summed to provide an estimate of the cumulative agreement between the linear function and the distribution of observations. The sum of the squared deviations is called the coefficient of determination or R2 statistic. This statistic measures the amount of variance explained by the model where 0 represents no variance explained and 1.0 represents 100% of the variance explained. 5 ENGR 1181 MATLAB 16: Modeling and Simulation Preparation Material The model also returns values for the significance of the individual coefficients from a statistical point of view. We want the relevant statistic to take on a value that assures us that the results could not have happened by chance more than 5% of the time or that we are 95% confident of the result. Similar statistics can be derived for non-linear curves fitted to data although the computational methods to derive these statistics are not as straightforward. We will not review the mathematics of those approximations here. What is more important to us is the general principle that we can calculate a measure of the quality of fit between any regular function and a set of observations that are scattered around that function. Even if the fit is very good, that alone does not prove that we have chosen the correct function. This can only be done across many experiments that reconfirm the form of the function. For empirical models such as this, we may explain a relationship without fully understand the physical processes or limits that govern the system. At some point, we may exceed the physical capacity of the system and the relationship will collapse. 6