Introduction to scientific programming in Earth's Sciences - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Introduction to scientific programming in Earth's Sciences

Description:

The Fibonacci numbers are computed according to the following relation: Fn = Fn ... first 10 Fibonacci numbers. For the first 50 Fibonacci numbers, compute the ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 10
Provided by: guillaum1
Category:

less

Transcript and Presenter's Notes

Title: Introduction to scientific programming in Earth's Sciences


1
Introduction to scientific programming in Earth's
Sciences
J.W. Goethe University. Frankfurt
  • Dr Guillaume RICHARD
  • Institüt für Geowissenchaften 1.232
  • richard_at_geophysik.uni-frankfurt.de

2
Overview
  • 12 x 45min Lectures / 45min training classes
    (praktical)
  • Basics (Hardware, OS, editor, etc.. )
  • Basics 2 (Linux commands, Compile,Visualize )
  • Languages Fortran (FORmula TRANslation)
  • Languages Fortran (2)
  • Languages Fortran (3)
  • Languages Fortran (4)
  • Languages C/C
  • Languages Matlab (1)
  • Languages Matlab (2)
  • Languages Maple
  • Introduction to Finite difference / Finite Volume
    method
  • Introduction to Finite difference / Finite Volume
    method (2)

3
L. 9 Matlab (2)
4
Plotting
  • The plot command is used to generate xy-plots in
    addition with title('figure'), xlabel('x'),
    ylabel('y')
  • Ex gtgt h pi/16 x 0hpi y sin(x) size(y)
  • gtgt plot(x,y,'go',x,2y)
  • gtgt plot(x,abs(y),'mx')
  • Subplots
  • Everything on one plot
  • Ex gtgt subplot(1,2,1)
  • gtgt plot(x,y,'go',x,2y)
  • gtgt subplot(1,2,2)
  • gtgt plot(x,abs(y),'mx')

5
Plotting
Overview of plotting facilities in matlab X-Y
plots Plot, Semilogx, semilogy,
loglog Histograms Hist R-Theta (polar) plots
Polar 3-D plots Mesh (surface plot), contour,
quiver (Vector field plot (matrix of arrows) )
6
Plotting
  • Examples
  • To plot sin(x)cos(y), for -4ltxlt4 -4ltylt4
  • gtgt X,Ymeshgrid(-4.24,-4.24)
  • gtgt mesh(sin(X).cos(Y))
  • or,
  • gtgt contour(sin(X).cos(Y))
  • Print
  • Use command print
  • Ex gtgt print -dps figure1.ps

7
C Style Read/Write
  • In addition to the high level read/write
    commands, Matlab allows C style file access. This
    is extremely helpful since the output generated
    by many home grown programs is in binary format
    due to disk space considerations.
  • The basic idea is that you open a file, execute
    the relevant reads and writes on a file, and then
    close a file. To move the file pointer to point
    to a particular place in the file use fseek and
    ftell.
  • Ex a file called "laser.dat" is opened. The file
    identifier is kept track of using a variable
    called fp. Once the file is opened the file
    position is moved to a particular place in the
    file, denoted pos, and two double precision
    numbers are read. Once that is done the position
    within the file is stored, and the file is
    closed.
  • gtgt fp fopen('laser.dat','r')
    fseek(fp,pos,'bof')
  • gtgttmp fread(fp,2,'double') pos ftell(fp)
    fclose(fp)

8
Read variables from a TEXT FILE
You can load data into matlab using the "load"
command. The data should be arranged just as you
would want to appear in the matrix for example,
loading a file which contained 1.1 2.2 3.4 2.2
3.3 2.3 would result in a two row, three column
matrix. The file should end in the extension
".dat". To load the file into a variable in
matlab, you'd type something of the following
form (substituting the path for your data) at the
matlab prompt gtgt load filename.dat The data
from the file will be loaded into the variable
"filename".
9
Exercice
  • The Fibonacci numbers are computed according to
    the following relation Fn Fn-1 Fn-2 with F0
    F1 1.
  • Compute the first 10 Fibonacci numbers.
  • For the first 50 Fibonacci numbers, compute the
    ratio Fn / Fn-1.
  • It is claimed that this ratio approaches the
    value of the golden ratio. What do your results
    show (plot them) ?

The golden ratio is defined as the ratio that
results when a line is divided so that the whole
line has the same ratio to the larger segment as
the larger segment has to the smaller segment.
Expressed algebraically, normalising the larger
part to unit length, it is the positive solution
of the equation X/11/(X-1)
( (1 sqrt(5))/2 )
Write a Comment
User Comments (0)
About PowerShow.com