Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168730
Image: ubuntu2004

Tutorial 19 August

Here are some examples of plotting functions:

var('x') f(x) = log(x) plot(f(x),(0,10)) # plot f(x) over x in [0,10]
g(x)=x^2 # Combining two plots with "+" plot(f(x),(0,5)) + plot(g(x),(0,5),color="red")

Problem 1

Use plotting of the functions f(x)=x2+x+1f(x)=x^2+x+1 and g(x)=(logx)10g(x)=(\log x)^{10} to find out roughly for which x>3x>3 the function ff becomes larger than gg.

Problem 2

The following is from Question 4 of the final exam of MTH110 last year (now we do this in Python):

The Goldbach Conjecture asserts that every even integer greater than 2 can be written as the sum of two primes.

a) Write and test a Python function PrimeSum(n) which returns true if n is the sum of two odd primes and returns false otherwise. You can assume that n is a positive integer.

Hints: Use a for-loop with x running from 3 to n-3 and test if x and n-x are both primes. The built-in function is_prime(x) can be used to test if x is prime.

b) Write and test Python function Goldbach(a,b) which returns true if the Goldbach Conjecture is correct for all even n with 2a<=n<=2b and false otherwise.