SlideShare a Scribd company logo
Excel Macro for computing definite integral of a polynomial function of degree 5, using Newton Raphson method. - Upendra Lele/Nov 2014 
Create a macro enabled Excel file with name “Integration of a function.xlsm”. Rename the first sheet as “Data” and type the details given in the image below. Add a command button on the sheet and rename it as compute. 
Now click on Developer menu, click on Macros, delete all previous macros and add the following code in a new Macro: 
---------------------------------------- 
Public i, j, k, iterations, row_no, col_no As Integer Public a, b, coeff(10) As Double Public x, incr_x, fn, sum_area As Double Public chkval As Double 
Sub Main() ' Solve a polynomial equation using Newton Raphson method ' Set up application progress message ' Application.Cursor = xlWait Application.DisplayStatusBar = True Application.StatusBar = "Calculations in progress. Please wait" Application.ScreenUpdating = False Application.DisplayAlerts = False Workbooks("Integration of a function.xlsm").Activate
Worksheets("Data").Activate ActiveSheet.ChartObjects(1).Select Selection.Delete 
Range("B11:C2000").Delete Call init_params Call compute_integral If j >= iterations Then If sum_area = 0 Then Cells(8, 5) = "Not possible to calculate integral" End If End If 
Call create_chart Workbooks(1).Activate Worksheets("Data").Activate Range("A1").Activate 
End Sub 
Sub init_params() ' Open files Workbooks(1).Activate Worksheets("Data").Activate a = Cells(6, 4).Value b = Cells(7, 4).Value Cells(8, 4) = "" Cells(8, 5) = "" row_no = 3 col_no = 3 coeff(0) = 0 k = 5 
For i = 1 To 6 coeff(i) = Cells(row_no, col_no) col_no = col_no + 1 Next 
iterations = 1000 x = a row_no = 11 Cells(row_no, 2).Value = x incr_x = (b - a) / iterations Call compute_fn sum_area = (fn * incr_x)
Cells(row_no, 3).Value = fn End Sub 
Sub compute_integral() ' Generate successive approximations of X For i = 1 To iterations row_no = row_no + 1 x = (x + incr_x) Call compute_fn sum_area = sum_area + (fn * incr_x) Cells(row_no, 2).Value = x Cells(row_no, 3).Value = fn Next 
Cells(8, 4) = sum_area Range("B11:B1011").NumberFormat = "0.000" Range("C11:C1011").NumberFormat = "0.00" 
End Sub 
Sub compute_fn() ' Compute the value of the function fn = ((coeff(1) * x ^ 5) + (coeff(2) * x ^ 4) + (coeff(3) * x ^ 3) + (coeff(4) * x ^ 2) + (coeff(5) * x) + coeff(6)) 
End Sub 
Sub create_chart() Sheets("Data").Select Range("F20").Select ActiveSheet.Shapes.AddChart.Select With ActiveChart .ChartType = xlColumnClustered .SetSourceData Source:=Workbooks(1).Sheets("Data").Range("B10:C1011") .SeriesCollection(1).XValues = Range("B11:B1011") .SeriesCollection(1).Values = Range("C11:C1011") .Axes(xlCategory).TickLabels.Font.FontStyle = "Bold" .Axes(xlValue).TickLabels.Font.FontStyle = "Bold" .HasTitle = True .HasLegend = False .ChartTitle.Text = "Y = f(x)" .Parent.RoundedCorners = True .ChartArea.Height = 200 .ChartArea.Width = 300 .ChartArea.Format.Fill.ForeColor.RGB = RGB(204, 255, 255) .SetElement (msoElementChartTitleAboveChart)
.ChartTitle.Characters.Font.Size = 12 .SeriesCollection(1).Select End With 
ActiveChart.SeriesCollection(2).Select Selection.Delete ' Resize and Position the chart on worksheet 
With ActiveChart.Parent .Left = 230 .Width = 375 .Top = 110 .Height = 225 End With 
Workbooks(1).Activate Worksheets("Data").Activate 
End Sub

