SUNY Geneseo Department of Mathematics
Wednesday, March 1
Math 230 02
Spring 2017
Prof. Doug Baldwin
Eleni Panagiotou, faculty candidate
“Quantifying Entanglement in Physical Systems”
Thursday, March 2, 2:30 PM, Newton 203
Extra credit for writing a paragraph or so summarizing connections you make between the talk and your own interests.
Starting with homework 1 (but not lab 4), if you can demonstrate by the “complete by” date that there are no appointments left in the grading window, I’ll extend the deadline for you to the earliest date on which you can make an appointment.
Homework 1 deadline is still Monday for grading.
I’m out of town from Wednesday afternoon through the end of the week.
Friday class will (probably) be something with Nicole, but the details are still being worked out.
Section 11.1
Write a function of one argument that prints “this number is negative” if its argument is less than 0.
A useful new Matlab function: fprintf( message )
will print the string
message to the command window.
fprintf( 'Hello World\n' )
\n
pattern indicates that a new line of output starts>> fprintf( 'Hello World\n' )
Hello World
>> fprintf( 'Hello World' )
Hello World>> fprintf( 'Hello\nWorld\n' )
Hello
World
Reading ideas:
if expression
...
end
end
if the expression is trueif expression
...
else
...
end
if
and
else
if the expression is true, or execute the statements between
else
and end
if the expression is falseif expression1
...
elseif expression2
...
elseif ...
...
else
...
end
Using these ideas, we can write a function that does more than asked in the original problem. This function classifies its argument as negative, zero, or positive:
function [] = negative( x )
%NEGATIVE Identify whether x is negative, zero, or positive
% via a printed message
if ( x < 0 )
fprintf( 'This number is negative\n' )
elseif ( x == 0 )
fprintf( 'This number is 0\n' )
else
fprintf( 'This number is positive\n' )
end
end
Some of you discovered Matlab’s input
function, which is complementary
to fprintf
in that it allows a Matlab program to read something from the user.
You can use input
to write a script equivalent to the negative function
above (typically you don’t need input
in functions, since they can and
should receive their inputs via their arguments).
%% Ask user for a number and decide whether it’s positive, zero, or
% negative.
x = input( 'What is your favorite number? ' );
if ( x < 0 )
fprintf( 'This number is negative\n' )
elseif ( x == 0 )
fprintf( 'This number is 0\n' )
else
fprintf( 'This number is positive\n' )
end
More on if
Lab on if
Handout available Friday (or sooner via Canvas)