SlideShare una empresa de Scribd logo
1 de 11
Chapter 3: Summing Series
Summing Series
𝑖=1
𝑁
𝑖2
N = input(’Enter the number of terms required: ’);
s = 0;
for i = 1:N
s = s + iˆ2;
end
disp([’Sum of the first ’ int2str(N) ‘ squares is ’ int2str(s)])
• At the moment we will stick to f(i) = iˆ2. Again we shall start by doing an example
by hand, let us determine the values of I_N for N equals one to four. Firstly N = 1
𝐼1 =
𝑖=1
𝑁
𝑖2 = 1
For N=2
𝐼2 =
𝑖=1
𝑁
𝑖2 = 1 + 4 = 5
For N=3
𝐼3 =
𝑖=1
𝑁
𝑖2
= 1 + 4 + 9 = 14
In general,
𝐼𝑁 = 𝐼 (𝑁−1) + 𝑁2
maxN = input(’Enter the maximum value of N required: ’);
I(1) = 1ˆ2;
for N = 2:maxN
I(N) = I(N-1) + Nˆ2;
end
disp([’Values of I_N’])
disp([1:N; I])
Summing Infinite Series
• The Taylor series for a function f(x) about a point x = a is given by
• We can use this to approximate sin x by an infinite series in x as
• Of course in using a computer we cannot actually take N to be infinity, but we
shall take it to be large in the hope that the error will be small. We can write the
above series (taking N = 10) and evaluate the series at the points 0, 0.1, 0.2, 0.3,
0.4 and 0.5 using
v = 0.0:0.1:0.5;
sinx = zeros(size(v));
N = 10; range = 0:N;
ints = 2*range+1;
for n = range
sinx = sinx+(-1)ˆn*v.ˆints(n+1)/(factorial(ints(n+1)));
end
v = 0.0:0.1:0.5; sets up the vector v running from zero to a half in steps of a tenth.
sinx = zeros(size(v)); The command size(v) gives the size of the vector v and then the
command zero sets up sinx as an array of zeros of the same size.
N = 10; range = 0:N; sets a variable N to be equal to 10 and then sets up a vector range
which runs from zero to N.
ints = 2*range+1; This gives the mathematical expression 2n+1 for all the elements of the
vector range and puts them in ints.
for n = range ..... end This loop structure repeats its arguments for n equal to all the
elements of range.
sinx = sinx+(-1)ˆn*v.ˆints(n+1)/(factorial(ints(n+1))); This mathematical expression evaluates
the subject of the summation as a function of n. ints(1) refers to the value when n = 0). Also
note the use of .ˆ when operating on v as this is a vector.
IF, elseif, else statements
• It is convenient at this stage to introduce some of the other commands which are
available to us when constructing conditional statements, namely else and elseif.
The general form of these is given by:
if (expression)
commands ...
elseif (expression)
commands ...
else
commands ...
End
• Notice that each if statement must be paired with an end statement, but we can
use as many elseif statements as we like, but only one else (within a certain
level). We are also able to nest if statements: again it is recommended that the
new levels are indented so as to aid readability.
Example 3.12 Consider the following piece of code which determines
which numbers between 2 and 9 go into a specified integer exactly:
str = ’Divisible by ’;
x = input(’Number to test: ’);
for j = 2:9
if rem(x,j) == 0
disp([str int2str(j)])
end
end
Example 3.13 Here we construct a conditional statement which
evaluates the function:
if x >= 0 & x <= 1
f = x;
elseif x > 1 & x <= 2
f = 2-x;
else
f = 0;
end
Conditional loops
• Suppose we now want to repeat a loop until a certain condition is
satisfied. This is achieved by making use of the MATLAB command
while, which has the syntax
while (condition)
commands...
end
• Example 3.16: Write out the values of x2 for all positive integer values x such that
x3 < 2000. To do this we will use the code
Iteration
• repetition of a mathematical or computational procedure applied
to the result of a previous application, typically as a means of
obtaining successively closer approximations to the solution of
a problem.

Más contenido relacionado

Similar a 5. Summing Series.pptx

how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
Sajid Marwat
 
Problem 2.19. How much time is required to add or subtract two large.pdf
Problem 2.19. How much time is required to add or subtract two large.pdfProblem 2.19. How much time is required to add or subtract two large.pdf
Problem 2.19. How much time is required to add or subtract two large.pdf
JUSTSTYLISH3B2MOHALI
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
Sri Prasanna
 