More Related Content

What's hot

R programming lab 3 - jupyter notebook
R programming lab   3 - jupyter notebookR programming lab   3 - jupyter notebook
R programming lab 3 - jupyter notebook
Ashwini Mathur
 
Creating a Table from a Function
Creating a Table from a FunctionCreating a Table from a Function
Creating a Table from a Function
dmidgette
 
R programming lab 1 - jupyter notebook
R programming lab   1 - jupyter notebookR programming lab   1 - jupyter notebook
R programming lab 1 - jupyter notebook
Ashwini Mathur
 
MS Sql Server: Doing Calculations With Functions
MS Sql Server: Doing Calculations With FunctionsMS Sql Server: Doing Calculations With Functions
MS Sql Server: Doing Calculations With Functions
DataminingTools Inc
 
Memory management
Memory managementMemory management
Memory management
sana younas
 
R reference card short
R reference card shortR reference card short
R reference card short
Shekar Manick
 
Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)
Kamal Acharya
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
Muhammed Thanveer M
 
Modular Macros for OCaml
Modular Macros for OCamlModular Macros for OCaml
Modular Macros for OCaml
OCaml Labs
 
Mysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERTMysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERT
Harish Gyanani
 
Dma
DmaDma
Play with matrix in r
Play with matrix in rPlay with matrix in r
Play with matrix in r
Ashwini Mathur
 
Parent Functions
Parent FunctionsParent Functions
Parent Functions
VLB10525
 
Public class arithmetic operatordemo
Public class arithmetic operatordemoPublic class arithmetic operatordemo
Public class arithmetic operatordemo
Cliff Rodrigo
 
Graph Plots in Matlab
Graph Plots in MatlabGraph Plots in Matlab
Graph Plots in Matlab
DataminingTools Inc
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Naveen Gupta
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 

What's hot (19)

Stack and heap
Stack and heapStack and heap
Stack and heap
 
Uts
UtsUts
Uts
 
R programming lab 3 - jupyter notebook
R programming lab   3 - jupyter notebookR programming lab   3 - jupyter notebook
R programming lab 3 - jupyter notebook
 
Creating a Table from a Function
Creating a Table from a FunctionCreating a Table from a Function
Creating a Table from a Function
 
R programming lab 1 - jupyter notebook
R programming lab   1 - jupyter notebookR programming lab   1 - jupyter notebook
R programming lab 1 - jupyter notebook
 
MS Sql Server: Doing Calculations With Functions
MS Sql Server: Doing Calculations With FunctionsMS Sql Server: Doing Calculations With Functions
MS Sql Server: Doing Calculations With Functions
 
Memory management
Memory managementMemory management
Memory management
 
R reference card short
R reference card shortR reference card short
R reference card short
 
Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
Modular Macros for OCaml
Modular Macros for OCamlModular Macros for OCaml
Modular Macros for OCaml
 
Mysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERTMysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERT
 
Dma
DmaDma
Dma
 
Play with matrix in r
Play with matrix in rPlay with matrix in r
Play with matrix in r
 
Parent Functions
Parent FunctionsParent Functions
Parent Functions
 
Public class arithmetic operatordemo
Public class arithmetic operatordemoPublic class arithmetic operatordemo
Public class arithmetic operatordemo
 
Graph Plots in Matlab
Graph Plots in MatlabGraph Plots in Matlab
Graph Plots in Matlab
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 

Similar to Excel macro for integration of a function

Excel macro to generate prime numbers
Excel macro to generate prime numbersExcel macro to generate prime numbers
Excel macro to generate prime numbers
Upendra Lele
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISPDevnology
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
MOHAMMAD SAYDUL ALAM
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
BilawalBaloch1
 
1.2 matlab numerical data
1.2  matlab numerical data1.2  matlab numerical data
1.2 matlab numerical data
TANVIRAHMED611926
 
