Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 53
2 + 2
4

Q2.

cos?
File: /usr/local/sage/sage-6.3.beta6/local/lib/python2.7/site-packages/sage/functions/trig.py Docstring: The cosine function. EXAMPLES: sage: cos(pi) -1 sage: cos(x).subs(x==pi) -1 sage: cos(2).n(100) -0.41614683654714238699756822950 sage: loads(dumps(cos)) cos We can prevent evaluation using the "hold" parameter: sage: cos(0,hold=True) cos(0) To then evaluate again, we currently must use Maxima via "sage.symbolic.expression.Expression.simplify()": sage: a = cos(0,hold=True); a.simplify() 1 TESTS: sage: conjugate(cos(x)) cos(conjugate(x)) sage: cos(complex(1,1)) # rel tol 1e-15 (0.8337300251311491-0.9888977057628651j)
sum?
File: /usr/local/sage/sage-6.3.beta6/local/lib/python2.7/site-packages/sage/misc/functional.py Docstring: Returns the symbolic sum sum_{v = a}^b expression with respect to the variable v with endpoints a and b. INPUT: * "expression" - a symbolic expression * "v" - a variable or variable name * "a" - lower endpoint of the sum * "b" - upper endpoint of the sum * "algorithm" - (default: 'maxima') one of - 'maxima' - use Maxima (the default) - 'maple' - (optional) use Maple - 'mathematica' - (optional) use Mathematica EXAMPLES: sage: k, n = var('k,n') sage: sum(k, k, 1, n).factor() 1/2*(n + 1)*n sage: sum(1/k^4, k, 1, oo) 1/90*pi^4 sage: sum(1/k^5, k, 1, oo) zeta(5) Warning: This function only works with symbolic expressions. To sum any other objects like list elements or function return values, please use python summation, see http://docs.python.org/library/functions.html#sumIn particular, this does not work: sage: n = var('n') sage: list=[1,2,3,4,5] sage: sum(list[n],n,0,3) Traceback (most recent call last): ... TypeError: unable to convert x (=n) to an integer Use python "sum()" instead: sage: sum(list[n] for n in range(4)) 10 Also, only a limited number of functions are recognized in symbolic sums: sage: sum(valuation(n,2),n,1,5) Traceback (most recent call last): ... AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'valuation' Again, use python "sum()": sage: sum(valuation(n+1,2) for n in range(5)) 3 (now back to the Sage "sum" examples) A well known binomial identity: sage: sum(binomial(n,k), k, 0, n) 2^n The binomial theorem: sage: x, y = var('x, y') sage: sum(binomial(n,k) * x^k * y^(n-k), k, 0, n) (x + y)^n sage: sum(k * binomial(n, k), k, 1, n) 2^(n - 1)*n sage: sum((-1)^k*binomial(n,k), k, 0, n) 0 sage: sum(2^(-k)/(k*(k+1)), k, 1, oo) -log(2) + 1 Another binomial identity (trac #7952): sage: t,k,i = var('t,k,i') sage: sum(binomial(i+t,t),i,0,k) binomial(k + t + 1, t + 1) Summing a hypergeometric term: sage: sum(binomial(n, k) * factorial(k) / factorial(n+1+k), k, 0, n) 1/2*sqrt(pi)/factorial(n + 1/2) We check a well known identity: sage: bool(sum(k^3, k, 1, n) == sum(k, k, 1, n)^2) True A geometric sum: sage: a, q = var('a, q') sage: sum(a*q^k, k, 0, n) (a*q^(n + 1) - a)/(q - 1) The geometric series: sage: assume(abs(q) < 1) sage: sum(a*q^k, k, 0, oo) -a/(q - 1) A divergent geometric series. Don't forget to forget your assumptions: sage: forget() sage: assume(q > 1) sage: sum(a*q^k, k, 0, oo) Traceback (most recent call last): ... ValueError: Sum is divergent. This summation only Mathematica can perform: sage: sum(1/(1+k^2), k, -oo, oo, algorithm = 'mathematica') # optional - mathematica pi*coth(pi) Use Maple as a backend for summation: sage: sum(binomial(n,k)*x^k, k, 0, n, algorithm = 'maple') # optional - maple (x + 1)^n Python ints should work as limits of summation (trac #9393): sage: sum(x, x, 1r, 5r) 15 Note: 1. Sage can currently only understand a subset of the output of Maxima, Maple and Mathematica, so even if the chosen backend can perform the summation the result might not be convertable into a Sage expression.

