User Tools

Site Tools


gibson:teaching:fall-2014:math445:lecture6-diary

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
gibson:teaching:fall-2014:math445:lecture6-diary [2014/09/18 11:26]
gibson created
gibson:teaching:fall-2014:math445:lecture6-diary [2014/09/18 12:21] (current)
gibson [Graphical data analysis of log-linear relations]
Line 1: Line 1:
-====== Math 445 lecture 6: logical array operations and log-linear relations ​======+====== Math 445 lecture 6 ======
  
-<​code>​+===== Finding twin primes using logical array operations ===== 
 + 
 +<​code ​matlab>
 % In honor of Yitang (Tom) Zhang'​s proof of the boundedness of gaps  % In honor of Yitang (Tom) Zhang'​s proof of the boundedness of gaps 
 % between primes, and of his MacArthur Fellowship announced yesterday, % between primes, and of his MacArthur Fellowship announced yesterday,
Line 133: Line 135:
 % Thus ends our homage to Yitang '​Tom'​ Zhang. I encourage you to  % Thus ends our homage to Yitang '​Tom'​ Zhang. I encourage you to 
 % view Tom's video on the MacArthur Foundation website. ​ % view Tom's video on the MacArthur Foundation website. ​
 +</​code>​
  
 +===== Summation of series examples =====
  
 +<code matlab>
 % ======================================================================= % =======================================================================
 % Now a couple examples of summing series, as compactly as possible % Now a couple examples of summing series, as compactly as possible
Line 182: Line 187:
 ans = ans =
      2      2
 +</​code>​
  
 +===== Graphical data analysis of log-linear relations =====
  
-======================================================================= +==== example 1: a linear relationship ​====
-% Ok. Let's move on the graphical data analysis+
  
 +<code matlab>
 % Load datafile '​data1.asc'​ into matlab with '​load'​ command % Load datafile '​data1.asc'​ into matlab with '​load'​ command
 >> D = load('​data1.asc'​); ​ >> D = load('​data1.asc'​); ​
Line 222: Line 229:
 >> ylabel('​y'​) >> ylabel('​y'​)
 >> grid on >> grid on
 +</​code>​
  
 +{{ :​gibson:​teaching:​fall-2014:​math445:​linearplot0.png?​direct&​400 |}} 
 +
 +<code matlab>
 % It's a straight line on a linear plot, so the functional relation is y = mx + b.  % It's a straight line on a linear plot, so the functional relation is y = mx + b. 
 % Hmmm, the slope is negative, dropping about 1 in y for every 2 in x. So I'​ll ​ % Hmmm, the slope is negative, dropping about 1 in y for every 2 in x. So I'​ll ​
Line 233: Line 244:
 >> plot(xdata, ydata, '​mo-',​ x, y, '​b.-'​) >> plot(xdata, ydata, '​mo-',​ x, y, '​b.-'​)
 >> xlabel('​x'​);​ ylabel('​y'​) >> xlabel('​x'​);​ ylabel('​y'​)
 +</​code>​
  
 +{{ :​gibson:​teaching:​fall-2014:​math445:​linearplot1.png?​direct&​400 |}} 
 +
 +<code matlab>
 % Wow, that's a great guess! But the slope is a little too negative, and the % Wow, that's a great guess! But the slope is a little too negative, and the
