Answer the following questions by slicing a numpy array containing the given array. Each answer should be done using slicing and summing multiple copies of the array. Do not use for
loops or any other approach. See example answer. 4 Points each.
In [1]:
import numpy as np
x = np.array([1, 4, 7, 11, 34, -3, 5, 7, 5, 2, 3, 13])
###-------###
x[::2]
Out[1]:
Use the two matrices given to answer the following problems. Answer in Python.
$$ \mathbf{A} = \left[\begin{array}{lcr} 3 & 2 & -1\\ 6 & 4 & -2\\ 5 & 0 & 3\\ \end{array}\right] \quad \mathbf{B} = \left[\begin{array}{lcr} 2 & 3 & 2\\ 3 & -4 & -2\\ 4 & -1 & 1\\ \end{array}\right] $$Evaluate the following definite integrals using the quad
function and the lambda
keyword. You may only report your answer in Python and you should only print the integral area to 4 significant figures and nothing else. Do not define a function, use lambda
to define your integrands if necessary. 4 points each.
$ \int_0^{\pi / 4} \tan x\, dx $
$\int_{-2}^0 3x^3\, dx$
$\int_0^3 4x^2 - x \,dx$
$\int_{-2}^2 \sin x^2 \, dx$
Plot [4 points] & evaluate [4 points] the following definite integral. Report your answer to 4 significant figures.
$$ \int_0^3 f(x)\, dx, \quad f(x) = \; \left. \begin{array}{llr} x^2 & \textrm{if} & |x| < 2\\ 4 & \textrm{if} & x > 2 \\ x & \textrm{otherwise} & \\ \end{array}\right\} $$Evlaute the following integral. Report your answer to 4 significant figures.
$$ \int_0^{1}\int_{-2 x}^x \sin xy \,dy\, dx $$Use the given datasets to compute the requested quantities:
x = [-0.42,1.34,1.6,2.65,3.53,4.48,5.48,6.21,7.49,8.14,8.91,10.1]
y = [1.58,1.61,2.04,5.47,9.8,16.46,25.34,33.32,49.7,58.79,71.26,93.34]
Write a function which will compute a confidence interval given a sample and confidence level. Your function should optionally take in the population standard deviation. Your function should return a value, $y$, such that $\mu = \bar{x} \pm y$. Demonstrate it on 3 examples: (1) 10 samples with known population standard deviation, (2) 30 samples with unknonw population standard deviation, and (3) 5 samples with unknown population standard deviation. You must both define the function (+ document it) and show it on these 3 examples to receive full credit. The confidence level (90%, 95%, etc) should be adjustable.