%Count the number of leap year days between Jan 1, 1900, and % Dec 31 of the inputted year in the 21st century, inclusive. noLD = 0; 0umber of leap days y = input('Enter a year from 1900 to 2099, inclusive: '); % caluculate the n of leap days if (y < 2100
%Count the number of leap year days between Jan 1, 1900, and % Dec 31 of the inputted year in the 21st century, inclusive. noLD = 0; 0umber of leap days from 1/1/1900 x = 0; 0umber of leap days from y to 12/31/2199 y = input('Enter a year from 1900 to 219
function newMatrix = my_permute(matrix, i, j) nc = size(matrix,2); newMatrix=matrix; for c=1:nc newMatrix(i,c) = matrix(j,c); newMatrix(j,c) = matrix(i,c); end
CS 100M Lecture 8 Topic: User-dened function, random numbers Reading: CFile Chapter 4
September 19, 2006
Script vs. function
A script is an m-le that is executed line-by-line just as if we are typing it into the Command Window. The value of a variable in
function finddna = findPattern(dna, pat) found = []; for i = 1:length(dna)-3 if pat(i) = 'A' & pat(i+1) = 'c' & pat(i+2) = 'G' & pat(i+3) = 'T' found = [found i]; end end
Chapter 3
Sequences
3.1 Summation
Nested loops, while-loops with compound termination criteria
3.2 Recursions
One-term recursion, searching for a first occurrence, two-term recursion.
In Chapter 2 we played with the sequence of regular n-gon areas
Chapter 4
Exponential Growth
4.1 Powers
User-defined function, function declarations, preconditions and post conditions, parameter lists, formal and actual parameters, functions that call other functions, scope rules, development through generalizat
Chapter 5
Points In The Plane
5.1 Centroids
One-dimensional arrays-vectors, initializing vectors, colon expression for subvectors, empty array [], functions with vector parameters, functions that return vectors.
5.2 Max's and Min's
Algorithm for fi
Chapter 9
The Second Dimension
9.1 Rows and Columns
2-dimensional arrays-matrix, functions that involve matrices, colon notation for submatrices, built-in function size
9.2 Operations
Searching a 2-dimensional array and updating its values, built-i
Chapter 1
From Formula to Program
1.1 A Small Example
Program structure, comments, variables, names, types, input, printing and formatting messages with fprintf, the assignment statement.
1.2 Sines and Cosines
Fragments, assertions, overwriting, sy
CS100M, Spring 2006
Prelim 1
Feb 23, 7:30 9:00pm
Name: _ (Legibly print last name, first name, middle name) NetID: _ Statement of integrity: I did not, and will not, break the rules of academic integrity on this exam. _ (Signature) Circle your lecture: Ci
CS100M Fall 2006 Project 2
Due: September 21, 2006 (Thursday) at 6pm
Submit your files on-line in CMS before the project deadline. Both correctness and good programming style contribute to your project score. You must work either on your own or with one p
CS100M Fall 2006 Project 3
due Thursday 10/5 at 6pm
You must work either on your own or with one partner. You may discuss background issues and general solution strategies with others, but the project you submit must be the work of just you (and your part
function x = toUpper(cha) %converts cha to upper case if it's lower case letter %if not lowercase letter, simply return cha code = double(cha); if code>=97 & code<=122 code=code-(97-65); x = char(code); else x = cha; end