Q3.

cos(3)
cos(3)
cos(3.)
-0.989992496600445
sqrt(4)
2
sqrt(8)
2*sqrt(2)
sqrt(8.)
2.82842712474619
I ** 2
-1
sqrt(-53.)
7.28010988928052*I

Q4.

i = var('i') # Students won't know that they need to do this. expression = sum(1 / sqrt(i), i, 1, 5) print expression
1/60*(((3*sqrt(2) + 2)*sqrt(3) + 2*sqrt(2))*sqrt(5) + 2*sqrt(2)*sqrt(3))*sqrt(2)*sqrt(3)*sqrt(5)
factor(expression)
1/60*(3*sqrt(2)*sqrt(3)*sqrt(5) + 2*sqrt(2)*sqrt(3) + 2*sqrt(2)*sqrt(5) + 2*sqrt(3)*sqrt(5))*sqrt(2)*sqrt(3)*sqrt(5)
simplify(expression)
1/60*(((3*sqrt(2) + 2)*sqrt(3) + 2*sqrt(2))*sqrt(5) + 2*sqrt(2)*sqrt(3))*sqrt(2)*sqrt(3)*sqrt(5)
expand(expression)
1/2*sqrt(2) + 1/3*sqrt(3) + 1/5*sqrt(5) + 3/2

Q5.

factor(234398)
2 * 233 * 503
f = 234398.factor() len(f)
3
nbroffactors = [] n = 1 while n < 1000: # Student might try a `for n in range` approach but this gives python int type objects which do not have a factor method. nbroffactors.append(len(n.factor())) n += 1 print mean(nbroffactors)
236/111

Q6.