C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2doc
Srikanth
 

Similar a 5. Summing Series.pptx (20)

Explanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expertExplanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expert
 
DSP_FOEHU - MATLAB 02 - The Discrete-time Fourier Analysis
DSP_FOEHU - MATLAB 02 - The Discrete-time Fourier AnalysisDSP_FOEHU - MATLAB 02 - The Discrete-time Fourier Analysis
DSP_FOEHU - MATLAB 02 - The Discrete-time Fourier Analysis
 
Classical programming interview questions
Classical programming interview questionsClassical programming interview questions
Classical programming interview questions
 
White box-sol
White box-solWhite box-sol
White box-sol
 
Introduction to python programming ( part-2 )
Introduction to python programming ( part-2 )Introduction to python programming ( part-2 )
Introduction to python programming ( part-2 )
 
Ee693 sept2014quizgt2
Ee693 sept2014quizgt2Ee693 sept2014quizgt2
Ee693 sept2014quizgt2
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
L06
L06L06
L06
 
Montecarlophd
MontecarlophdMontecarlophd
Montecarlophd
 
Theoryofcomp science
Theoryofcomp scienceTheoryofcomp science
Theoryofcomp science
 
big_oh
big_ohbig_oh
big_oh
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Problem 2.19. How much time is required to add or subtract two large.pdf
Problem 2.19. How much time is required to add or subtract two large.pdfProblem 2.19. How much time is required to add or subtract two large.pdf
Problem 2.19. How much time is required to add or subtract two large.pdf
 
Mathematical Statistics Assignment Help
Mathematical Statistics Assignment HelpMathematical Statistics Assignment Help
Mathematical Statistics Assignment Help
 
algorithm
algorithmalgorithm
algorithm
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
 
Informe laboratorio n°1
Informe laboratorio n°1Informe laboratorio n°1
Informe laboratorio n°1
 
C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2doc
 
Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01
 
Dynamical systems solved ex
Dynamical systems solved exDynamical systems solved ex
Dynamical systems solved ex
 

Más de HassanShah396906 (13)

lit-review-presentation [Autosaved].pptx
lit-review-presentation [Autosaved].pptxlit-review-presentation [Autosaved].pptx
lit-review-presentation [Autosaved].pptx
 
Bone Cement.pptx
Bone Cement.pptxBone Cement.pptx
Bone Cement.pptx
 
Optoelectronics Device’s.pptx
Optoelectronics Device’s.pptxOptoelectronics Device’s.pptx
Optoelectronics Device’s.pptx
 
5.Introduction_to_Heisenberg_model.pptx
5.Introduction_to_Heisenberg_model.pptx5.Introduction_to_Heisenberg_model.pptx
5.Introduction_to_Heisenberg_model.pptx
 
M1 - Research Philosophy and Methods.pptx
M1 - Research Philosophy and Methods.pptxM1 - Research Philosophy and Methods.pptx
M1 - Research Philosophy and Methods.pptx
 
Finite Element Method.pptx
Finite Element Method.pptxFinite Element Method.pptx
Finite Element Method.pptx
 
Ch # 9 Electrode Polarization.pptx
Ch # 9 Electrode Polarization.pptxCh # 9 Electrode Polarization.pptx
Ch # 9 Electrode Polarization.pptx
 
2. Chap 1.pptx
2. Chap 1.pptx2. Chap 1.pptx
2. Chap 1.pptx
 
Density Functional Theory.pptx
Density Functional Theory.pptxDensity Functional Theory.pptx
Density Functional Theory.pptx
 
Introduction to Python – Learn Python Programming.pptx
Introduction to Python – Learn Python Programming.pptxIntroduction to Python – Learn Python Programming.pptx
Introduction to Python – Learn Python Programming.pptx
 
Molecular dynamics Simulation.pptx
Molecular dynamics Simulation.pptxMolecular dynamics Simulation.pptx
Molecular dynamics Simulation.pptx
 
Interconnects.pptx
Interconnects.pptxInterconnects.pptx
Interconnects.pptx
 
VMDL_FEATURES.ppt
VMDL_FEATURES.pptVMDL_FEATURES.ppt
VMDL_FEATURES.ppt
 

Último

Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Sérgio Sacani
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Sérgio Sacani
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
PirithiRaju
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdf
PirithiRaju
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptx
AlMamun560346
 
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
Lokesh Kothari
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
Areesha Ahmad
 

