Docsity

Math Modeling: Syntax for Data Transformation and Developing Models - Prof. Afshin Ghoreis, Lab Reports of Mathematics

Toggle sidebar
bg1
Mathematics Computer Laboratory - Math 1200
Lab 5 - Mathematical Modeling
Due
You should only turn in exercises in this lab with its title and your name as the
Title
and
Subtitle
. Edit
your document and use appropriate margins to get a polished and neat document.
1. The objective of this lab is to discuss syntax for data transformation, data tting, and development
of appropriate exponential and power models.
Data collection is an integral part of most scientic studies. Data analysis can lead to discovery of well-
dened relationships between dierent variables. Then a mathematical model can be developed based on
such relationships. Model interpretation and forecasting, in real-world terms, usually leads to a deeper
understanding and more precise future studies. This cycle will continue until a suciently accurate math-
ematical model is developed. This method has led humans to discovery of almost all basic scientic laws
that we know to day.
2. Starting with a set of data points, let's use Mathematica to nd its \best" t among dierent classes
of functions.
(a)
xdata={0.5, 1, 1.4, 2, 2.5, 3, 3.6, 4, 4.8}
These are the
x
or domain values.
Note: It is convenient to use a descriptive list name.
(b)
ydata={0.2, 1, 3.5, 8, 15.5, 28, 43.1, 64, 112.5}
These are the corresponding
y
or range
values.
Note: You might get a warning message about the similarity of names used for the two lists.
(c)
xydata=Transpose[{xdata, ydata}]
Now we have matched the corresponding data values.
(d)
dataplot=ListPlot[xydata]
This gives the graph of the data points.
(e) The command
Fit
will yield the function which \best" ts the data among all functions of agiven
type.
f1=Fit[xydata, {1,x}, x]
You should get
,
29
:
612
+
23
:
7854 x
.
The list
f
1,x
g
species that the function type is linear:
f
(
x
) =
c
1
1 +
c
2
x
.The last
x
indicates
that
x
is the independent variable.
(f)
f1graph=Plot[f1, {x, 0, 5}]
This gives the graph of the t function on the domain [0
;
5] .
(g) To see how well this function ts the data, view the graph of both on the same coordinate system.
The
Show
command displays graphs on the same coordinate system.
Show[dataplot, f1graph]
The \best" linear function does not seem to t the data well!
pf3
pf4
pf5

Partial preview of the text

Download Math Modeling: Syntax for Data Transformation and Developing Models - Prof. Afshin Ghoreis and more Lab Reports Mathematics in PDF only on Docsity!

Mathematics Computer Lab oratory - Math 1200 Lab 5 - Mathematical Mo deling

Due

You should only turn in exercises in this lab with its title and your name as the Title and Subtitle. Edit your do cument and use appropriate margins to get a p olished and neat do cument.

  1. The ob jective of this lab is to discuss syntax for data transformation, data tting, and development of appropriate exp onential and p ower mo dels.

Data collection is an integral part of most scienti c studies. Data analysis can lead to discovery of well- de ned relationships b etween di erent variables. Then a mathematical mo del can b e develop ed based on such relationships. Mo del interpretation and forecasting, in real-world terms, usually leads to a deep er understanding and more precise future studies. This cycle will continue until a suciently accurate math- ematical mo del is develop ed. This metho d has led humans to discovery of almost all basic scienti c laws that we know to day.

  1. Starting with a set of data p oints, let's use Mathematica to nd its \b est" t among di erent classes of functions.

(a) xdata={0.5, 1, 1.4, 2, 2.5, 3, 3.6, 4, 4.8} These are the x or domain values. Note: It is convenient to use a descriptive list name.

(b) ydata={0.2, 1, 3.5, 8, 15.5, 28, 43.1, 64, 112.5} These are the corresp onding y or range values. Note: You might get a warning message ab out the similarity of names used for the two lists.

(c) xydata=Transpose[{xdata, ydata}] Now we have matched the corresp onding data values.

(d) dataplot=ListPlot[xydata] This gives the graph of the data p oints.

(e) The command Fit will yield the function which \b est" ts the data among all functions of a given typ e.

f1=Fit[xydata, {1,x}, x] You should get 29 : 612 + 23 : 7854 x.

The list f1,xg sp eci es that the function typ e is linear: f (x) = c 1  1 + c 2  x. The last x indicates that x is the indep endent variable.

(f ) f1graph=Plot[f1, {x, 0, 5}] This gives the graph of the t function on the domain [0; 5].

(g) To see how well this function ts the data, view the graph of b oth on the same co ordinate system. The Show command displays graphs on the same co ordinate system.

Show[dataplot, f1graph]

The \b est" linear function do es not seem to t the data well!

  1. Continued. (h) Let's nd the \b est" t quadratic function.

f2=Fit[xydata, {1, x, x^2}, x] You should get 11 : 235 19 : 3367 x + 8 : 26701 x^2.

This is the function which \b est" ts the data among all functions of the form f (x) = c 1  1 + c 2  x + c 3  x^2. (i) f2graph=Plot[f2, {x, 0, 5}]

(j) Show[dataplot, f1graph, f2graph] The graph of data p oints and b oth t functions are displayed on the same co ordinate system. It is clear that the quadratic function is a b etter t.

The general form of the Fit command is

Fit[List of data points, List of functions, List of independent variables]

This command gives the b est \least square t" of the desired function form. (k) Let's try a function of the form f (x) = c 1  1 + c 2  x + c 3  ex