k = var('k') k = 3 while k < 100: # This is one approach of doing this that makes nice use of the string substitution below but there are many other ways. print "For k =%s, k ^ 2 - 79 * k + 1601 = %s is prime: %s" % (k, k^2 - 79 * k +1601, (k^2 - 79 * k +1601).is_prime()) k += 1
For k =3, k ^ 2 - 79 * k + 1601 = 1373 is prime: True For k =4, k ^ 2 - 79 * k + 1601 = 1301 is prime: True For k =5, k ^ 2 - 79 * k + 1601 = 1231 is prime: True For k =6, k ^ 2 - 79 * k + 1601 = 1163 is prime: True For k =7, k ^ 2 - 79 * k + 1601 = 1097 is prime: True For k =8, k ^ 2 - 79 * k + 1601 = 1033 is prime: True For k =9, k ^ 2 - 79 * k + 1601 = 971 is prime: True For k =10, k ^ 2 - 79 * k + 1601 = 911 is prime: True For k =11, k ^ 2 - 79 * k + 1601 = 853 is prime: True For k =12, k ^ 2 - 79 * k + 1601 = 797 is prime: True For k =13, k ^ 2 - 79 * k + 1601 = 743 is prime: True For k =14, k ^ 2 - 79 * k + 1601 = 691 is prime: True For k =15, k ^ 2 - 79 * k + 1601 = 641 is prime: True For k =16, k ^ 2 - 79 * k + 1601 = 593 is prime: True For k =17, k ^ 2 - 79 * k + 1601 = 547 is prime: True For k =18, k ^ 2 - 79 * k + 1601 = 503 is prime: True For k =19, k ^ 2 - 79 * k + 1601 = 461 is prime: True For k =20, k ^ 2 - 79 * k + 1601 = 421 is prime: True For k =21, k ^ 2 - 79 * k + 1601 = 383 is prime: True For k =22, k ^ 2 - 79 * k + 1601 = 347 is prime: True For k =23, k ^ 2 - 79 * k + 1601 = 313 is prime: True For k =24, k ^ 2 - 79 * k + 1601 = 281 is prime: True For k =25, k ^ 2 - 79 * k + 1601 = 251 is prime: True For k =26, k ^ 2 - 79 * k + 1601 = 223 is prime: True For k =27, k ^ 2 - 79 * k + 1601 = 197 is prime: True For k =28, k ^ 2 - 79 * k + 1601 = 173 is prime: True For k =29, k ^ 2 - 79 * k + 1601 = 151 is prime: True For k =30, k ^ 2 - 79 * k + 1601 = 131 is prime: True For k =31, k ^ 2 - 79 * k + 1601 = 113 is prime: True For k =32, k ^ 2 - 79 * k + 1601 = 97 is prime: True For k =33, k ^ 2 - 79 * k + 1601 = 83 is prime: True For k =34, k ^ 2 - 79 * k + 1601 = 71 is prime: True For k =35, k ^ 2 - 79 * k + 1601 = 61 is prime: True For k =36, k ^ 2 - 79 * k + 1601 = 53 is prime: True For k =37, k ^ 2 - 79 * k + 1601 = 47 is prime: True For k =38, k ^ 2 - 79 * k + 1601 = 43 is prime: True For k =39, k ^ 2 - 79 * k + 1601 = 41 is prime: True For k =40, k ^ 2 - 79 * k + 1601 = 41 is prime: True For k =41, k ^ 2 - 79 * k + 1601 = 43 is prime: True For k =42, k ^ 2 - 79 * k + 1601 = 47 is prime: True For k =43, k ^ 2 - 79 * k + 1601 = 53 is prime: True For k =44, k ^ 2 - 79 * k + 1601 = 61 is prime: True For k =45, k ^ 2 - 79 * k + 1601 = 71 is prime: True For k =46, k ^ 2 - 79 * k + 1601 = 83 is prime: True For k =47, k ^ 2 - 79 * k + 1601 = 97 is prime: True For k =48, k ^ 2 - 79 * k + 1601 = 113 is prime: True For k =49, k ^ 2 - 79 * k + 1601 = 131 is prime: True For k =50, k ^ 2 - 79 * k + 1601 = 151 is prime: True For k =51, k ^ 2 - 79 * k + 1601 = 173 is prime: True For k =52, k ^ 2 - 79 * k + 1601 = 197 is prime: True For k =53, k ^ 2 - 79 * k + 1601 = 223 is prime: True For k =54, k ^ 2 - 79 * k + 1601 = 251 is prime: True For k =55, k ^ 2 - 79 * k + 1601 = 281 is prime: True For k =56, k ^ 2 - 79 * k + 1601 = 313 is prime: True For k =57, k ^ 2 - 79 * k + 1601 = 347 is prime: True For k =58, k ^ 2 - 79 * k + 1601 = 383 is prime: True For k =59, k ^ 2 - 79 * k + 1601 = 421 is prime: True For k =60, k ^ 2 - 79 * k + 1601 = 461 is prime: True For k =61, k ^ 2 - 79 * k + 1601 = 503 is prime: True For k =62, k ^ 2 - 79 * k + 1601 = 547 is prime: True For k =63, k ^ 2 - 79 * k + 1601 = 593 is prime: True For k =64, k ^ 2 - 79 * k + 1601 = 641 is prime: True For k =65, k ^ 2 - 79 * k + 1601 = 691 is prime: True For k =66, k ^ 2 - 79 * k + 1601 = 743 is prime: True For k =67, k ^ 2 - 79 * k + 1601 = 797 is prime: True For k =68, k ^ 2 - 79 * k + 1601 = 853 is prime: True For k =69, k ^ 2 - 79 * k + 1601 = 911 is prime: True For k =70, k ^ 2 - 79 * k + 1601 = 971 is prime: True For k =71, k ^ 2 - 79 * k + 1601 = 1033 is prime: True For k =72, k ^ 2 - 79 * k + 1601 = 1097 is prime: True For k =73, k ^ 2 - 79 * k + 1601 = 1163 is prime: True For k =74, k ^ 2 - 79 * k + 1601 = 1231 is prime: True For k =75, k ^ 2 - 79 * k + 1601 = 1301 is prime: True For k =76, k ^ 2 - 79 * k + 1601 = 1373 is prime: True For k =77, k ^ 2 - 79 * k + 1601 = 1447 is prime: True For k =78, k ^ 2 - 79 * k + 1601 = 1523 is prime: True For k =79, k ^ 2 - 79 * k + 1601 = 1601 is prime: True For k =80, k ^ 2 - 79 * k + 1601 = 1681 is prime: False For k =81, k ^ 2 - 79 * k + 1601 = 1763 is prime: False For k =82, k ^ 2 - 79 * k + 1601 = 1847 is prime: True For k =83, k ^ 2 - 79 * k + 1601 = 1933 is prime: True For k =84, k ^ 2 - 79 * k + 1601 = 2021 is prime: False For k =85, k ^ 2 - 79 * k + 1601 = 2111 is prime: True For k =86, k ^ 2 - 79 * k + 1601 = 2203 is prime: True For k =87, k ^ 2 - 79 * k + 1601 = 2297 is prime: True For k =88, k ^ 2 - 79 * k + 1601 = 2393 is prime: True For k =89, k ^ 2 - 79 * k + 1601 = 2491 is prime: False For k =90, k ^ 2 - 79 * k + 1601 = 2591 is prime: True For k =91, k ^ 2 - 79 * k + 1601 = 2693 is prime: True For k =92, k ^ 2 - 79 * k + 1601 = 2797 is prime: True For k =93, k ^ 2 - 79 * k + 1601 = 2903 is prime: True For k =94, k ^ 2 - 79 * k + 1601 = 3011 is prime: True For k =95, k ^ 2 - 79 * k + 1601 = 3121 is prime: True For k =96, k ^ 2 - 79 * k + 1601 = 3233 is prime: False For k =97, k ^ 2 - 79 * k + 1601 = 3347 is prime: True For k =98, k ^ 2 - 79 * k + 1601 = 3463 is prime: True For k =99, k ^ 2 - 79 * k + 1601 = 3581 is prime: True

