Hello Earth! › files › NAGT... · Homework 3 — Data analysisFRS 135, LAB 04 ilillianw, 1 of 1...
Transcript of Hello Earth! › files › NAGT... · Homework 3 — Data analysisFRS 135, LAB 04 ilillianw, 1 of 1...
Hello Earth!
A grounded introduction to Matlab
Frederik J SimonsChristopher Harig
Adam C. Maloof
Princeton University
(Enter teacher) i
Something canny Matlab can do i
100 200 300 400 500 600 700 800 900 1000
200
400
600
800
1000
100 200 300 400 500 600 700 800 900 1000
200
400
600
800
1000
Something cunning you can do i
The extreme basics — I i
1. help
The extreme basics — I i
1. help
2. lookfor
The extreme basics — I i
1. help
2. lookfor
3. type
The extreme basics — I i
1. help
2. lookfor
3. type
4. who, whos
The extreme basics — I i
1. help
2. lookfor
3. type
4. who, whos
6. diary
The extreme basics — II i
7. plot
The extreme basics — II i
7. plot
8. xlabel,ylabel,title
The extreme basics — II i
7. plot
8. xlabel,ylabel,title
11. hold on, hold off
The extreme basics — II i
7. plot
8. xlabel,ylabel,title
11. hold on, hold off
13. sprintf
The extreme basics — II i
7. plot
8. xlabel,ylabel,title
11. hold on, hold off
13. sprintf
14. print
The extreme basics — II i
7. plot
8. xlabel,ylabel,title
11. hold on, hold off
13. sprintf
14. print
15. load, imread
Props i
Name Function Exampleimread Reads an image file ix=imread('filename');fullfile Constructs a valid path name ff=fullfile('dirn','fname');size Queries the size of a variable s=size(ix);plot Plots (x, y) values on a graph x=[1 2 3]; y=[10 20 30];
plot(x,y,'o')xlabel Uses a quoted string for an x-axis label xlabel('elevation [m]')ylabel Uses a quoted string for a y-axis label xlabel('roughness')hold on Keeps current axes for next time you plot anything x=[1 2 pi]; y=[10 20 30];
plot(x,y,'bo'); hold on;plot(10*x,3*y,'rs')
linspace Makes an array of N evenly spaced values x=linspace(-3,3,100)between a and b
reshape Changes the dimensions of an array x x=linspace(-3,3,100);to a rows and b columns xr=reshape(x,20,5)
hist Makes a histogram (and plots it) x=linspace(-3,3,10);hist(x)
bar
axis xy
axis ij
Table 1: List of Matlab commands and their function and usage examples.
1
The extreme basics — III i
Addressing:rows, columns, dimensions, range
The extreme basics — III i
Addressing:rows, columns, dimensions, range
17. size
The extreme basics — III i
Addressing:rows, columns, dimensions, range
17. size
18. transpose
The extreme basics — III i
Addressing:rows, columns, dimensions, range
17. size
18. transpose
19. colon
The extreme basics — III i
Addressing:rows, columns, dimensions, range
17. size
18. transpose
19. colon
20. linspace
The extreme basics — III i
Addressing:rows, columns, dimensions, range
17. size
18. transpose
19. colon
20. linspace
Logic:logical, character, string, double
The extreme basics — III i
Addressing:rows, columns, dimensions, range
17. size
18. transpose
19. colon
20. linspace
Logic:logical, character, string, double
21. <, >, ==, ∼, &, |
Going commando i
0 500 1000 1500 2000 2500 3000 3500 4000 4500 500040
60
80
100
120
140
160
180anything 3
column dimension
row
dim
ensi
on
Walkthrough i
colo
r
I, Frederik Simons, am plotting H1W−18.35−test2.jpg
grey
grey
500 550 600 650 700 750 800 850 900 950 1000
diff(
grey
)
Script! i
0 100 200 3000
0.5
1
1.5
2
2.5
3
3.5
4
4.5x 10
6
0 100 200 3000
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5x 10
6
0 100 2000
1
2
3
4
5
6x 10
6
Homework 1 i
Navigate to Course Materials, Software Installation and Templates.
1. Install Matlab as per the instructions.
2. Start Matlab: you will be making a Very Simple Plot.
3. Create ("edit") a new code (*.m) file called "lab01b.m" and in it,
type the following few instructions, or some slight variations
thereof, according to your taste (i.e. vary the numbers):
x=linspace(0,pi,100);
A=1; B=3; f1=0; f2=0;
y1=A*sin(x+f1); y2=B*cos(x+f2); y3=y1+y2;
figure (1)
plot(x,y1,’r’); hold on; plot(x,y2,’g’); plot(x,y3,’b’)
title(’yournetidl01b’)
hold off; axis tight
print(’-dpdf’,’yournetidl01b’)
4. Save this file, see that you can find it again.
5. In step 3, "yournetid" is once again your Princeton netid of course.
6. Now "run" or "execute" this "script" and make sure that something
pops up on your screen - and that a PDF gets made!
7. Find the PDF that you just made (’yournetidl01b.pdf’).
That is your second Assignment! Upload it to Blackboard by the deadline.
Homework 1 i
0 0.5 1 1.5 2 2.5 3 3.5−3
−2
−1
0
1
2
3
4yourpuidl01b
Code hygiene i
1. “If you type it twice, you need to use a variable”
Code hygiene i
1. “If you type it twice, you need to use a variable”
2. “If you say it in the absolute, you need to reformulate to the relative”
Code hygiene i
1. “If you type it twice, you need to use a variable”
2. “If you say it in the absolute, you need to reformulate to the relative”
3. “Annotate all graphs completely, and give them meaningful names ”
Code hygiene i
1. “If you type it twice, you need to use a variable”
2. “If you say it in the absolute, you need to reformulate to the relative”
3. “Annotate all graphs completely, and give them meaningful names ”
4. “Annotate all code completely, to a ridiculous degree”
Code hygiene i
1. “If you type it twice, you need to use a variable”
2. “If you say it in the absolute, you need to reformulate to the relative”
3. “Annotate all graphs completely, and give them meaningful names ”
4. “Annotate all code completely, to a ridiculous degree”
Documentation/Help/Date
Code hygiene i
1. “If you type it twice, you need to use a variable”
2. “If you say it in the absolute, you need to reformulate to the relative”
3. “Annotate all graphs completely, and give them meaningful names ”
4. “Annotate all code completely, to a ridiculous degree”
Documentation/Help/Date
Input/Output
Code hygiene i
1. “If you type it twice, you need to use a variable”
2. “If you say it in the absolute, you need to reformulate to the relative”
3. “Annotate all graphs completely, and give them meaningful names ”
4. “Annotate all code completely, to a ridiculous degree”
Documentation/Help/Date
Input/Output
Computation/Algorithm
Code hygiene i
1. “If you type it twice, you need to use a variable”
2. “If you say it in the absolute, you need to reformulate to the relative”
3. “Annotate all graphs completely, and give them meaningful names ”
4. “Annotate all code completely, to a ridiculous degree”
Documentation/Help/Date
Input/Output
Computation/Algorithm
Figures/Embellishment
Code hygiene i
1. “If you type it twice, you need to use a variable”
2. “If you say it in the absolute, you need to reformulate to the relative”
3. “Annotate all graphs completely, and give them meaningful names ”
4. “Annotate all code completely, to a ridiculous degree”
Documentation/Help/Date
Input/Output
Computation/Algorithm
Figures/Embellishment
Variable Output
Homework 2 — Data collection i
0 50 100 150 200 250 300 3500
50
100
150
200
250
300
350
easting [m] from 528927 in UTM zone 18
north
ing
[m] f
rom
446
6190
in U
TM z
one
18Adrian’s GPS data, their means ±2 standard deviations
CP1CP2CP3CP4CL5
Homework 2 — Data curation i
0 50 100 150 200 250 300 350
0
50
100
150
200
250
300
350
easting [m] from 528927 in UTM zone 18
nort
hing
[m] f
rom
446
6190
in U
TM
zon
e 18
Adrian’s GPS data, their means ±2 standard deviations
CP1CP2CP3CP4CL5
Homework 3 — Data analysis i
FRS 135, LAB 04 lillianw, 1 of 1
TRANSVERSE DUNES IN THE SYRIA PLANUM, MARS1
Motive. By examining transverse dunes on Mars, an environment without disruptive elements such as water and2
vegetation, we can draw conclusions about the initial processes of transverse dune formation on Earth. More3
specifically, we investigate why higher degree slopes correspond with shorter transverse dune wavelengths and4
higher amplitudes.5
Hypothesis . Shorter dune wavelengths appear on steeper slopes because winds are not able to travel far6
before touching the ground and depositing sediment; higher dune amplitudes occur on steeper slopes because7
the distance of the slope to the boundary layer decreases at a quicker rate, resulting in higher velocity sediment-8
carrying winds that can carry and deposit more sediment.9
180 200 220 240
Ele
vatio
n [m
]
6152
6154
6156
6158
6160
A
Meters East230 240 250 260 270 280 290 300
Ele
vatio
n [m
]
6154
6156
6158
6160
B
Dune Wavelength [m]5 10 15 20 25 30
Cou
nt
0
1
2
3
4
5
6A
6B
AB
Bright Dunes in the Syria Planum
Meters0 50 100 150 200 250
Met
ers
0
50
100
150
200
250
Ele
vatio
n [m
]
0
2
4
6
8
10
12
14
16
Figure 1: Transect A crosses 8 transverse dune peaks and transect B crosses 6 dune peaks . Transect B follows a steeperslope than transect A. The average dune wavelength found along transect B was 7.54m; along transect A the average dunewavelength was 12.47m. The average dune amplitudes (not shown in figure) were 1.02m for transect B and 0.82m fortransect A. Image was downloaded from < htt p : //www.uahirise.org/dtm/dtm.php?ID = ESP0328141670>
Acknowledgements. Thank you to Chris Harig, Adam Maloof, and Amber Yin for their help with figure10
drafting in Matlab, and to Gene Li for assiting with the image download.11
Homework 3 — Data analysis iFRS 135, LAB 04 gretam, 1 of 1
INTRA-CRATER DUNES IN IAXARTES THOLUS, MARS1
Motivation. Studying digital elevation models of dunes on Mars can lead to insights about the surface and2
weather on Mars.3
Hypothesis. As the elevation of the dunes in Iaxartes Tholus increases, the dunes increase in size (wavelength4
and amplitude), possibly due to a more abundant sand supply.5
Meters East0 500 1000 1500 2000 2500
Ele
vatio
n [m
]
0
50
100
150
200
A
Meters East0 500 1000 1500 2000 2500
Ele
vatio
n [m
]
0
50
100
150
200
B
Elevation [m]0 50 100 150 200
Dun
e W
avel
engt
h [m
]
0
100
200
300
400
500
600
700
AB
A
B
Intra-Crater Dunes in Iaxartes Tholus, Elevation offset = -5982.44 m
Meters East0 500 1000 1500 2000 2500 3000 3500
Met
ers
Sou
th
0
500
1000
1500
2000
2500
Ele
vatio
n [m
]
0
20
40
60
80
100
120
140
160
180
200
Figure 1: Intra-crater dunes in Iaxartes Tholus vary with elevation. Transect lines show increasing wavelength and amplitude as the elevation increases.Digital elevation model came from http://www.uahirise.org/dtm/dtm.php?ID=ESP_018938_2520.
Acknowledgements. Thank you to Gene Li, Joanna Zhang, Bruce Allen, Devin Blake Kilpatrick, Chris6
Harig and Adam Maloof who helped with figure drafting.7
Homework 3 — Data analysis iBRUCE ALLEN, LAB 04 brucema, 1 of 1
DARK DUNES IN HERSCHEL CRATER OF MARS1
Motivation. Mapping and analyzing sand dunes on Mars allows humans to better understand the environment2
of a place that they’ve yet to step foot on.3
Hypothesis. Based on the geometry in figure 1, the transected dunes are Barchan dunes.4
A
B
Dark Dunes in Herschel Crater of Mars
Meters0 500 1000 1500
Met
ers
0
500
1000
1500
2000
2500
3000
Elev
atio
n [m
]
0
10
20
30
40
50
0 100 200 300 400 500
Elev
atio
n [m
]
0
10
20
30
40
50
A
Meters East0 100 200 300 400 500
Elev
atio
n [m
]
0
10
20
30
40
50
B
Elevation [m]0 20 40 60
Cou
nt
#105
0
2
4
6
8
10
12
14Elevations offset from 1161.76
Mean = 17.90Median = 15.02
Figure 1: The heat map represents the elevation of sand dunes on Mars, with two transects, A and B, drawn over two specificdunes. The elevation, along with the peaks, of those dunes are then graphed as A and B respectively below the heat map.The histogram is a count of how often certain elevations were measured and the mean and median of those measurements.
Acknowledgements. Thank you to Akshay Mehra and Christopher Harig for helping me detect problems in5
my code.6
Homework 3 — Data reduction i
0 10 20 30 40 50 60 70 80 90 100
−10
−8
−6
−4
−2
0
2
4
6
8
10
mynetidl05 − A 1.00 4.00 5.00 P 10.00 30.00 40.00 ph 0.00 1.57 0.00
time [s]
sign
als
(indi
vidu
al p
iece
s an
d th
eir
sum
)
Homework 3 — Data reduction i
0 10 20 30 40 50 60 70 80 90 100−10
−5
0
5
10
time [s]
sign
al a
nd it
s pr
edic
tion
rms prediction error is 2.78 data unitsvariance reduction 59.56%
0 5 10 15 20 25 30 35 40 450
1
2
3
4
5
period [s]
ampl
itude
[uni
ts o
f the
dat
a]
mynetidl05 − A 0.16 0.69 4.73 P 9.00 20.00 42.00
Homework 3 — Data reduction i
0 10 20 30 40 50 60 70 80 90 100−10
−5
0
5
10
time [s]
sign
al a
nd it
s pr
edic
tion
rms prediction error is 0.00 data unitsvariance reduction 100.00%
0 5 10 15 20 25 30 35 400
1
2
3
4
5
period [s]
ampl
itude
[uni
ts o
f the
dat
a]
mynetidl05 − A 1.00 4.00 5.00 P 10.00 30.00 40.00
Homework 3 — Data reduction i
0 10 20 30 40 50 60 70 80 90 100−10
−5
0
5
10
time [s]
sign
al a
nd it
s pr
edic
tion
rms prediction error is 1.86 data unitsvariance reduction 81.94%
0 5 10 15 20 25 30 35 40 45 500
1
2
3
4
period [s]
ampl
itude
[uni
ts o
f the
dat
a]
mynetidl05 − A 1.04 3.51 4.28 P 10.00 30.00 46.00
Homework 3 — Data reduction i
0 10 20 30 40 50 60 70 80 90 100−15
−10
−5
0
5
10
15
time [s]
sign
al a
nd it
s pr
edic
tion
rms prediction error is 3.47 data unitsvariance reduction 48.87%
0 5 10 15 20 25 30 35 40 450
1
2
3
4
5
period [s]
ampl
itude
[uni
ts o
f the
dat
a]
mynetidl05 − A 0.39 0.63 4.74 P 9.00 20.00 42.00
Homework 3 — Data reduction i
0 10 20 30 40 50 60 70 80 90 100−15
−10
−5
0
5
10
15
time [s]
sign
al a
nd it
s pr
edic
tion
rms prediction error is 1.81 data unitsvariance reduction 86.11%
0 5 10 15 20 25 30 35 400
1
2
3
4
5
period [s]
ampl
itude
[uni
ts o
f the
dat
a]
mynetidl05 − A 1.14 4.22 5.07 P 10.00 30.00 40.00
Homework 3 — Data reduction i
0 10 20 30 40 50 60 70 80 90 100−15
−10
−5
0
5
10
15
time [s]
sign
al a
nd it
s pr
edic
tion
rms prediction error is 2.66 data unitsvariance reduction 70.01%
0 5 10 15 20 25 30 35 40 45 500
1
2
3
4
period [s]
ampl
itude
[uni
ts o
f the
dat
a]
mynetidl05 − A 1.09 3.74 4.27 P 10.00 30.00 46.00
Homework 3 — Data reduction i
0 10 20 30 40 50 60 70 80 90 100−10
−5
0
5
10
time [s]
sign
al a
nd it
s pr
edic
tion
rms prediction error is 2.83 data unitsvariance reduction 44.53%
0 5 10 15 20 25 30 35 40 450
0.5
1
1.5
2
2.5
3
3.5
period [s]
ampl
itude
[uni
ts o
f the
dat
a]
mynetidl05 − A 0.14 0.55 3.55 P 9.00 20.00 42.00
Homework 3 — Data reduction i
0 10 20 30 40 50 60 70 80 90 100−10
−5
0
5
10
time [s]
sign
al a
nd it
s pr
edic
tion
rms prediction error is 1.85 data unitsvariance reduction 76.19%
0 5 10 15 20 25 30 35 400
1
2
3
4
period [s]
ampl
itude
[uni
ts o
f the
dat
a]
mynetidl05 − A 0.74 3.01 3.78 P 10.00 30.00 40.00
Homework 3 — Data reduction i
0 10 20 30 40 50 60 70 80 90 100−10
−5
0
5
10
time [s]
sign
al a
nd it
s pr
edic
tion
rms prediction error is 2.39 data unitsvariance reduction 60.47%
0 5 10 15 20 25 30 35 40 45 500
0.5
1
1.5
2
2.5
3
period [s]
ampl
itude
[uni
ts o
f the
dat
a]
mynetidl05 − A 0.83 2.68 3.13 P 10.00 30.00 46.00
Homework 4 — All of the above i
0 50 100 150 200 250
4.958
4.96
4.962
4.964
4.966
x 104
0 50 100 150 200 250
4.945
4.95
4.955
4.96
4.965
4.97x 10
4
time [s]
sign
al a
nd it
s pr
edic
tion
rms prediction error is 26.29 data unitsvariance reduction 4.82%