f3=Fit[xydata, {1, x, E^x}, x] You should get 7 : 42772 + 0 : 744476 Ex^ + 6 : 51318 x.

(l) f3graph=Plot[f3, {x, 0, 5}]

(m) Show[dataplot, f2graph, f3graph] From this comparison, one may conclude that the function f3 is as go o d a t as f2.

Although it might b e p ossible to list an arbitrary collection of functions and get an accurate t, such a mo deling metho d has two ma jor draw backs.

(a) The mathematical mo del may not reveal the true nature of the relationship b etween di erent variables and therefore provide no new insights.

(b) The mathematical mo del may give an inaccurate forecast.

The data in the last part was generated using a cubic relationship b etween x and y variables including small variations to account for data collection inaccuracies. None of the t functions showed this b ehavior and all would b e very p o or predictor of value of y outside the x interval [0: 1 ; 4 :8]. Therefore, it is imp ortant to cho ose functions which represent the relationship b etween variables and also nd the smallest numb er of functions for which there is an accurate t.

We will now develop an indicator for recognizing exp onential, y = a ek^ x^ , and p ower, y = a xb^ , relationships in data; in either case, taking the logarithm of b oth sides reveals a linear relationship in transformed data.

y = a ek^ x^ () ln y = ln(a ek^ x^ ) () ln y = ln a + ln ek^ x^ = ln a + k x () Y = k x + A where Y = ln y and A = ln a

y = a xb^ () ln y = ln(a xb^ ) () ln y = ln a + ln xb^ = ln a + b ln x () Y = bX + A where Y = ln y , X = ln x and A = ln a

  1. Continued.

(k) Clear[xdata, ydata, xydata, dataplot, f1, f1graph, f2, f2graph, f3, f3graph]; Clear[lnydata, xlnydata, logplot, lnxdata, lnxlnydata, loglogplot, y, modelplot]

  1. We will now discuss another mo deling example.

(a) xdata={1.1, 2, 3.1, 4.1, 4.9, 6}

(b) ydata={0.34, 0.46, 0.61, 0.83, 1.12, 1.51}

(c) xydata=Transpose[{xdata, ydata}]

(d) dataplot=ListPlot[xydata]

(e) lnydata=Log[ydata]

(f ) xlnydata=Transpose[{xdata, lnydata}]

(g) logplot=ListPlot[xlnydata, PlotJoined->True] The transformed data (x; ln y ) seem pretty straight.

(h) lnxdata=N[Log[xdata]]

(i) lnxlnydata=Transpose[{lnxdata, lnydata}]

(j) loglogplot=ListPlot[lnxlnydata, PlotJoined->True] The transformed data (ln x; ln y ) do es not seem as straight.

(k) Show[logplot, loglogplot] The logplot lo oks more straight.

(l) Fit[xlnydata, {1,u}, u] You should get 1 : 4111 + 0 : 30453 u.

Therefore ln y = 1 : 4111 + 0 : 30453 x. Exp onentiating b oth sides yields:

ln y = 1 : 4111 + 0 : 30453 x eln^ y^ = e^1 :4111+0:^30453 x y = e^1 :^4111 e^0 :^30453 x

Using Mathematica:

E^(-1.4111) E^(0.30453 x) Thus, approximately, y = 0 : 24 e^0 :^3 x^.

y=0.24 E^(0.3 x)

(m) modelplot=Plot[y, {x, 0.5,6.5}]

(n) Show[dataplot, modelplot] This graph indicates that y = 0 : 24 e^0 :^3 x^ is a very go o d t.

(o) Clear[xdata, ydata, xydata, dataplot, lnydata, xlnydata, logplot] Clear[lnxdata, lnxlnydata, loglogplot, y, modelplot]

In each of the following exercises, determine whether the exp onential mo del or the p ower mo del b etter ts the data using the straightness indicator. Then develop the chosen mo del. Follow the steps in parts 3 and

  1. Add appropriate comments (typ e your comments in text cells) to explain your work.

A. Let d b e the average distance, in millions of miles, of planets in our solar system from the Sun and let T years b e the corresp onding p erio d (time for one complete revolution around the Sun) of each planet.

Planet d T Mercury 35.96 0. Venus 67.20 0. Earth 92.90 1. Mars 141.6 1. Jupiter 483.3 11. Saturn 886.2 29. Uranus 1783 84 Neptune 2793 164.

B. Let L represent the length of a simple p endulum in centimeters and let p erio d T b e the corresp onding time, in seconds, in which the p endulum completes one swing back and forth.

Note: Assuming a p endulum is not allowed to swing to o far from the vertical, its p erio d T is indep endent of the angle it swings through.

L 5 10 15 20 25 30 35 T 0 : 45 0 : 63 0 : 78 0 : 89 1 : 00 1 : 10 1 : 19

C. Let P represent the U.S. p opulation size, in millions, at census years 1790 to 1890.

Year 1790 1800 1810 1820 1830 1840 1850 1860 1870 1880 1890 P 3 : 929 5 : 308 7 : 240 9 : 638 12 : 866 17 : 069 23 : 192 31 : 443 38 : 558 50 : 156 62 : 948

Note: You may want to start with setting year 1780 as time zero. Then the dates will transform to times 10 to 110. In Mathematica you can do this by time=year 1780 where year is the list of the years: year=f1790, 1800 , ... g.