4. functions
4. functions4. functions
4. functions
PhD Research Scholar
 
Basics of MATLAB programming
Basics of MATLAB programmingBasics of MATLAB programming
Basics of MATLAB programming
Ranjan Pal
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Kurmendra Singh
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
amanabr
 
Rethink programming: a functional approach
Rethink programming: a functional approachRethink programming: a functional approach
Rethink programming: a functional approach
Francesco Bruni
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117
Ganesan Narayanasamy
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
srxerox
 
deep learning library coyoteの開発(CNN編)
deep learning library coyoteの開発(CNN編)deep learning library coyoteの開発(CNN編)
deep learning library coyoteの開発(CNN編)
Kotaro Tanahashi
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
Matlab Assignment Experts
 
10. Recursion
10. Recursion10. Recursion
10. Recursion
Intro C# Book
 
ML with python.pdf
ML with python.pdfML with python.pdf
ML with python.pdf
n58648017
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
gilpinleeanna
 

Similar to Excel macro for integration of a function (20)

Excel macro to generate prime numbers
Excel macro to generate prime numbersExcel macro to generate prime numbers
Excel macro to generate prime numbers
 
Ch6
Ch6Ch6
Ch6
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
1.2 matlab numerical data
1.2  matlab numerical data1.2  matlab numerical data
1.2 matlab numerical data
 
4. functions
4. functions4. functions
4. functions
 
Basics of MATLAB programming
Basics of MATLAB programmingBasics of MATLAB programming
Basics of MATLAB programming
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Rethink programming: a functional approach
Rethink programming: a functional approachRethink programming: a functional approach
Rethink programming: a functional approach
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
deep learning library coyoteの開発(CNN編)
deep learning library coyoteの開発(CNN編)deep learning library coyoteの開発(CNN編)
deep learning library coyoteの開発(CNN編)
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
 
Notes7
Notes7Notes7
Notes7
 
5 numerical analysis
5 numerical analysis5 numerical analysis
5 numerical analysis
 
10. Recursion
10. Recursion10. Recursion
10. Recursion
 
ML with python.pdf
ML with python.pdfML with python.pdf
ML with python.pdf
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
 

More from Upendra Lele

Incredible india presentation
Incredible india presentationIncredible india presentation
Incredible india presentation
Upendra Lele
 
Lagrangian optimization example
Lagrangian optimization exampleLagrangian optimization example
Lagrangian optimization example
Upendra Lele
 
Case study in Entrepreneurship (new Business set up)
Case study in Entrepreneurship (new Business set up)Case study in Entrepreneurship (new Business set up)
Case study in Entrepreneurship (new Business set up)
Upendra Lele
 
Iso9000 case study
Iso9000 case studyIso9000 case study
Iso9000 case study
Upendra Lele
 
Capacity planning case study 2
Capacity planning case study 2Capacity planning case study 2
Capacity planning case study 2
Upendra Lele
 
Capacity planning case study 1
Capacity planning case study 1Capacity planning case study 1
Capacity planning case study 1
Upendra Lele
 
Retail management case study
Retail management case studyRetail management case study
Retail management case study
Upendra Lele
 

More from Upendra Lele (7)

Incredible india presentation
Incredible india presentationIncredible india presentation
Incredible india presentation
 
Lagrangian optimization example
Lagrangian optimization exampleLagrangian optimization example
Lagrangian optimization example
 
Case study in Entrepreneurship (new Business set up)
Case study in Entrepreneurship (new Business set up)Case study in Entrepreneurship (new Business set up)
Case study in Entrepreneurship (new Business set up)
 
Iso9000 case study
Iso9000 case studyIso9000 case study
Iso9000 case study
 
Capacity planning case study 2
Capacity planning case study 2Capacity planning case study 2
Capacity planning case study 2
 
Capacity planning case study 1
Capacity planning case study 1Capacity planning case study 1
Capacity planning case study 1
 
Retail management case study
Retail management case studyRetail management case study
Retail management case study
 

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 

