10/26/2015
Addresses
Variables are stored in memory locations
They went that
away!
Each memory location has a unique address, a positive integer value
This address is determined when the program is compiled and loaded
It can vary from execution to executi
REVIEW OF
RECURSION
2010
Recursion
2
Factorial
The factorial function is a classic example of the
use of recursion
int fact(int n)cfw_
if (n > 1)
return n * fact(n-1);
else
return 1;
2010
Recursion
3
Recursive Binary Search
int recursive_binary_search
(i
NUMBERS
Nathan Friedman
2013
Computer Structure
Earlier we saw that computers are made up of
switches of some kind that can be on or off
We can represent these two values by 0 and 1
We build circuits to store binary sequences
We encode instructions as
Nathan Friedman
2012
Computing for Engineers
Reason #1:
My faculty made me!
Reason #2:
Its exciting to learn how to understand
computers better
2011
3
There are three components to this course
Computing for Engineers
2
Reason #1:
My faculty made me!
Comp
2009
Multidimensional Arrays
2
Power Output (Etter chapter 5.8)
We want to study the power output of an
MULTIDIMENSIONAL
ARRAYS
electrical plant over time
Given a file with the following structure
Each line represents the data acquired in a week
There
2010
Recursion
2
What is Recursion?
Recursion is a programming technique that
allows us to approach programming in a
different style
To solve a problem, we make an
assumption that the computer is able to
solve smaller instances of the same
problem
RECUR
02/10/2013
2013
Pointers in C
2
Addresses
Variables are stored in memory locations
THEY WENT THAT
AWAY!
Each memory location has a unique address, a positive
integer value
This address is determined when the program is compiled
and loaded
Pointers in C
2011
Subprograms
2
Functions
There are many useful operations which
DELEGATING TASKS
are not part of the basic instruction set of
the computer
C has many libraries containing such
functions for our use. We have seen some
of these intrinsic or predefined
9/2/2013
2013
Files and Arrays
2
Files
Large amounts of data are usually stored in files
These files can be created by programs that
DATA COLLECTIONS
generate values or capture data from sensing
devices
Programs can read and process the data stored
in
2011
Searching and Sorting
2
Wheres Waldo?
SEARCHING AND
SORTING IN C
A common use for computers is to search for the
Nathan Friedman
2013
We are given an array along with its size and a
whereabouts of a specific item in a list
The most straightforward
9/2/2013
2011
Do Loops and Arrays
2
Repetition
OVER AND OVER AND
OVER AGAIN
Repetition
Nathan Friedman
2011
Do Loops and Arrays
3
A table of temperature conversions
void main() cfw_
float celsius, fahrenheit;
To fully take advantage of the speed of a
com
2013
Introduction to C Programming
2
Recall Our First Program
#include <stdio.h>
INTRODUCTION TO C
void main () cfw_
/* This is my first C program */
Nathan Friedman
2013
printf ("Hello World\n");
2013
Introduction to C Programming
Concepts We Introduced
2013
Basic Expressions
2
Light from the Sun
How long (in minutes) does it take light to travel from the
sun to earth?
Light travels 9.46 x 1012 km a year
(2 + 2 = ?)
A year is 365 days, 5 hours, 48 minutes and 45.9747
seconds long
Nathan Friedman
2013
2013
As we have seen:
Every programming language must provide a
selection mechanism that allows us to control
whether or not a statement should be executed
This will depend on whether or not some
condition is satisfied (such as the discriminant
being po
06/11/2013
2013
From C to Fortran - Part 3
2
Parameter Passing Example
FROM C TO FORTRAN
PART 3
Nathan Friedman
2013
program testing
implicit none
integer : x, y, add
x = 13
y = 4
write (*,*) x, y
write (*,*) add(x,y)
write (*,*) x, y
end program
integer
10/25/2013
2011
From Fortran to C - The Basics
2
Our Goals
How are Fortran and C similar?
FORTRAN TO C
THE BASICS
What are the differences?
How can I use my knowledge of C to program in
Fortran?
Nathan Friedman
2013
2011
From Fortran to C - The Basics
ARRAYS AND
SUBPROGRAMS
Nathan Friedman
2013
2013
Arrays and Files
2
Arrays
Arrays can be defined in Fortran just as they can
in C
The concept is the same but there are a couple of
differences
The syntax is slightly different
The major idea to get used
Multidimensional
Arrays
NATHAN FRIEDMAN
201
Power Output (from Etter)
We want to study the power output of an electrical
plant over time
Given a file with the following structure
Each line represents the data acquired in a week
There are seven values on
8/21/2015
A First Look At C
Lets have a first look at C
We examine a simple program that instructs the computer to output a greeting (Hello World) to
the screen.
It is stored in a plain text file with a suffix of .c to indicate that the file contains a C
8/24/2015
Back to the roots of a quadratic
Lets have another look at our program for finding the roots of a quadratic
equation
Choices, Choices,
Choices
We used the classic formula that involved finding the square root of the
discriminant
What if the disc
8/24/2015
Light from the Sun
How long (in minutes) does it take light to travel from the sun to earth?
Assume the following:
1. Light travels 9.46 x 1012 km a year
(2 + 2 = ?)
2. A year is 365 days, 5 hours, 48 minutes and 45.9747 seconds long
3. The aver
COMP 208: Computers in Engineering
Winter 2016: Assignment 1
This assignment is due on January 26, 2016 at 11:59 PM. It must be submitted using
MyCourses.
The cutoff time is automated. Assignments submitted within the next hour will be
accepted but marked
COMP 208: Computers in Engineering
Winter, 2016
Assignment 2: Backwards and Forwards
Due Date
Assignment 2 is due on Thursday, February 11 at 23:59. The cutoff is automated and is
exactly at this time. Assignments submitted within the next hour will be co
ROOT FINDING
Friedman
2013
2013
Root Finding
2
Root Finding
Many applications involve finding the roots of a
function f(x).
That is, we want to find a value or values for x
such that f(x)=0
2013
Root Finding
3
Roots of a Quadratic
We have already seen a
Introduction to MATLAB
Fall 2013
Wenbo He
Part II: More on Matlab
Basics
M Files
Operations and Build-in functions
Plotting
Save, Load and Delete
Script
What is a script file or m file?
Simple text with a sequence of Matlab
commands
Why we use a sc
Introduction to MATLAB
Fall 2013
Wenbo He
Basics
MATLAB Environment
Getting Help
Variables
Vectors, Matrices, and Linear Algebra
What is Matlab?
Matrix Laboratory Package
High Level Language
Interactive Programming
Environment.
Matlab
High Level
Langua
06/11/2013
2013
Numerical Integration
2
Integration
NUMERICAL
INTEGRATION
Many applications require evaluating the integral
Nathan Friedman
2013
As we have seen, we may not even have an
2013
of a function
The integrals of many elementary functions
cann
Basics
Introduction to MATLAB
Flow Control
Loops
Fall 2013
What is Matlab?
Matrix Laboratory Package
High Level Language
Interactive Programming
Environment.
MATLAB Environment
Getting Help
Variables
Vectors, Matrices, and Linear Algebra
Script(.m fi
Recall Function Definitions
Declare function name, inputs, and
outputs
Introduction to MATLAB
Part 3
Syntax:
function [y1, ., yN] = myfun(x1, ., xM)
Inputs: x1,xM
Outputs: y1,yN
Save code in a text file with .m extension, and
name the file name match
Last Name _
First Name _
McGill ID _
Make sure the version number is marked on your scantron sheet.
This is Version 1
McGill University
COMP 208 - Computers in Engineering
Mid-Term Examination
Tuesday,March11,2014
6:00 8:00 P. M.
Faculty standard calculat
Last Name _
First Name _
McGill ID _
Make sure the version number is marked on your scantron sheet.
This is Version 1
McGill University
COMP 208 - Computers in Engineering
Mid-Term Examination
Tuesday,October22,2013
6:30 8:30 P. M.
Faculty standard calcul
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
cfw_
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int i = 0;
int j = 0;
int k = 0;
int l = 0;
int number = 100000;
loop*/
int input_number = 0;
/*variable
/*variable
/*variable
/*variable
%graphing ln 2 - converges
n = 1:100;
% # of terms in patial sum
[y,partial_sum] = natural_log (2,100);
% calling function
%the graphs are all combined as wanted in the instructions so code is at
%line 35 - 40
%part 3 - harmonic series evaluate
tol = 0.00