# Tutor profile: Cole B.

## Questions

### Subject: R Programming

How do I check if a number is prime in R?

R does not possess a native "prime number checker" function, so you must define one yourself. For this example, I will provide the simplest function I know of, which relies on trial division to determine primality. The following function "primeTest" returns TRUE if the number you wish to test, n, is prime (go ahead and give it a try). primeTest <- function(n) n == 2L || all(n %% 2:max(2,floor(sqrt(n))) != 0). Now, we could have easily defined the function as follows: primeTestV2 <- function(n) all(n %% 2:max(2,floor(sqrt(n))) != 0). This function just performs integer division on n by all numbers 2,3,..., max(2,floor(sqrt(n))) and, if none of them are zero (that is, no integer in our list evenly divides n), concludes that n is prime. What's wrong with this algorithm? You can check this yourself, but primeTestV2(2) returns FALSE, which is not true at all, as 2 is prime - its evenness being the reason why we must be particular! Thus, we must specifically check if the number we are testing is 2, hence the form of the original function.

### Subject: Basic Math

What is $3^4/3^2$?

We can evaluate this quotient in two ways. The first and most appealing solution is to evaluate the numerator and denominator separately and end with simple division. This method yields the following: $( \frac{3^4}{3^2} = \frac{81}{9} = 9.$) The second approach is to recall the following exponent law: $(\frac{x^a}{x^b} = x^{a-b}.$) With this in mind, our problem is solved as follows: $(\frac{3^4}{3^2} = 3^{4-2} = 3^2 = 9.$)

### Subject: Calculus

Compute $$\int_C \vec{F} \cdot \vec{T} ds$$ for (1) a semi-circle in the first and second quadrants with equation $$x^2 + y^2 = 4$$, and (2) a downward facing ellipse with equation $$z = 4-x^2$$.

(1) A simple parametrization is given by $$r(u) = \langle2\cos(u), 2\sin(u), 0\rangle$$ for $$0 \le u \le \pi$$. Calculating $$\vec{T}$$ gives $$\vec{r}'(t) =\ \langle-2\sin(u), 2\cos(u), 0\rangle$$. So, $(\int_0^\pi \langle2(\cos(u) + \sin(u)),0,0\rangle \cdot \langle-2\sin(u), 2\cos(u), 0\rangle \ du = \\ \int_0^\pi -4(\cos(u)\sin(u) + \sin^2(u))\ du = -2\pi$) (2) For this question, we've two separate parametrizations we can use: $$\vec{r} = \langle t,0,4-t^2\rangle$$ and $$\vec{r} = \langle 2\sin(t),0,4\cos(t)\rangle$$. Both parametrizations yield the same result, so we settle with the latter, with domain $$-\pi/2 \le t \le \pi/2$$. Calculating $$\vec{T}$$: $$\vec{r}' = \langle2\cos(t), 0, -4\sin(t)\rangle$$. For $$y=0$$, $$F(x,0,z) = \langle x, 0, z^2\rangle = \langle2\sin(t), 0, 16\cos^2(t)\rangle$$. Calculating the line integral yields: $(\int_{-\pi/2}^{\pi/2} \langle2\sin(t), 0, 16\cos^2(t)\rangle \cdot \langle2\cos(t), 0, -4\sin(t)\rangle \ dt = \\ \int_{-\pi/2}^{\pi/2} 4\cos(t)\sin(t) - 74\sin(t)\cos^2(t)\ dt = 0$)

## Contact tutor

needs and Cole will reply soon.