# HW-3

## 2292 days ago by bigdata2016

Problem 1. Engineering Math

Evaluate

$\iint\limits_S y dS$

Where $S$ is the portion of the cylinder $x^2+y^2=k^2$ that lies between $z=a$ and $z=b$.

Solution: The parameterization of this cylinder

$\vec{r}(\theta, z)=(k\cos\theta, k\sin\theta, z)$ where $a\leq z\leq b$ and $0\leq\theta \leq 2\pi$

$\vec{r}_\theta(\theta, z)=\dfrac{d\vec{r}}{d\theta}=(-k\sin\theta, k\cos\theta, 0)$

$\vec{r}_z(\theta, z)=\dfrac{d\vec{r}}{dz}=(0, 0, 1)$

The cross product is

$\vec{r}_\theta\times \vec{r}_z=\left|{\begin{bmatrix} \vec{i}&\vec{j}&\vec{k}\\ -k\sin\theta & k\cos\theta & 0\\ 0 & 0 & 1 \end{bmatrix}}\right|=(-k\cos\theta, -k\sin\theta, 0)$

The norm of the cross product is $\|{\vec{r}_\theta\times \vec{r}_z}\|=k$. Then

$\iint\limits_S y dS=\iint\limits_D k\sin\theta\cdot kdA=\int\limits_0^{2\pi}\int\limits_a^b k^2\sin\theta \quad dzd\theta=0.$

