














































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A lecture note from mat 305: mathematical computing at the university of southern mississippi, fall 2009. It covers decision making in sage, including boolean statements, piecewise functions, and characterizing concavity. The lecture includes pseudocode examples and sage code implementation.
Typology: Study notes
1 / 54
This page cannot be seen from the preview
Don't miss anything!
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
Lecture 7: Decision-making in Sage
John Perry
University of Southern Mississippi
Fall 2009
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
1 Decision-making
2 Boolean statements
3 Having said all that...
4 Summary
You should be in worksheet mode to repeat the examples.
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
A function may have to act in different ways, depending on the arguments.
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
A function may have to act in different ways, depending on the arguments.
Piecewise functions:
f (x) =
f 1 (x) , x ∈
a 0 , a 1
f 2 (x)^ , x ∈
a 1 , a 2
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
if (condition): if-statement if-statement
... non-if statement
where
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
sage: f = cos(x) sage: ddf = diff(f,2) sage: if (ddf(3pi/4) > 0): print 'concave up at', 3pi/ concave up at 3/4*pi
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
if (condition1): if-statement
... elif (condition2): elif1-statement ... elif (condition3): elif2-statement ... ... else: else-statement ... non-if statement
where
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
if condition if-statement
... else if condition elseif1-statement ... else if condition elseif2-statement ... ... else condition else-statement ...
Notice:
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
Write a Sage function that tests whether a function f is concave up or down at a given point. Have it return the string ’concave up’, ’concave down’, or ’neither’.
Different choices =⇒ need to make a decision! =⇒ if
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
Write a Sage function that tests whether a function f is concave up or down at a given point. Have it return the string ’concave up’, ’concave down’, or ’neither’.
Different choices =⇒ need to make a decision! =⇒ if
Start with pseudocode.
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
algorithm check_concavity inputs a ∈ R f (x), a twice-differentiable function at x = a outputs
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
algorithm check_concavity inputs a ∈ R f (x), a twice-differentiable function at x = a outputs ’concave up’ if f is concave up at x = a ’concave down’ if f is concave down at x = a ’neither’ otherwise do
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
sage: def check_concavity(a, f, x): ddf = diff(f, x, 2) if (ddf(x=a) > 0): return 'concave up' elif (ddf(x=a) < 0): return 'concave down' else: return 'neither'
Mathematical Computing John Perry
Decision- making Boolean statements Having said all that... Summary
sage: def check_concavity(a, f, x): ddf = diff(f, x, 2) if (ddf(x=a) > 0): return 'concave up' elif (ddf(x=a) < 0): return 'concave down' else: return 'neither' sage: check_concavity(3*pi/4, cos(x), x) 'concave up' sage: check_concavity(pi/4, cos(x), x) 'concave down'