Functions
Objectives
Functions
Control flow
Syntax
Scope
Functions
Variables
Purpose
This far
Script files
All code inside one big file
maybe structured into cells
Used builtin matlab functions
sin, cos, zeros etc.
How do we structure our code?
COMP 116: Introduction to
Scientific Programming
Spring Semester 2017
Roll call!
I am going to read off the roster as we know it.
If I call your name, please respond. ;)
If I dont call your name, then please send us ([email protected]
and [email protected]
COMP 116: Introduction to Scientific Programming and Data Science
Bulletin Description:
COMP 116 Introduction to Scientific Programming (3). Prerequisite MATH 231. An
introduction to programming for computationally oriented scientists. Fundamental
program
Professor Presentation 2012
We want a simpler world where students arent stuck on homework and instructors arent
buried under student emails a world where knowledge transfer from instructors, and
between students, is rapid, fun and beautifully efficient.
Assignment 5: Watershed Computations
Due Thursday, April 13rd, 2017 at 11:59pm
A watershed is an area of land that is drained by a collection of rivers, streams, or lakes, and is the natural
unit for managing natural resources and controlling effluent res
/*
* $SimpleCalculator.java
*
* Program TODO:<3 >: TODO:<SimpleCalculator>
*
* Programmer: Andrew Clary
* Due Date: TODO: 7/6/2015
*
* Bonus(es) Attempted: TODO: none
*
* COMP110001, SS2 2015 Instructor: Alex Blate
*
* HONOR PLEDGE: On my honor, I have n
Andrew Clary 720450131
Written HW1
R2.1:
Mystery is equal to 0 at the end of the sequence.
R2.2
A variable can only be initialized once and it is initialized in both the first and the third lines.
R2.5
a.
b.
c.
d.
e.
6.25
6
12.5
3
Sqrt(2)
R2.11
2 is an i
MATLAB
continued
MATLAB environment
Command Window
Workspace
Current directory
Command History
Editor Window
Figure Window
Help System
MATLAB concepts
Case Sensitive
Grouping
( ), cfw_ , [ ]
Help
> help <topic>
> doc <topic>
> helpbrowser
Quitting
Brief Introduction to Arrays
Scalars, Vectors and Matrices
Vocabulary
Array: A collection of items that can be selected
by indices.
Matrix: A table of numbers.
A rectangular (mn) array of m rows and n
columns of elements (values).
Vector: A matrix contain
Basic Concepts
Assignment, Variables, Expressions
What we are going to learn
Programming
Assignment <variablename> = <expresssion>
Variables
Naming rules & Naming guidelines
Data Types int32, uint16, single, double, char,
Expressions
More Operators
Logic
Conditional Logic
Logical Expressions,
Selection Statements
Motivation
Step by Step Programming
All we have learned to do up to now
Execute statements in order they occur
Single path through program script
Conditional Programming
What if we only want
Program Design
Readable Programs
Whitespace
Grouping
Indentation
to show control flow
Documentation
Naming
Comments
Write programs for
people first,
computers second.
 Steve McConnell
Will you be able to
read and understand
your own code six
months
SCOPE (cont)
Main Script:

clear all
global a
a = 3;
b = 2;
c = 1;
a = callMe1( b, c );
b = callMe2( c, a );
function ret = callMe1( a, b )
ret = a1;
a = 4;
function c = callMe2( b, d )
global a
a = callMe1(b,d);
c = b;
Rotate Columns
Ponder, if you w
Basic Concepts
Least Squares and Linear Systems
What we are going to learn
Leastsquares in depth
Simple algorithms/concepts to invert
matrices
This is all implemented in MATLAB (\)
( and more sophisticated methods).
We simply revisit the principles of m
Plotting & Publishing
What we are going to learn
Plotting 2D graphics
Plot, line attributes, other properties
Formatting: Labels, titles, legends,
Multiple plots (overlaid, subplots)
Other plot commands
Publishing scripts to documents
HTML
Microsoft W
Basic Concepts
Matrices and Calculations
Introduction to Linear Systems
What we are going to learn
Review: Operators on scalars, vectors,
and matrices
Review: Difference between elementwise
and matrix operations
Introduction to linear systems in matrix
Basic Concepts
Matrices and Indices
What we are going to learn
Scalars,Vectors, and Matrices
Arrays
Indices
Matrix: A rectangular
(mn) array of m
rows and n columns
of elements (values).
Vector: A matrix
containing only a
single row (1n) or
column (m1).
if expression
statements
end
expression
F
T
statements
if expression
statements 1
else
statements 2
end
Statements 2
F
F
expression
T
Statements 1
if exp1
statements 1
elseif exp2
statements 2
else
statements 3
end
F
F
statements 3
exp2
exp1
T
statements
Andrew Clary (720450131)
Test Outputs
Test 1:
>4*5
> 20.0
>+7
> 27.0
>6
> 21.0
>/4
> 5.25
>
Discussion: for the first test I input typical values checking that the program would add,
subtract, divide, and multiply. I also checked that it would rememb
Quiz10: 3D Visualization
This quiz has 5 problems on 3D visualization. Each problem is worth 2 points.
There will be no partial credit.
As usual you have 30 minutes to solve it. Please time yourself.
Contents
P1: 3D Plotting
P2: Evaluating a 2D function
P
Notes0125
2/8/16, 7:03 PM
Notes for 25 January (snow day)
Ack! Another snow day and we're hardly started! I hate it that we are missing so many classes
here at the beginning when we should be laying down foundations.
No worries, we'll figure out how to br
Notes0323
3/29/16, 11:32 PM
Notes for 23 March
Prime numbers have been studied for centuries but a strange property of their last digits has just
been noticed. You can read the paper on arxiv (http:/arxiv.org/abs/1603.03720) or a more
approachable account
Notes0212
2/12/16, 1:19 PM
In [2]: %matplotlib inline
import numpy as np
import pylab
In [3]: np.random.seed(0) # we can force the random numbers to be same everytime
np.random.random_integers(0, 10, 10)
Out[3]: array([5, 0, 3, 3, 7, 9, 3, 5, 2, 4])
Tuple
Introduction to Python: An open resource for students and teachers
3/28/16, 9:26 AM
Show all output
Hide all output
Introducing Functions
One of the core principles of any programming language is, "Don't Repeat Yourself". If you have an action that should
Notes0311
3/29/16, 11:31 PM
Notes for 11 March
Functions, loops, and strings
A palindrome is a string that is the same when read forward or backward often with the
extension that you can ignore spaces and nonletter characters. For example:
hannah
racecar
Markdown Cells
2/8/16, 2:58 PM
Markdown Cells
Doubleclick in this cell to see how I created it.
This is a markdown cell. Markup languages describe how to format text. HTML is a markup
language. TeX is a markup language. Markdown is a super simple markup