var('u,z,k') assume(k>0) r(u,v)=(k*cos(u),k*sin(u),z) r1=diff(r,u) r2=diff(r,z) show(r1) show(r2)
 \newcommand{\Bold}[1]{\mathbf{#1}}\left( u, v \right) \ {\mapsto} \ \left(-k \sin\left(u\right),\,k \cos\left(u\right),\,0\right) \newcommand{\Bold}[1]{\mathbf{#1}}\left( u, v \right) \ {\mapsto} \ \left(0,\,0,\,1\right)
c=r1.cross_product(r2) d=c.norm() e=d.simplify_full() show (e)
 \newcommand{\Bold}[1]{\mathbf{#1}}\left( u, v \right) \ {\mapsto} \ \sqrt{{\left| \sin\left(u\right) \right|}^{2} + {\left| \cos\left(u\right) \right|}^{2}} k
var('a,b') A=integral(k*sin(u)*k,u,0,2*pi) B=integral(A,z,a,b) show (B)
 \newcommand{\Bold}[1]{\mathbf{#1}}0

Problem 2. Calculus.

@interact def graph(g=input_box('sin(x)+cos(2x)', label="$f(x)=$"), initial=input_box('1', label="$a =$"), initial1=input_box('0.01', label="$a-x_{0} =$")): f(x)=g # change this to whatever function you like df(x)=diff(f,x) # Sage will compute the derivative of f ddf(x)=diff(df,x); a=float(initial) h=float(initial1) value=f(a)+df(a)*h+ddf(a)*h^2 html('         <font color="blue">$f(x)=%s$</font>;    <font color="red">$f^{(1)}(x)=%s$</font>; <font color="red">$f^{(2)}(x)=%s$</font><br><br>'%(latex(g),latex(df(x)), latex(ddf(x)))) html(' <font color="blue">$f(%s)\\approx%s$</font> <br><br>'%(latex(a-h),value))

 $f(x)=$ $a =$ $a-x_{0} =$

## Click to the left again to hide and once more to show the dynamic interactive window

Problem 3. Linear Algebra.

QR factorization using Householder matrix

A=matrix(RDF, [[1,2,3,4,4],[1,1,2,2,3],[-1,-2,2,1,-3],[0,1,0,2,0],[3,4,-2,0,1]]) B=A H1=identity_matrix(A.nrows()) A1=A for i in range(0,A.nrows()-1): print "Step", i+1 x=A1.matrix_from_columns([0]) html('$A_%s=%s$ and $x=%s$' %(i,latex(A.round(3)), latex(x.n(digits=3))) ) print x1_=(-sgn(x[0,0])+((-1)^sgn(x[0,0])+1)/2)*sqrt((x.transpose()*x)[0,0]) u=matrix(RDF,x.nrows(),1) u[0,0]=sqrt((x1_-x[0,0])/(2*x1_)) for j in range(1,x.nrows()): u[j]=x[j,0]/(-2*u[0,0]*x1_) H=matrix(RDF,x.nrows(),x.nrows(),1)-2*u*u.transpose() k=identity_matrix(RDF,i) H=k.block_sum(H) H1=H*H1 A=H*A html(' $H_%s=%s$' %(i+1,latex(H.round(3))) ) A1=A.submatrix(i+1,i+1,A.nrows()-i-1,A.ncols()-i-1) print html(' $Q=%s$ and $R=%s$' %(latex(H1.round(3)),latex(A.round(3))) )
 Step 1 $A_0=\left(\begin{array}{rrrrr} 1.0 & 2.0 & 3.0 & 4.0 & 4.0 \\ 1.0 & 1.0 & 2.0 & 2.0 & 3.0 \\ -1.0 & -2.0 & 2.0 & 1.0 & -3.0 \\ 0.0 & 1.0 & 0.0 & 2.0 & 0.0 \\ 3.0 & 4.0 & -2.0 & 0.0 & 1.0 \end{array}\right)$ and $x=\left(\begin{array}{r} 1.00 \\ 1.00 \\ -1.00 \\ 0.000 \\ 3.00 \end{array}\right)$ $H_1=\left(\begin{array}{rrrrr} -0.289 & -0.289 & 0.289 & 0.0 & -0.866 \\ -0.289 & 0.935 & 0.065 & 0.0 & -0.194 \\ 0.289 & 0.065 & 0.935 & 0.0 & 0.194 \\ 0.0 & 0.0 & 0.0 & 1.0 & 0.0 \\ -0.866 & -0.194 & 0.194 & 0.0 & 0.418 \end{array}\right)$ Step 2 $A_1=\left(\begin{array}{rrrrr} -3.464 & -4.907 & 0.866 & -1.443 & -3.753 \\ -0.0 & -0.547 & 1.522 & 0.781 & 1.263 \\ 0.0 & -0.453 & 2.478 & 2.219 & -1.263 \\ 0.0 & 1.0 & 0.0 & 2.0 & 0.0 \\ -0.0 & -0.642 & -3.434 & -3.658 & -4.21 \end{array}\right)$ and $x=\left(\begin{array}{r} -0.547 \\ -0.453 \\ 1.00 \\ -0.642 \end{array}\right)$ $H_2=\left(\begin{array}{rrrrr} 1.0 & 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & -0.395 & -0.327 & 0.722 & -0.464 \\ 0.0 & -0.327 & 0.923 & 0.169 & -0.109 \\ 0.0 & 0.722 & 0.169 & 0.626 & 0.24 \\ 0.0 & -0.464 & -0.109 & 0.24 & 0.846 \end{array}\right)$ Step 3 $A_2=\left(\begin{array}{rrrrr} -3.464 & -4.907 & 0.866 & -1.443 & -3.753 \\ 0.0 & 1.384 & 0.181 & 2.107 & 1.866 \\ 0.0 & 0.0 & 2.164 & 2.53 & -1.122 \\ -0.0 & 0.0 & 0.694 & 1.314 & -0.312 \\ -0.0 & -0.0 & -3.88 & -3.217 & -4.01 \end{array}\right)$ and $x=\left(\begin{array}{r} 2.16 \\ 0.694 \\ -3.88 \end{array}\right)$ $H_3=\left(\begin{array}{rrrrr} 1.0 & 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 1.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & -0.481 & -0.154 & 0.863 \\ 0.0 & 0.0 & -0.154 & 0.984 & 0.09 \\ 0.0 & 0.0 & 0.863 & 0.09 & 0.497 \end{array}\right)$ Step 4 $A_3=\left(\begin{array}{rrrrr} -3.464 & -4.907 & 0.866 & -1.443 & -3.753 \\ 0.0 & 1.384 & 0.181 & 2.107 & 1.866 \\ -0.0 & -0.0 & -4.496 & -4.197 & -2.872 \\ -0.0 & 0.0 & -0.0 & 0.612 & -0.494 \\ -0.0 & -0.0 & 0.0 & 0.701 & -2.99 \end{array}\right)$ and $x=\left(\begin{array}{r} 0.612 \\ 0.701 \end{array}\right)$ $H_4=\left(\begin{array}{rrrrr} 1.0 & 0.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 1.0 & 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 1.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 & -0.658 & -0.753 \\ 0.0 & 0.0 & 0.0 & -0.753 & 0.658 \end{array}\right)$ $Q=\left(\begin{array}{rrrrr} -0.289 & -0.289 & 0.289 & 0.0 & -0.866 \\ 0.421 & -0.301 & -0.421 & 0.722 & -0.181 \\ -0.706 & -0.512 & -0.406 & 0.029 & 0.271 \\ 0.286 & -0.072 & -0.645 & -0.645 & -0.286 \\ 0.399 & -0.747 & 0.399 & -0.249 & 0.249 \end{array}\right)$ and $R=\left(\begin{array}{rrrrr} -3.464 & -4.907 & 0.866 & -1.443 & -3.753 \\ 0.0 & 1.384 & 0.181 & 2.107 & 1.866 \\ -0.0 & -0.0 & -4.496 & -4.197 & -2.872 \\ 0.0 & -0.0 & -0.0 & -0.931 & 2.578 \\ 0.0 & -0.0 & 0.0 & 0.0 & -1.594 \end{array}\right)$ Step 1 and Step 2 and Step 3 and Step 4 and and 

html('$Q\cdot R=%s$' %( latex((H1.transpose()*A).round(3)) ) ) print html( '$Q^T\cdot Q=%s$'%( latex((H1.transpose()*H1).round(3) ) ))