
ANDY RIDGWELL STR = ’DO YOU LIKE BANANAS?’ UC-RIVERSIDE / DEPT. OF EARTH AND PLANETARY SCIENCES 2019/20 Copyright © 2019 Andy Ridgwell http://www.seao2.info/teaching.html Except where otherwise noted, content of this document is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 license (CC BY-NC-SA 3.0) (http://creativecommons.org/licenses/by-nc-sa/3.0/) Current printing, December 2019 Contents How to use this Textbook 17 0.1 Fonts and highlighting 17 0.2 Help(!) and keyword definitions 17 0.3 Side notes and other distractions from the main text 18 0.4 What and when to type 18 0.5 Code structure 19 0.6 ’Answer’ codes 20 1 Elements of ... MATLAB and data visualization 21 1.1 Using the MATLAB software 22 1.1.1 Starting MATLAB 22 1.1.2 The command line 22 1.1.3 MATLAB GUI 23 1.1.4 Help(!) 23 1.2 Basic concepts 24 1.2.1 Variables 24 1.2.2 Numerical expressions and Arithmetic operators 27 1.2.3 Relational and logical operators 28 1.2.4 Functions (built-in) 29 1.2.5 Miscellaneous commands 29 1.3 Vectors and arrays #1 31 1.3.1 Creating vectors 31 1.3.2 Basic vector manipulation 32 1.3.3 Addressing elements in vectors 32 4 1.4 Basic graphing (aka. ’data visualization’) 34 1.4.1 Plotting 34 1.4.2 Graph labelling 35 1.4.3 Sub-plots 36 1.4.4 Saving graphics and figures 36 1.5 Vectors and arrays #2 38 1.5.1 Creating matrices and arrays 38 1.5.2 Basic matrix manipulation 39 1.5.3 Some matrix math :( 41 1.6 Loading and saving data 43 1.6.1 Where am I? 43 1.6.2 Loading and importing data 44 1.6.3 Saving and exporting data 45 1.6.4 Loading and saving the workspace 45 1.7 Basic data processing (and yet more plotting) 47 1.7.1 Sorting data (in arrays) 47 1.7.2 Data scaling 49 1.7.3 Data (row) deletion 50 1.8 Nicer graphing 53 1.8.1 Modifying lines/symbols in plot 53 1.8.2 Plotting multiple data-sets 53 1.8.3 Changing label font size (and type) 54 1.8.4 Scatter plots 55 1.8.5 Simple 2D data and bitmap visualization 55 1.9 Further matrix math (systems of equations) 57 2 Elements of ... programming 61 2.1 Introduction to scripting (programming!) in MATLAB 62 2.1.1 Programming good practice 63 2.1.2 Debugging the bugs in buggy code 65 5 2.2 Functions 68 2.3 Conditionals ’101’ 71 2.3.1 if ... 71 2.3.2 switch ... 76 2.4 Loops ’101’ 78 2.4.1 for ... 78 2.4.2 Other loop configurations and usages 82 2.4.3 Fun(!) worked examples 83 2.5 Loops and conditionals ... together(!) 89 2.5.1 for ... and conditionals 89 2.5.2 while ... 92 2.6 Even more (and loopier) loops 95 3 Further ... MATLAB and data visualization 99 3.1 Further data input 100 3.1.1 Formatted text (ASCII) input 100 3.1.2 Importing ... Excel spreadsheets 104 3.1.3 Importing ... netCDF format data 105 3.2 Further (spatial / (x,y,z)) plotting 108 3.2.1 Contour plotting 108 3.3 Further data processing 117 3.3.1 find! 118 3.3.2 Other data filtering 123 3.3.3 Basic (pretend) ’stats’ 124 3.3.4 Some useful data manipulations techniques 126 3.3.5 Data interpolation 127 3.4 Even nicer graphing and graphics 131 3.4.1 Drawing lines and shapes 132 3.4.2 Colors 137 3.4.3 Placing and making text ’nice’ 137 3.4.4 Creating color maps 138 6 4 Further ... Programming 141 4.1 Nested loops 142 4.2 Algorithms and problem-solving 150 4.2.1 Example #1: max(!) 150 4.2.2 Example #2: sort(!!) 155 4.2.3 Example #3: a gridded problem 158 4.3 Interpreting equations (0) – Basics 170 4.4 Interpreting equations (1) – Population models 171 4.4.1 Exponential (and unrestricted) growth 171 4.4.2 Restricted growth (and an equilibrium state) 172 4.5 Interpreting equations (2) – Pure lovely maths 175 4.5.1 Sequence convergence (in 1D) 175 4.5.2 Sequence convergence (in 2D) 178 5 Programming applications – games! 185 5.1 Tic-tac-toe 186 5.1.1 Mouse behavior 189 5.1.2 Drawing the ’objects’ 189 5.1.3 Identifying specific boxes 191 5.1.4 Remembering turns (and arrays!) 193 5.1.5 Putting it all together 194 6 Numerical modelling – zero-D / equilibrium 199 6.1 Zero-D Energy-balance model of the climate system 200 6.1.1 The basic EBM 201 6.1.2 The EBM as a function 203 6.1.3 Creating a function for the evolution of solar constant through geological time 204 6.1.4 Using multiple functions and calculating global surface temperature as a function of geological time 205 6.1.5 Parameter sensitivity experiments using the EBM – #1 208 6.1.6 Parameter sensitivity experiments using the EBM – #2 211 7 6.2 ’Daisy World’ 214 6.2.1 ’fixed daisy’ daisy-world 215 6.2.2 ’dumb daisy’ daisy-world 217 6.2.3 ’clever daisy’ daisy-world 221 6.2.4 Efficient and ’clever daisy’ daisy-world 222 7 Numerical modelling – Dynamic (time-stepping) 225 7.1 Catch the ball (ballistics and simulating trajectories) 230 7.2 Dynamics in the zero-D Energy-balance climate model 240 8 Numerical modelling – To infinity (1D) and beyond(!) 245 8.1 1-D energy-balance climate model 246 8.2 1-D reaction-transport model 252 9 Graphical User Interfaces (GUI) 263 9.1 MATLAB GUI basics 264 9.1.1 Hello, World [Static Text (box)] 266 9.1.2 Simple GUI responses [Push Button] 268 9.1.3 Updating object properties (do you like bananas?) 271 9.1.4 Simple GUI responses [Sliders] 275 9.2 MATLAB apps 277 10 Numerical modelling meets GUI (prettier games!) 279 10.1 GUI Pokémon game 280 11 Example codes 297 11.1 Chapter 1 codes 298 11.2 Chapter 2 codes 299 11.3 Chapter 4 codes 301 11.4 Chapter 10 codes 302 8 Bibliography 303 Index 305 List of Figures 1 Schematic for a generic script. 19 2 Schematic for a generic function. 19 1.1 Example of the default output of the plot function. 34 1.2 A plot illustrating axis auto-scaling (maximum x and y values now slightly larger than 10 and 100, respectively). 35 1.3 A (only very slightly) improved plot. 35 1.4 Arrangement of subplots. 36 1.5 Result of simply throwing the entire data matrix at plot .... 45 1.6 Spline fit to measured changes inCO2 concentration in Law Done ice core, following Etheridge et al. [1996]. 45 1.7 proxy reconstructed past variability in atmospheric CO2. 47 1.8 Proxy reconstructed past variability in atmospheric CO2 (sorted data). 48 1.9 Observed annual global mean surface temperature anomaly (com- pared to year 1910 to 2000 average). 49 1.10 Observed annual global mean surface temperature. 50 1.11 Observed annual mean surface temperature in Riverside. 51 1.12 Observed global annual mean surface temperature anomaly, relative to the mean of 1910 through 2000. 51 1.13 Observed annual mean surface temperature anomaly, relative to the mean of 1910 through 2000, at Riverside. 52 1.14 Observed annual mean surface temperature anomaly, relative to the mean of 1910 through 2000, at Riverside, filtered to remove years with missing monthly data. 52 1.15 Proxy reconstructed past variability in atmospheric CO2 (sorted data). 53 1.16 Proxy reconstructed past variability in atmospheric CO2 (sorted data). 54 1.17 Proxy reconstructed past variability in atmospheric CO2 (scatter plot). 55 1.18 Proxy reconstructed past variability in atmospheric CO2 (scatter plot). 55 1.19 A 2D plot of some random gridded model data. 55 1.20 A 2D plot of some random gridded model data ... but with the un- derlying data matrix re-orientated before plotting. 56 1.21 Lake volumes and river flow rates in the Great Lakes system. 57 2.1 Schematic of the example program. 64 10 2.2 Schematic of the Hello World program. 65 2.3 Output from the (bug-fixed version of) plot_some_dull_stuff m-file. 67 2.4 Schematic structure of the simple bananas question program. 72 2.5 Schematic structure of the extended bananas question program. 73 2.6 A slight variant on the schematic structure of the extended bananas question program. 74 2.7 Schematic of the bananas program using the if ... else ... construct (and displaying alternative messages). 74 2.8 Extremely unappealing blocky plot of Earth surface temperature (who cares with month? – the graphics are too poor to matter ...). 86 2.9 Continental outline (of sorts). 96 2.10 Another continental outline (of sorts). 96 2.11 Another go at the continental outline! 98 3.1 Very basic imaging (image) of an array (2D) of data – here, global bathymetry. 109 3.2 Slightly improved very basic imaging (imagesc) of bathymetry data. 109 3.3 Example result of basic usage of the contour function. 110 3.4 Example usage of contourf, with the hot colormap (giving dark- /brown colors as deep ocean, and light/white as high altitude). 110 3.5 Example usage of contour, contouring only the zero height isoline, and providing a label.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages307 Page
-
File Size-