Q7.

y = var('y') myexp = x ^ 2 - 5 * x ^ 2 + 12 * x * y - 9 * y ^ 2 myexp.factor()
-(2*x - 3*y)^2

Q8.

f(x) = x^3 + pi*x^2 - 23/2*x^2 - 23/2*pi*x + 15*x+ 15*pi plot(f, -15, 15)
f.roots() # If students don't understand the output invite them to try `f.roots?`
[(-pi, 1), (3/2, 1), (10, 1)]
f.factor()
x |--> 1/2*(pi + x)*(2*x - 3)*(x - 10)
solve(f(x) == 0, x)
[x == -pi, x == (3/2), x == 10]

Q9.

solve(x^2 == -1, x)
[x == -I, x == I]
a = var('a') solve(x^2 - 53 * x + 2 * a == 0, x)
[x == -1/2*sqrt(-8*a + 2809) + 53/2, x == 1/2*sqrt(-8*a + 2809) + 53/2]
solve(sin(x) == x - 1, x) # This won't work as `solve` finds analytical solutions to equations plot(sin(x) - x + 1, -10, 10) # Invite students to plot this to attempt to find a root, once they have done this encourage them to look at `find_root?`
[x == sin(x) + 1]
find_root(sin(x) - x + 1, 0, 5)
1.934563210752024
solve(x^5 + sin(x) - 2 * x == .5 ,x) # Again no result can be obtained plot(x^5 + sin(x) - 2 * x - .5, x, -5, 5)
[0 == 2*x^5 - 4*x + 2*sin(x) - 1]
find_root(x^5 + sin(x) - 2 * x - .5, -2, 2)
1.131990740991698
y, z = var('y', 'z') solve([x + y == z, 3*x - y == 0, y + z ==1], [x, y, z])
[[x == (1/7), y == (3/7), z == (4/7)]]