Excel macro for integration of a function

  • 1. Excel Macro for computing definite integral of a polynomial function of degree 5, using Newton Raphson method. - Upendra Lele/Nov 2014 Create a macro enabled Excel file with name “Integration of a function.xlsm”. Rename the first sheet as “Data” and type the details given in the image below. Add a command button on the sheet and rename it as compute. Now click on Developer menu, click on Macros, delete all previous macros and add the following code in a new Macro: ---------------------------------------- Public i, j, k, iterations, row_no, col_no As Integer Public a, b, coeff(10) As Double Public x, incr_x, fn, sum_area As Double Public chkval As Double Sub Main() ' Solve a polynomial equation using Newton Raphson method ' Set up application progress message ' Application.Cursor = xlWait Application.DisplayStatusBar = True Application.StatusBar = "Calculations in progress. Please wait" Application.ScreenUpdating = False Application.DisplayAlerts = False Workbooks("Integration of a function.xlsm").Activate
  • 2. Worksheets("Data").Activate ActiveSheet.ChartObjects(1).Select Selection.Delete Range("B11:C2000").Delete Call init_params Call compute_integral If j >= iterations Then If sum_area = 0 Then Cells(8, 5) = "Not possible to calculate integral" End If End If Call create_chart Workbooks(1).Activate Worksheets("Data").Activate Range("A1").Activate End Sub Sub init_params() ' Open files Workbooks(1).Activate Worksheets("Data").Activate a = Cells(6, 4).Value b = Cells(7, 4).Value Cells(8, 4) = "" Cells(8, 5) = "" row_no = 3 col_no = 3 coeff(0) = 0 k = 5 For i = 1 To 6 coeff(i) = Cells(row_no, col_no) col_no = col_no + 1 Next iterations = 1000 x = a row_no = 11 Cells(row_no, 2).Value = x incr_x = (b - a) / iterations Call compute_fn sum_area = (fn * incr_x)
  • 3. Cells(row_no, 3).Value = fn End Sub Sub compute_integral() ' Generate successive approximations of X For i = 1 To iterations row_no = row_no + 1 x = (x + incr_x) Call compute_fn sum_area = sum_area + (fn * incr_x) Cells(row_no, 2).Value = x Cells(row_no, 3).Value = fn Next Cells(8, 4) = sum_area Range("B11:B1011").NumberFormat = "0.000" Range("C11:C1011").NumberFormat = "0.00" End Sub Sub compute_fn() ' Compute the value of the function fn = ((coeff(1) * x ^ 5) + (coeff(2) * x ^ 4) + (coeff(3) * x ^ 3) + (coeff(4) * x ^ 2) + (coeff(5) * x) + coeff(6)) End Sub Sub create_chart() Sheets("Data").Select Range("F20").Select ActiveSheet.Shapes.AddChart.Select With ActiveChart .ChartType = xlColumnClustered .SetSourceData Source:=Workbooks(1).Sheets("Data").Range("B10:C1011") .SeriesCollection(1).XValues = Range("B11:B1011") .SeriesCollection(1).Values = Range("C11:C1011") .Axes(xlCategory).TickLabels.Font.FontStyle = "Bold" .Axes(xlValue).TickLabels.Font.FontStyle = "Bold" .HasTitle = True .HasLegend = False .ChartTitle.Text = "Y = f(x)" .Parent.RoundedCorners = True .ChartArea.Height = 200 .ChartArea.Width = 300 .ChartArea.Format.Fill.ForeColor.RGB = RGB(204, 255, 255) .SetElement (msoElementChartTitleAboveChart)
  • 4. .ChartTitle.Characters.Font.Size = 12 .SeriesCollection(1).Select End With ActiveChart.SeriesCollection(2).Select Selection.Delete ' Resize and Position the chart on worksheet With ActiveChart.Parent .Left = 230 .Width = 375 .Top = 110 .Height = 225 End With Workbooks(1).Activate Worksheets("Data").Activate End Sub