2010.1004 Lab1

4062 days ago by calcpage123

Lab1 MrG 2010.1004

#21) find a function such that the domain is any Real number, the range is 0<=y<=1 # student sample 1 translate sin(x) plot(sin(x)/2+.5,-10,10) 
       
# student sample 2 bell curve (y<>0) plot(e**(-(x**2)),-10,10) 
       
# student sample 3 logistic function (0<y<1) plot(1/(1+exp(-x)),-10,10) 
       
# student sample 4 odd powers of cos(x) plot((cos(x))**7/2+0.5,-10,10) 
       
# student sample 5 bell curve (y<>0) plot(1/(1+x**2),-10,10) 
       
# student sample 6 just like sample 2 (y<>0) plot(exp(-x**2),-10,10) 
       
# student sample 7 even powers of sin(x) plot(sin(x)**2,-10,10) 
       
# student sample 8 damped oscillation (y<>0) plot([(exp(-x/10)*cos(10*x)/2)+1/2,1/2],0,30) 
       
#22) {1,2,3,4,5,6} ==> {5,8,11,14,17,20} g(n)=3*n+2 g(1),g(2),g(3),g(4),g(5),g(6) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(5, 8, 11, 14, 17, 20\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(5, 8, 11, 14, 17, 20\right)
# more student sample code g(n)=n+(n+1)*2 for n in range(6): g(n+1) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}5
\newcommand{\Bold}[1]{\mathbf{#1}}8
\newcommand{\Bold}[1]{\mathbf{#1}}11
\newcommand{\Bold}[1]{\mathbf{#1}}14
\newcommand{\Bold}[1]{\mathbf{#1}}17
\newcommand{\Bold}[1]{\mathbf{#1}}20
\newcommand{\Bold}[1]{\mathbf{#1}}5
\newcommand{\Bold}[1]{\mathbf{#1}}8
\newcommand{\Bold}[1]{\mathbf{#1}}11
\newcommand{\Bold}[1]{\mathbf{#1}}14
\newcommand{\Bold}[1]{\mathbf{#1}}17
\newcommand{\Bold}[1]{\mathbf{#1}}20

23) prove that m + m+1 + m+2 + ... + n-2 + n-1 + n = [(n-m+1)*(n+m)]/2

23) given 0<=m<=n and m,n are integers

m + m+1 + m+2 + ... + n-2 + n-1 + n = S

n + n-1 + n-2 + ... + m+2 + m+1 + m = S

(m+n)+(m+n)+(m+n) + ... + (m+n)+(m+n)+(m+n) = 2S

(n-m+1)*(n+m) = 2S

S = [(n-m+1)*(n+m)]/2

#23) prove that m + m+1 + m+2 + ... + n-2 + n-1 + n = [(n-m+1)*(n+m)]/2 #23) given 0<=m<=n and m,n are integers def sum(m,n): return (n-m+1)*(n+m)/2 sum(2,8) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}35
\newcommand{\Bold}[1]{\mathbf{#1}}35
#24) use python code or pseudo code to calculate 2**n-1 without using exponentiation def mersene(n): x=n-1 a=2 while x>0: a=2*a x=x-1 return a-1 mersene(70) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}1180591620717411303423
\newcommand{\Bold}[1]{\mathbf{#1}}1180591620717411303423
# a bit cleaned up def mersene(n): p=1 while n>0: p=p*2 n=n-1 return p-1 mersene(70) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}1180591620717411303423
\newcommand{\Bold}[1]{\mathbf{#1}}1180591620717411303423
#25) use python code or pseudo code to calculate factorials def fact(n): m=1 f=1 while m<=n: f=f*m m=m+1 return f fact(6) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}720
\newcommand{\Bold}[1]{\mathbf{#1}}720
# check with SAGE factorial(6) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}720
\newcommand{\Bold}[1]{\mathbf{#1}}720
#26) use python code or pseudo code to calculate x**2 without exponentiation def sqr(x): return x*x sqr(-50) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}2500
\newcommand{\Bold}[1]{\mathbf{#1}}2500
#26) use python code or pseudo code to calculate x**2 without multiplication # only for positive x def sqr(x): n=x s=0 while n>0: s=s+x n=n-1 return s sqr(50) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}2500
\newcommand{\Bold}[1]{\mathbf{#1}}2500