Último (20)

9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)
 
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verifiedConnaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
 
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts ServiceJustdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
 
module for grade 9 for distance learning
module for grade 9 for distance learningmodule for grade 9 for distance learning
module for grade 9 for distance learning
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdf
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
 
Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
 
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencyHire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
 
Site Acceptance Test .
Site Acceptance Test                    .Site Acceptance Test                    .
Site Acceptance Test .
 
GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdf
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptx
 
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
 
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
 

5. Summing Series.pptx

  • 2. Summing Series 𝑖=1 𝑁 𝑖2 N = input(’Enter the number of terms required: ’); s = 0; for i = 1:N s = s + iˆ2; end disp([’Sum of the first ’ int2str(N) ‘ squares is ’ int2str(s)])
  • 3. • At the moment we will stick to f(i) = iˆ2. Again we shall start by doing an example by hand, let us determine the values of I_N for N equals one to four. Firstly N = 1 𝐼1 = 𝑖=1 𝑁 𝑖2 = 1 For N=2 𝐼2 = 𝑖=1 𝑁 𝑖2 = 1 + 4 = 5 For N=3 𝐼3 = 𝑖=1 𝑁 𝑖2 = 1 + 4 + 9 = 14 In general, 𝐼𝑁 = 𝐼 (𝑁−1) + 𝑁2
  • 4. maxN = input(’Enter the maximum value of N required: ’); I(1) = 1ˆ2; for N = 2:maxN I(N) = I(N-1) + Nˆ2; end disp([’Values of I_N’]) disp([1:N; I])
  • 5. Summing Infinite Series • The Taylor series for a function f(x) about a point x = a is given by • We can use this to approximate sin x by an infinite series in x as • Of course in using a computer we cannot actually take N to be infinity, but we shall take it to be large in the hope that the error will be small. We can write the above series (taking N = 10) and evaluate the series at the points 0, 0.1, 0.2, 0.3, 0.4 and 0.5 using
  • 6. v = 0.0:0.1:0.5; sinx = zeros(size(v)); N = 10; range = 0:N; ints = 2*range+1; for n = range sinx = sinx+(-1)ˆn*v.ˆints(n+1)/(factorial(ints(n+1))); end v = 0.0:0.1:0.5; sets up the vector v running from zero to a half in steps of a tenth. sinx = zeros(size(v)); The command size(v) gives the size of the vector v and then the command zero sets up sinx as an array of zeros of the same size. N = 10; range = 0:N; sets a variable N to be equal to 10 and then sets up a vector range which runs from zero to N. ints = 2*range+1; This gives the mathematical expression 2n+1 for all the elements of the vector range and puts them in ints. for n = range ..... end This loop structure repeats its arguments for n equal to all the elements of range. sinx = sinx+(-1)ˆn*v.ˆints(n+1)/(factorial(ints(n+1))); This mathematical expression evaluates the subject of the summation as a function of n. ints(1) refers to the value when n = 0). Also note the use of .ˆ when operating on v as this is a vector.
  • 7. IF, elseif, else statements • It is convenient at this stage to introduce some of the other commands which are available to us when constructing conditional statements, namely else and elseif. The general form of these is given by: if (expression) commands ... elseif (expression) commands ... else commands ... End • Notice that each if statement must be paired with an end statement, but we can use as many elseif statements as we like, but only one else (within a certain level). We are also able to nest if statements: again it is recommended that the new levels are indented so as to aid readability.
  • 8. Example 3.12 Consider the following piece of code which determines which numbers between 2 and 9 go into a specified integer exactly: str = ’Divisible by ’; x = input(’Number to test: ’); for j = 2:9 if rem(x,j) == 0 disp([str int2str(j)]) end end
  • 9. Example 3.13 Here we construct a conditional statement which evaluates the function: if x >= 0 & x <= 1 f = x; elseif x > 1 & x <= 2 f = 2-x; else f = 0; end
  • 10. Conditional loops • Suppose we now want to repeat a loop until a certain condition is satisfied. This is achieved by making use of the MATLAB command while, which has the syntax while (condition) commands... end • Example 3.16: Write out the values of x2 for all positive integer values x such that x3 < 2000. To do this we will use the code
  • 11. Iteration • repetition of a mathematical or computational procedure applied to the result of a previous application, typically as a means of obtaining successively closer approximations to the solution of a problem.