3.7.1: Series Additional Material
- Page ID
- 84392
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)By Carey A. Smith
There are 2 methods to sum a series. Let the variable "term" be computed value of the current value and the variable "total" be the running sum.
Method 1: Use a temporary variable, "total_new", to make it clear what is happening:
total_new = total + term;
% Add the previous total and the current term to get the new total.
total = total_new;
% Reset total to the new value
Method 2: Directly assign the new value of "total" to be equal to current value of total + term:
total = total + term;
% Replace the previous total with the sum of the current term + term
These 2 methods are equivalent. The first method is more obvious what is happening. The second is method common among experienced programmers. It may be slightly faster.
Note: Variable names other than "total"--such as "series_sum--are often used in codes.
Warning: Do not using "sum" as a variable, because that would be a name collision with the built-in function sum().
.
% Clear any variables etc.
clear all; close all; format compact; clc;
% Initialize these variables:
n = 6; % The number of terms in the series
A0 = 4; % The first value
r = 1/2; % The ratio of successive terms
% Write a for loop that computes the terms in the series which are computed with this expression:
% A(k) = A0*r^k;
%% Method 1:
total = 0; % Initialize the total
for k = 1:n
A(k) = A0*r^k;
total_new = total + A(k);
total = total_new;
end
A % This displays all the values of the vector A
disp(['Method 1 total = ',num2str(total)])
%% Method 2:
total = 0; % Initialize the total
for k = 1:n
A(k) = A0*r^k;
total = total + A(k);
end
A % This displays all the values of the vector A
disp(['Method 2 total = ',num2str(total)])
Solution
Add example text here.
.
The Taylor's series for the arctangent function is:
atan(x) = x - x3/3 + x5/5 - x7/7 + ...
The general formula for the kth term is computed with these 2 lines of code:
m = (2*k-1) % This generates 1, 3, 5, 7, ...
term = (-1)^(k-1)*x^m / m % (-1)^(k-1) = 1, -1, 1, -1, ...
Because the sign changes from term to term, this is called an alternating series.
(1 pt) Write a Matlab m-file script. This script will have a "for loop". The details of the for loop are described below.
(1 pt) Put these lines of code at the beginning of your file:
% Compute the Taylor's series for atan(x)
% Clear any variables; close any figures; eliminate white space; clear the console
clear all; close all; format compact; clc;
% Open a figure for plotting the partial sums
% Octave needs graphics toolkit to plot graph.
graphics_toolkit("fltk") % Do not use with MATLAB
figure;
hold on;
grid on;
(1 pt) Initialize these variables:
x = pi/5 % Set the x-value
atan_series = 0; % Initialize the series' sum
(2 pts) Write a for loop. Let k = the for-loop index. k goes from 1 to 8
(3 pts) Inside the for loop, compute term as specified above for each iteration.
Then add term to the previous value of atan_series with this code (method 1):
atan_series_new = atan_series + term
atan_series = atan_series_new
(1 pt) Inside the for loop, also plot the kth partial sum with this code:
plot(k, atan_series,'o');
(1 pt) After the for loop, display the sum and the last term with these lines of code:
atan_series % Display the series sum
term % Display the last term that was calculated
(1 pt) Compute and display atan_Matlab = atan(x) [Matlab's buit-in function]
(1 pt) Compute and display the absolute error = abs( atan_series - atan_Matlab)
If the code is done correctly, the absolute error should be < 0.001
- Answer
-
Add texts here. Do not delete this text first
.
The image of a star thru a space telescope, which has no aberrations, is called an Airy pattern, shown in this image:
Figure \(\PageIndex{1}\): Airy pattern
(Airy pattern image [en.Wikipedia.org], This work has been released into the public domain by its author, Sakurambo at English Wikipedia.)
The formula for a cross-section of the Airy pattern intensity is:
\[ I(\theta) = I_0 \left[ \frac{2J_1(k*a*sin\theta)}{k*a*sin\theta} \right]^2 = I_0 \left[ \frac{2J_1(x)}{x} \right]^2 \]
where J1(x) is the 1st-order Bessel function of the 1st kind.
This Bessel function is approximated by this infinite series with α = 1:
\[J_\alpha (x) = \sum_{m=0}^\infty \frac{(-1)^m}{m!*\Gamma(m+\alpha+1)} * \left(\frac{x}{2}\right)^{(2m+\alpha)} \]
For m!, use the Matlab function factorial(m)
Г(p) = the Gamma function. In Matlab this function is gamma(p).
When is a positive integer, gamma(p) = (p-1)!
Instructions:
- Set x = 0.5
- Write a for loop to sum the terms of this Bessel function series, Jα(x), for m = 0 to 10.
- Display the last term
- Display the resulting sum
Solution
term = 1.5697e-27
J1_x = 0.24227
..