using MTH229
using Plots
plotly()
Plots.PlotlyBackend()
Test 1 will be soon – October 10th!
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.
As in class, we use the following two packages and ask for the Plotly
backend:
using MTH229
using Plots
plotly()
Plots.PlotlyBackend()
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*4
Does the Julia
code do what the math formula expects?
Math code:
\[ \cos^2(a - \pi) \]
Julia code:
^2(a - pi) cos
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:
\[ \frac{1}{2a} \]
Julia code:
1 / 2a
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
\[ a^2 + b^2 -2ab\cos(C) = c^2 \]
Does the following set of Julia
commands compute this expression for the given values.
= 3, 5, 6
a, b, c = (c^2 - (a^2 + b^2)) / (-2a*b)
cosC 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.
= 10, 8
R1, Rt 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} \]
Use your formula to identify which is greater \(f(2)\) or \(\sin(2)\)?
Write a Julia
function to compute
\[ 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
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?
Consider the function \(f(x) = x^x\) over the interval \([1/2, 2]\). The tangent line at \(x=1/2\) is given by
f(x) = x^x
g(x) = tangent(f, 1/2)(x)
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.
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, 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?
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?
a###############################################################b
a###############################b................................
a###############b................................................
........a#######b................................................
........a###b....................................................
........a#b......................................................
.........ab......................................................
⋮⋮
a###############################################################b
a###############################b................................
a###############b................................................
........a#######b................................................
........a###b....................................................
........a#b......................................................
.........ab......................................................
⋮⋮
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
, find the zero.
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
.)