-% y-intercept a little low. Try y = -0.x + 18. And this time let's just put +% y-intercept a little low. Try y = -0.49 x + 18.5. And this time let's just put 
-% the expression for y into the plot command, so that we can regenerate the  +% the expression for y into the plot command, with the labeling commands following 
-plot with different constants ​in a single command. ​+% on the same line, so that we can regenerate the plot with different constants ​ 
 +% quickly by making small changes to a single command ​line. 
 + 
 +>> plot(xdata, ydata, '​mo-',​ x, -0.49 * x + 18.5, '​b-'​);​ xlabel('​x'​);​ ylabel('​y'​);​ grid on; 
 +</​code>​ 
 + 
 +{{ :​gibson:​teaching:​fall-2014:​math445:​linearplot2.png?​direct&​400 |}}  
 + 
 +<code matlab>​ 
 +% Even better! The slope looks just right but our guess is still a little low. 
 +% Raise the y intercept up to 19. 
 + 
 +>> plot(xdata, ydata, '​mo-',​ x, -0.49 * x + 19, '​b-'​);​ xlabel('​x'​);​ ylabel('​y'​);​ grid on; 
 +</​code>​ 
 + 
 +{{ :​gibson:​teaching:​fall-2014:​math445:​linearplot3.png?​direct&​400 |}}  
 + 
 +<code matlab>​ 
 +% Perfect! So the functional relation between y and x is y = -0.49 x + 19 
 +</​code>​ 
 + 
 +==== example 2: a log-linear relationship ==== 
 + 
 +<code matlab>​ 
 +% Load the next data file and try to figure out its y = f(x) relation.  
 +>> D = load('​data3.asc'​);​ 
 +>> xdata = D(:,1); 
 +>> ydata = D(:,2); 
 +>> plot(xdata, ydata,'​mo-'​);​ xlabel('​x'​);​ ylabel('​y'​);​ grid on 
 +</​code>​
  
->> plot(xdata, ydata, 'mo-', xg, -0.49 * xg + 18.5, '​b-'​)+{{ :​gibson:​teaching:​fall-2014:​math445:​logplot0.png?​nolink&​400 |}}
  
 +<code matlab>
 +% That looks exponential,​ so graph y logarithmically
 +>> semilogy(xdata,​ ydata, '​mo-'​);​ xlabel('​x'​);​ ylabel('​y'​);​ grid on
 +</​code>​
  
->> plot(xdata, ydata, 'mo-', xg, -0.49 * xg + 19, '​b-'​)+{{ :​gibson:​teaching:​fall-2014:​math445:​logplot1.png?​nolink&​400 |}}
  
 +<code matlab>
 +% Great! It's a straight line with y graphed logatithmically,​ so the relation is
 +% of the form 
 +%   log10 y = m x + b,   or equivalently
 +%         y = 10^(mx+b), or equivalently
 +%         y = c 10^(mx)
 +% for some constants m and c. let's take rough guesses, judging from the plot.
 +%
 +% m is the slope in log10 y versus x. log10 y drops from 2 at x=10 to about 1 at x=20.
 +% So m looks to be about -1/10, (rise of -1 over run of 10). You can get the constant c
 +% by estimating the value of y at x=0. That looks to be about c=400. So let's give
 +% y = 400 10^(-0.1 x) a try.
  
-plot(x,y, 'mo-'xg-0.49 * xg + 18.5, '​b.-'​+>> x = linspace(-205010); 
-plot(x,y, '​mo-', ​xg-0.49 xg + 18.7, '​b.-'​) +>> semilogy(xdataydata,'​mo-', ​x400*10.^(-0.1*x)); xlabel('x'); ylabel('y'); grid on 
-plot(x,y, '​mo-',​ xg, -0.49 xg + 18.9, 'b.-') +</​code>​
-plot(x,y, '​mo-',​ xg,-0.49 * xg + 19, 'b.-')+
  
 +{{ :​gibson:​teaching:​fall-2014:​math445:​logplot2.png?​nolink&​400 |}}
  
 +<code matlab>
 +% Not too shabby. But the slope is a little too negative and y is too low at x=0. 
 +% A few iterations of adjusting the constants gives
  
-% great! relation is y = -0.49 + 19+>> semilogy(xdata,​ ydata,'​mo-',​ x, 700*10.^(-0.085*x)); xlabel('​x'​);​ ylabel('​y'​);​ grid on 
 +</​code>​
  
 +{{ :​gibson:​teaching:​fall-2014:​math445:​logplot3.png?​nolink&​400 |}}
  
-try another +<code matlab>​ 
-D = load('​data3.asc'​);​ +so the functional form is y = 700 * 10^(-0.085 x)
-x= D(:,1); +
-y=D(:,2); +
-plot(x,​y,'​mo-') +
-% looks exponential,​ so graph y logarithmically +
-semilogy(x,​y,'​mo-'​)+
  
 +% Don't ask me why Matlab keeps changing the grid lines on the logarithmic plots... ​
 +</​code>​
gibson/teaching/fall-2014/math445/lecture6-diary.1411064819.txt.gz · Last modified: 2014/09/18 11:26 by gibson