Name:_
Student #:_
York University
Department of Electrical Engineering & Computer Science
Lassonde School of Engineering
EECS 1541: Introduction to Computing for the Physical Sciences
Test 1 (Solutio
Name:_
Student #:_
York University
Department of Electrical Engineering & Computer Science
Lassonde School of Engineering
EECS 1541: Introduction to Computing for the Physical Sciences
Test 2 (Solutio
Ordinary differential equations
1
"Simple" pendulum
the simple pendulum is a
standard topic in most
introductory physics courses
the tangential component
of the net force acting on the
pendulum is
=
Numerical integration
1
Numerical integration
numerical integration attempts to estimate the value
of a definite integral without solving for the indefinite
integral; i.e.,
=
estimate the value of
2/5/15 7:13 PM
C:\Us.\1541_test1_assignment1_solutions.m
% CH. 3 quesitons from the textbook,
% solutions for #5,6,7,10,12,24,29,30,31,37
% #5.
x = input('Enter a real number: ');
fprintf('The number
Ordinary differential equations
1
Example problem
consider the no-drag projectile motion problem
0 initial velocity
0 , 0
2
initial position
Example problem
the solution is known to all physics studen
% Ch. 5 exercises (5, 7, 13, 18, 23, 28, 29, 30, 36, 40)
% Question 5
x = input('Enter an interger n: ');
for index = 1:x
disp('I love this stuff!');
end
% Question 7
function [y] = sumsteps2(x)
total
% Ch. 4 exercises (6, 7, 8, 10, 12, 13, 18, 22) %
% Question 6
a = input('Enter the value of "a":');
b = input('Enter the value of "b":');
if a =0
disp('Error! "a" cannot be equal to zero');
else
y =
1
Textbook exercises
The textbook has many programming exercises that would make good test questions:
Chapter 1 29, 31, 32, 33, 34
Chapter 2 6, 7, 8, 9, 10, 13, 14, 15, 24, 25, 26, 27, 33, 34, 40, 43,
Course Description
This course introduces students to computer-based problem solving techniques that can be used to approach
problems in the physical sciences, such as answering questions that require
Representing numbers
and Basic MATLAB
1
Representing numbers
numbers used by computers do not behave the same as
numbers used in mathematics
e.g., try the following in MATLAB:
help intmax
x = intmax;
You have 2 hours to complete this test.
There are 5 multi-part questions in this test. Create a script named test1.m to answer the questions.
For each part of each question, create a new cell (section
Logicals
1
Logicals
a logical expression is an expression that evaluates to
either true or false
a logical variable is a variable whose value is either true
or false
logical variables are usually call
% Lab 2 Sinusoidal waves
% This lab uses MATLAB to explore sinusoidal waves.
% Amplitude
% Plot three sinusoidal waves each having a different amplitude
% for time t from -3 seconds to 3 seconds in st
Logical indexing
you can use a logical array to perform indexing on
another array
MATLAB extracts the array elements corresponding to the
nonzero values in the logical array
1
the output is always in
Vectors and Matrices II
1
Matrices
a maxtrix is a 2-dimensional array where the size of the
dimensions is usually larger than 1
2x3
2
5x6
Creating matrices
a matrix of size m x n can be created by ent
Numerical differentiation
1
Announcement
there is a script and some functions available for this
lecture on the course web site
2
Numerical differentiation
numerical differentiation attempts to estima
Matrix operations
Scripts
1
Matrix transpose
if A is an m x n matrix then the transpose of A is an
n x m matrix where the row vectors of A are written as
column vectors
2
> u = [1 2 3];
> v = u'
v =
1
Scripts
1
MATLAB Scripts
a script is text file containing a sequence of MATLAB
commands
each command usually occurs on a separate line of the file
MATLAB can run the commands in a script by reading
th
Computing for the Physical
Sciences
CSE1541M
1
Who Am I?
Dr. Burton Ma
office
Lassonde 2046
hours : see syllabus on course web page
email
2
[email protected]
Course Format
everything you need to kno
Random variables
1
Note
there is no chapter in the textbook that corresponds to
this topic
2
Computing random numbers
the ability to quickly generate random numbers has
many very useful applications
M
Basic statistics (continued)
1
Interquartile range
like the mean, the standard deviation and variance are
sensitive to erroneous measurements
the interquartile range is a more robust measure of
disper
User-defined functions
1
Recall the script example from Day 5
an undamped spring-mass system is an example of a
simple harmonic oscillator
the position of the mass is given by
= sin
2
2
3
User-define
You have 2 hours to complete this test.
There are 5 multi-part questions in this test. Create a script named test1.m to answer the questions.
For each part of each question, create a new cell (section
Basic MATLAB continued;
Using functions
1
Variable names
valid variable
names
x
$
does not begin with a letter
$ is not allowed in variable names
x6
6x
does not begin with a letter
lastValue
if
if