using MTH229
using Plots
gr()Plots.GRBackend()
Test 1 will be soon—March 12th.
The test will be on paper. You will have to write out all your answers and in some cases your Julia commands to receive full credit.
On the test you can use the computer and the internet, but you can not:
Here are some sample questions. Many of these are designed for immediate feedback. The actual test questions will definitely be different. The following should be helpful nonetheless.
using MTH229
using Plots
gr()Plots.GRBackend()
For the next several questions there is some math expression and a Julia expression. You are asked if the Julia code expresses the same calculation. Both are written as though \(a\) had some value assigned to it.
Math code:
\[ \sin(\cos(a)) \]
Julia code:
sin(cos(a))Does the Julia code do what the math formula expects?
Math code:
\[ 1 + \frac{1}{2} + \frac{1}{2\cdot 3} + \frac{1}{2 \cdot 3 \cdot 4} \]
Julia code:
1 + 1/2 + 1/2*3 + 1/2*3*4Does the Julia code do what the math formula expects?
Math code:
\[ \cos^2(a - \pi) \]
Julia code:
cos^2(a - pi)Does the Julia code do what the math formula expects?
Math code:
\[ \ln(\frac{1 - a}{a}) \]
Julia code:
ln( (1-a) / a)Does the Julia code do what the math formula expects?
Math code:
\[ 1 - \frac{1 -a^2}{1 + a^2} \]
Julia code:
(1 - (1 - a^2)) / (1 + a^2)Does the Julia code do what the math formula expects?
Math code:
\[ e^{-1/2\cdot(x-1)^2} \]
Julia code:
exp^(-1/2*(x-1)^2)Does the Julia code do what the math formula expects?
Which of these is actually a Julia function for some common mathematical function:
Suppose for specific \(a,b,\) and \(c\) values you were to solve for \(C\) (in radians) in
\[ a^2 + b^2 -2ab\cos(C) = c^2 \]
Does the following set of Julia commands compute this expression for the given values.
a, b, c = 3, 5, 6
cosC = (c^2 - (a^2 + b^2)) / (-2a*b)
acos(cosC)Suppose for specific \(R_t\) and \(R_1\) you have to solve for \(R_2\) from:
\[ \frac{1}{R_t} = \frac{1}{R_1} + \frac{1}{R_2} \]
Does the following set of Julia commands compute this expression for the given values.
R1, Rt = 10, 8
1 / (1/Rt - 1/R1)Is the above image funny or informative?
Write a Julia function to compute
\[ f(x) = x - \frac{x^3}{6} + \frac{x^5}{120} \]
Would this function work?
f(x) = x - x^3/6 + x^5/120
Use your function to identify which is greater \(f(2)\) or \(\sin(2)\)?
Write a Julia function to compute
\[ f(x) = x - \sin(x^2) \]
Would this function work?
f(x) = x - sin(x^2)
Which value is bigger \(f(1)\), \(f(2)\), or \(f(3)\)?
The piece-wise defined function \(f\) is given below:
\[ f(x) = \begin{cases} 2x + 3 & x < 1 \\ 5 & x \geq 1 \end{cases} \]
It can be entered into Julia using the ternary operator by:
f(x) = x < 1 ? 2x + 3 : 5
Using this function (type it in), which values is biggest?
Consider the function \(f(x) = x^x\) over the interval \([1/2, 2]\). The secant line between these points is defined by
f(x) = x^x
a, b = 1/2, 2
g(x) = f(b) + (f(b) - f(a))/(b-a) * (x - b)
At the value of \(x=1\) which is bigger?
You could also have used the secant(f,a,b) function to define g.
Consider the function \(f(x) = x^x\) over the interval \([1/2, 2]\). The tangent line to \(f(x)\) at \(x=1/2\) is given by
f(x) = x^x
tl = tangent(f, 1/2)At the value of \(x=1\) which is bigger?
For these questions, you are expected to read the values from the graph to 1 decimal point.
What is f(1)?
What value of x satisfies f(x)=2?
How many values of x satisfy f(x) = 3?
A secant line for a function \(f\) at \(a\) and \(b\) is the line going through the two points \((a,f(a))\) and \((b, f(b))\).
A tangent line for a function \(f\) at \(c\) is the line that best approximates \(f(x)\) at the point \(x=c\).
Consider this graph:
There are two lines. What is the dashed line?
What is the dash-dotted line?
If you identified a tangent line above, what is the value of \(c\) the line is tangent at?
Consider this graph of some function \(f(x)\) over \([-10,10]\):
To identify a zero of the function is impossible from the graph. Why?
To reframe the graph to try to identify a zero, which would you try?
Consider the following plot of \(f(x) = \cos(x)\) and \(g(x) = x/10\). Where do they intersect within \([0, \pi/2]?\)
f(x) = cos(x)
g(x) = x/10
plot(f, 0, pi/2)
plot!(g)Consider the following plot of \(f(x) = \ln(x)\) and its tangent line at \(x=1/2\).
f(x) = log(x)
plot(f, 1/10, 3/2)
plot!(tangent(f, 1/2))
plot!(zero)When does the tangent line cross the \(x\) axis?
The continuous function \(f(x) = x^2 e^{-x}\) has a maximum value over the interval \([0, 4]\). What is it. (The \(y\) value)
f(x) = x^2 * exp(-x)
plot(f, 0, 4)Two lines will intersect unless they are parallel. Consider this plot of \(f(x) = x^x\) over \([1/2, 2]\) along with its secant line over \([1/2, 2]\) and its tangent line at \(x=1\).
Where do they intersect? Use Inf if they do not.
f(x) = x^x
plot(f, 1/4, 4; ylims = (0, 4.1), legend=false)
plot!(secant(f, 1/2, 2))
plot!(tangent(f, 1))For these zero-finding problems, you can’t get enough accuracy for a correct answer just from reading the graph. You will need to use bisection or fzero.
Consider \(f(x) = x^5 - x - 1\). The interval \([a_0, b_0] = [1,2]\) is a bracketing interval. From the output of bisection(f, 1, 2), you should be able to see that \([a_1, b_1] = [1, 1.5]\). What is \([a_3, b_3]?\)
\(a_3\) is equal to?
\(b_3\) is equal to?
What “value” is the zero of \(f(x)\) in \([1,2]\) guaranteed by the intermediate value theorem?
(Value in quotes, as the actual mathematical answer is only approximated by this floating point value.)
Consider the following plot of some special function
plot(besselj0, -5, 5)
plot!(zero)Which of the following intervals is a bracketing interval for besselj0?
Using the bracketing interval and fzero (or bisection), find the zero.
For the function graphed above, which interval is not a bracketing interval? (A bracketing interval is \([a,b]\) where by the intermediate value theorem you know a zero is guaranteed to be between \(a\) and \(b\).
For the remaining questions you will be using bisection or fzero to solve one of three types of equations:
We solve this with bisection or fzero, but the last two pattern types require you to introduce an auxiliary function.
Consider the functions \(g(x) = \sin(x)\) and \(f(x) = \sin(x + \sin(x + \sin(x)))\). For each, \((2,3)\) is a bracketing interval. Does bisection find the exact same value or a different value when used?
Find a zero of the decreasing function f(x) = erfc(x) - 1/2.
(You might need to plot first to find a bracketing interval.)
The function \(f(x) = \tan^{-1}(x)\) is an increasing, continuous function. Using the intermediate value theorem, this says the function will take on any value in its range exactly once. That is for any \(y\) in \((-\pi/2, \pi/2)\) there is just one \(x\) with \(f(x) = y\). Find that \(x\) value when \(y = 1.23456\)
(It is even possible for this problem to use \((-\infty, \infty)\) for the bracketing interval when using fzero.)
The functions \(f(x) = xe^{-x^2}\) and \(g(x) = x + 1\) over the interval \([-2,2]\) intersect just once. Find the \(x\) value of the point of intersection using fzero.
f(x) = x * exp(-x^2)
g(x) = x + 1
plot(f, -2, 2)
plot!(g)The function f(x) = airyai(x) and the function g(x) = x/4 intersect once in the interval \([0,5]\). Where? (Use fzero.)