



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solution to problem 2 of homework set 4 in a college-level calculus course. It explains how to compute the derivatives of the tangent function using the maclaurin series and compares it with the arc-tangent function. The document also includes sample diaries from running the matlab code for both methods.
Typology: Assignments
1 / 5
This page cannot be seen from the preview
Don't miss anything!




tan(x) = x +
x^3 3
2 x^5 15
17 x^7 315
62 x^9 2835
We can use this procedure to compute (with some effort and pain) all the derivatives to some order. For example, usingthe expression above the first five non-zero coefficients in the power series are
c = [
These can be used to compute the partial sum through the fifth non-zero term. With additional work we can extend this to more terms. A Matlab code that uses this approach is available as hw 4 2a.m. We should be aware that power series typically have a finite radius of convergence - this means there is a finite value r such that the sequence of partial sums converges iff |x| < r. For the tangent the radius of convergence is |x| < π/4. Here is a sample diary from runningthis code:
hw_4_2a Supply an argument (| x |<= pi/4) for the tan function :. Supply a tolerance (positive):. After 4 termsthe Maclaurin sum is0.. The relative error is: 3.46393970e- diary off
As an alternative, we can use the Maple symbollic toolbox and the diff command to form the symbollic deivative of tan(x). Note that Matlab uses an overloading feature to permit the use of the same command (here diff) to perform different functions. Earlier, we had used diff with a matrix argument, and now we use it with a symbollic argument. A code that uses this approach is available as hw 4 2b.m.
Here is a sample diary from runningthis code:
hw4_2b Supply an argument (| x |<= pi/4) for the tan function :. Supply a tolerance (positive):. The sum through the term n = 5 is 0. The relative error at x = 0.2 is3.46394e- diary off
Note that in this course we do not discuss the Maple symbollic toolbox. The hw 4 2b.m code is for your amusement. Fortunately, it produces the same result as the earlier version of the code.
Finally, it was suggested that we consider the Maclaurin expansion of the arc-tangent atan. The first few terms in the Maclaurin expansion are
tan−^1 (x) = x −
x^3 3
x^5 5
x^7 7
x^9 9
Here, we can see the pattern:
For the arc-tangent the radius of convergence is |x| < 1.
Here is a sample diary from runningthis code:
hw_4_2c Please enter a value to be evaluated :. Please enter a tolerance for the Maclaurin series :. After 7 termsthe Maclaurin sum is0.. The relative error is: 8.98441411e- diary off
r =
(x^2 + y^2 ) and θ = tan−^1 (y/x).
There is an issue of quadrant resolution since tan(x + π) = tan(x). Fortunately, Mat- lab (and most other scientific computing languages) provide us with a two argument arc tangent (atan2) to resolve the quandrant. A function.m file that uses this approach is available as cart2polar.m. Here is a sample diary from runningthis code:
[radius, angle] = cart2polar(1,2)
radius=
angle =
diary off
One subtle feature is to use Matlab’s dot or array arithmetic, so that we can provide an array of x and y values. Of course, the arrays must be the same size and we get back comaptibly sized arrays of radius and theta values.
r =
(x^2 + y^2 + z^2 ) , θ = tan−^1 (y/x) , andφ = cos−^1 (z/r).
Note that r ≥ 0 , −π < θ ≤ π, and0 ≤ φ ≤ pi Here again, we use the two argument arc tangent to resolve the quandrant for θ and employ dot or array arithmetic. A function.m file that uses this approach is available as cart2spherical.m. Here is a sample diary from runningthis code:
[radius, theta, phi] = cart2spherical(1,2,2) radius = 3 theta =
phi =
diary off