HW5
From CDS 130
Homework #5
Contents 
1. Numerical Integration
1.1. Tile Size
Suppose that you want to estimate the area of room by laying down tiles.
 What is an advantage of using small tiles to estimate the area?
 What is an advantage of using big tiles to estimate the area?
Answer 


1.2. Rectangle motivation
When we are estimating area using a computer, we add up the area of rectangles instead of the area of a bunch of tiles (squares) or triangles. Why?
Answer 


1.3. Algorithm for splitting rectangles
The image below shows how a student doubled the number of rectangles used to estimate the area in the blue box. They just drew a line through the middle of each rectangle.
 Why is this approach not useful?
 Suggest a better algorithm for doubling the number of rectangles.
1.4. Numerical Integration

1.5. Numerical Integration

1.6. Numerical Integration
In this problem, we are given an equation that represents the height so we can compute the area by hand calculations and by iteration.
Compute the area between the lines y=0, x=3, and y=x^{2} using rectangles of width 1. Use this graph paper and let 1 unit be the width of a square.
Answer 

In the image below, three dots were drawn at xvalues of 1, 2, and 3. The yamplitude was computed using the formula y=x^{2} to give yvalues for the dots of 1^{2}=1, 2^{2}=4, and 3^{2}=9. The width of each rectangle is 1, so the total area is the sum of the areas of the three rectangles, or 1*1 + 1*4 + 1*9 = 14. 
Repeat the above using rectangles of width 1/2 of a square.
Answer 

In the image below, three dots were drawn at xvalues of 0.5, 1, 1.5, 2, 2.5, and 3. The yamplitude was computed using the formula y=x^{2} to give yvalues for the dots of 0.5^{2}=0.25, 1^{2}=1, ..., 2.5^{2}=6.25, and 3^{2}=9. The width of each rectangle is 0.5, so the total area is the sum of the areas of the six rectangles, or 0.5*0.25 + 0.5*1 + 0.5*2.25 + 0.5*4+ 0.5*6.25 + 0.5*9 = 11.375. 
Write down your rule for selecting the heights of the rectangles in 1. and 2. What would an advantage be of having a simple rule or a rule that is the same for all rectangles as opposed to a rule that depends on x?
Answer 

For the first problem, the rule was to draw a horizontal line from x=0 to x=1 on the xaxis. Then draw a vertical line up to x=1^{2} and draw a dot. The two lines represent two sides of the first rectangle. Next draw a line from x=1 to x=2 on the xaxis. Then draw a vertical line up to x=2^{2} and draw a dot. The two lines represent two sides of the second rectangle. Etc. For second problem, the rule was to draw a horizontal line from x=0 to x=0.5 on the xaxis. Then draw a vertical line up to x=0.5^{2} and draw a dot. The two lines represent two sides of the first rectangle. Next draw a line from x=0.5 to x=1.0 on the xaxis. Then draw a vertical line up to x=1^{2} and draw a dot. The two lines represent two sides of the second rectangle. Etc. 
Write a program without a for
to compute the area using w=1.
Answer 

To figure out how to write a program to do the computation with a for loop, write out the steps in longhand form. clear; w = 1; A(1) = w*1*1; A(2) = w*2*2; A(3) = w*3*3; Atotal = A(1)+A(2)+A(3) now, rewrite the above using an iteration variable. clear; w = 1 i = 1; A(i) = w*i*i; i = 2; A(i) = w*i*i; i = 3; A(i) = w*i*i; Atotal = A(1)+A(2)+A(3) 
Rewrite the program with a for
loop.
Answer 

Both programs above correctly compute the area. The last program can be rewritten as clear; w = 1; for i = [1:3] A(i) = w*i*i; end Atotal = sum(A) Note that the last line was rewritten using the z = sum([1,2,4]) will assign the value 
Answer the last two questions using w = 0.5.
Answer 

Here is a program that almost does what we want. The problem is that the array clear; w = 0.5 i = 0.5; A(i) = w*i*i; i = 1.0; A(i) = w*i*i; i = 1.5; A(i) = w*i*i; i = 2.0; A(i) = w*i*i; i = 2.5; A(i) = w*i*i; i = 3.0; A(i) = w*i*i; Atotal = sum(A) the above (nonvalid) program can be rewritten as clear; w = 0.5 for i = [0.5:0.5:3.0] A(i) = w*i*i end Atotal = sum(A) To make this program work, we need the array clear; w = 0.5 k = 1; for i = [0.5:0.5:3.0] A(k) = w*i*i; k = k+1; end Atotal = sum(A) If you rewrite the above in longhand notation, you will see that it does the correct calculation. 
1.7. Numerical Integration
The following program is used to estimate the area under the curve y = x^{2}/4 between x = 0 and x = 5:
A = 0; for i = [1:5] A = A+ (i)^2/4; end
Sketch the curve and the rectangles that correspond to the program above. Label the height of each rectangle.
2. Computational Simulations
2.1. Logistic Map in Octave
 Write an Octave program that reproduces the four figures shown on the Google Spreadsheet shown in class on this spreadsheet [1]. You may want to refer back to Introduction_To_Octave for information on creating plots.
 Describe in 310 sentences what happens as r is increased above 3.5. The idea is to give a "science description" of the observation. That is, explain what you observe in the same way that you would when trying explain a painting to someone over the phone  the person on the other end should have a fairly good idea of what the main features of the painting are.
Extra Credit
 Create an animation that shows what happens as r is increased above 3.5. See Introduction_To_Octave#Create_an_Animation.
3. Validation
3.1. Neuron Model
In the above, we gave a procedure for validating a model. In reality, these steps are rarely explicitly presented, and sometimes steps are left out.
In the paper "Simple Model of Spiking Neurons" by Izhikevich (pdf), simulation results from a model are presented and the author argues that the model reproduces the spiking and bursting observed in cortical neurons. You are not expected to understand many of the science or computational details given in this work. However, you should be able to answer the following basic questions that should be specified in any description of the results from a computational simulation:
 What was the mathematical model?
 Was the computational model given?
 What are the model's adjustable parameters?
 Write out any sentences in the paper that you feel are related to validation.
3.2. Dog Shaking Frequency Model
Read this "Physicists Discover Universal "WetDog Shake" Rule  How fast should a wet dog rotate its body to dry its fur?" [2]
 What was the science/conceptual model for how fast a dog shakes?
 What was the mathematical model for how fast a dog shakes?
 How was the mathematical model validated?
 How could a computational model be used to figure out the reason the mathematical model did not match the data?
3.3. Validation in the Wild
In one of your science courses, you have worked with a science model. In the description of the model, was there any discussion of how it was validated? If you can't find a discussion there, do some searching on the web.
Write two or three sentences that describe the model and how the model was validated. If you could not find any discussion of validation, describe the research that you did in an attempt to find a model with a discussion of validation.
3.4. Reading
 Read the two papers (pdf  pdf) (only read the first two pages of each and the conclusions of the neuron paper, you can skim the rest)
 You are not expected to understand many of the science or computational details given in this work. However, you should be able to answer the following basic questions that should be specified in any description of the results from a computational simulation and be prepared to discuss:
 What is the conceptual/science model?
 What is the mathematical model?
 What is the computational model?
 How many adjustable parameters does each model have?
 How was the model verified?
 How was the model validated?
 Suggest your own verification test
 Suggest your own validation test