using MTH229
using Plots
gr();Review for test 1 in MTH229
Sorry, this is a review for a test which allows the use of a computer. It might still prove helpful, but is not so representative.
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.
Expressions
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.
Question
Math code:
\[ \sin(\cos(a)) \]
Julia code:
sin(cos(a))Does the Julia code do what the math formula expects?
Question
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?
Question
Math code:
\[ \cos^2(a - \pi) \]
Julia code:
cos^2(a - pi)Does the Julia code do what the math formula expects?
Question
Math code:
\[ \ln(\frac{1 - a}{a}) \]
Julia code:
ln( (1-a) / a)Does the Julia code do what the math formula expects?
Question
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?
Question
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?
Question
Which of these is actually a Julia function for some common mathematical function:
Question
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)Question
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)Question
Is the above image funny or informative?
Functions
Question
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)\)?
Question
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)\)?
Question
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?
Question
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.
Question
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?
Plots
For these questions, you are expected to read the values from the graph to 1 decimal point.
Question
What is f(1)?
What value of x satisfies f(x)=2?
How many values of x satisfy f(x) = 3?
Question
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?
Question
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?
Question
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)Question
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?
Question
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)Question
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))Finding zeros
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.
Question
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.)
Question
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.
Question
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\).
Note
For the remaining questions you will be using bisection or fzero to solve one of three types of equations:
- \(f(x) = 0\)
- \(f(x) = c\)
- \(f(x) = g(x)\)
We solve this with bisection or fzero, but the last two pattern types require you to introduce an auxiliary function.
Question
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?
Question
Find a zero of the decreasing function f(x) = erfc(x) - 1/2.
(You might need to plot first to find a bracketing interval.)
Question
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.)
Question
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)Question
The function f(x) = airyai(x) and the function g(x) = x/4 intersect once in the interval \([0,5]\). Where? (Use fzero.)