SlideShare a Scribd company logo
1 of 4
Download to read offline
Excel Macro for solving a polynomial function of degree 10, using Newton Raphson method. - Upendra Lele/Nov 2014 
Create a macro enabled Excel file with name “Solving a Polynomial Equation.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 “Start”. 
Now click on Developer menu, click on Macros, delete all previous macros and add the following code in a new Macro. Make sure that line continuation delimiter “_” is added for long lines of code. 
After adding the code, enter some values as coefficients and click on “Start” button to check the result. 
Copy the following macro: 
Public i, j, k, iterations, row_no, col_no, chart_row_no As Integer Public coeff(15), der_coeff(15) As Double Public x, fn, der_fn, new_ratio As Double Public chart_range, x_values As String Public chkval As Double 
Sub Main() ' Solve a polynomial equation using Newton Raphson method ' Set up application progress message Application.DisplayStatusBar = True Application.StatusBar = "Calculations in progress. Please wait" Application.ScreenUpdating = False
Application.DisplayAlerts = False cgpi = 0 Call init_params Call solve_eqn If j >= iterations Then If Abs(fn) >= 0.0001 Then Cells(6, 5) = "Solution does not exist" Else Call create_chart End If End If End Sub 
Sub init_params() ' Open files Workbooks("Solving a Polynomial Equation.xlsm").Activate Worksheets("Data").Activate Call clear_chart Cells(6, 4) = "" Cells(6, 5) = "" Cells(7, 4) = "" Cells(8, 4) = "" row_no = 3 col_no = 3 coeff(0) = 0 der_coeff(0) = 0 k = 5 
For i = 1 To 11 coeff(i) = Cells(row_no, col_no) der_coeff(i) = k * Cells(row_no, col_no) col_no = col_no + 1 k = k – 1 Next 
iterations = 1000 x = 1 chart_row_no = 11 Call compute_fn Cells(chart_row_no, 2) = Round(x, 4) Cells(chart_row_no, 3) = Round(fn, 2) chart_row_no = chart_row_no + 1 End Sub
Sub solve_eqn() ' Generate successive approximations of X For j = 1 To iterations If Abs(fn) > 0.0001 Then x = (x - new_ratio) Call compute_fn Cells(chart_row_no, 2) = Round(x, 4) Cells(chart_row_no, 3) = Round(fn, 2) chart_row_no = chart_row_no + 1 Else Cells(5, 4).Value = x Cells(6, 4).Value = fn Cells(7, 4) = j j = iterations End If Next 
End Sub 
Sub compute_fn() ' Compute the value of the function fn = ((coeff(1) * x ^ 10) + (coeff(2) * x ^ 9) + (coeff(3) * x ^ 8) + (coeff(4) * x ^ 7) + (coeff(5) * x ^ 6)) + _ ((coeff(6) * x ^ 5) + (coeff(7) * x ^ 4) + (coeff(8) * x ^ 3) + (coeff(9) * x ^ 2) + (coeff(10) * x) + coeff(11)) 
der_fn = ((der_coeff(1) * x ^ 9) + (der_coeff(2) * x ^ 8) + (der_coeff(3) * x ^ 7) + (der_coeff(4) * x ^ 6) + _ (der_coeff(5) * x ^ 5) + (der_coeff(6) * x ^ 4) + (der_coeff(7) * x ^ 3) + (der_coeff(8) * x ^ 2) + (der_coeff(9) * x) + der_coeff(10)) 
new_ratio = (fn / der_fn) End Sub 
Sub create_chart() Sheets("Data").Select Range("F20").Select x_values = "B11:B" + Trim(Str(chart_row_no)) chart_range = "C11:C" + Trim(Str(chart_row_no)) ActiveSheet.Shapes.AddChart.Select With ActiveChart .ChartType = xlLine .SetSourceData Source:=Workbooks(1).Sheets("Data").Range("B10:C1011")
.SeriesCollection(1).XValues = Range(x_values) .SeriesCollection(1).Values = Range(chart_range) .Axes(xlCategory).TickLabels.Font.FontStyle = "Bold" ' .Axes(xlCategory).TickLabels.NumberFormat = "3" .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("Solving a Polynomial Equation.xlsm").Activate Worksheets("Data").Activate 
End Sub 
Sub clear_chart() On Error Resume Next ActiveSheet.ChartObjects(1).Select Selection.Delete chart_row_no = 11 
For i = 1 To 1000 Cells(chart_row_no, 2) = "" Cells(chart_row_no, 3) = "" chart_row_no = chart_row_no + 1 Next 
End Sub

More Related Content

Similar to Excel macro for solving a polynomial equation

Excel macro for integration of a function
Excel macro for integration of a functionExcel macro for integration of a function
Excel macro for integration of a functionUpendra Lele
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data ManipulationChu An
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming languageLincoln Hannah
 
R Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdfR Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdfTimothy McBush Hiele
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxagnesdcarey33086
 
INTRODUCTION TO MATLAB session with notes
  INTRODUCTION TO MATLAB   session with  notes  INTRODUCTION TO MATLAB   session with  notes
INTRODUCTION TO MATLAB session with notesInfinity Tech Solutions
 
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.docxgilpinleeanna
 
Finding root of equation (numarical method)
Finding root of equation (numarical method)Finding root of equation (numarical method)
Finding root of equation (numarical method)Rajan Thakkar
 
Introduction to Functions
Introduction to FunctionsIntroduction to Functions
Introduction to FunctionsMelanie Loslo
 
Monadologie
MonadologieMonadologie
Monadologieleague
 

Similar to Excel macro for solving a polynomial equation (20)

Excel macro for integration of a function
Excel macro for integration of a functionExcel macro for integration of a function
Excel macro for integration of a function
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
Matlab1
Matlab1Matlab1
Matlab1
 
Seminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mmeSeminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mme
 
R Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdfR Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdf
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
INTRODUCTION TO MATLAB session with notes
  INTRODUCTION TO MATLAB   session with  notes  INTRODUCTION TO MATLAB   session with  notes
INTRODUCTION TO MATLAB session with notes
 
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
 
Finding root of equation (numarical method)
Finding root of equation (numarical method)Finding root of equation (numarical method)
Finding root of equation (numarical method)
 
Statistics lab 1
Statistics lab 1Statistics lab 1
Statistics lab 1
 
Introduction to Functions
Introduction to FunctionsIntroduction to Functions
Introduction to Functions
 
Monadologie
MonadologieMonadologie
Monadologie
 
Matlab algebra
Matlab algebraMatlab algebra
Matlab algebra
 
Chapter2
Chapter2Chapter2
Chapter2
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Sample2
Sample2Sample2
Sample2
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
R language introduction
R language introductionR language introduction
R language introduction
 

More from Upendra Lele

Incredible india presentation
Incredible india presentationIncredible india presentation
Incredible india presentationUpendra Lele
 
Excel macro to generate prime numbers
Excel macro to generate prime numbersExcel macro to generate prime numbers
Excel macro to generate prime numbersUpendra Lele
 
Lagrangian optimization example
Lagrangian optimization exampleLagrangian optimization example
Lagrangian optimization exampleUpendra 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 studyUpendra Lele
 
Capacity planning case study 2
Capacity planning case study 2Capacity planning case study 2
Capacity planning case study 2Upendra Lele
 
Capacity planning case study 1
Capacity planning case study 1Capacity planning case study 1
Capacity planning case study 1Upendra Lele
 
Retail management case study
Retail management case studyRetail management case study
Retail management case studyUpendra Lele
 

More from Upendra Lele (8)

Incredible india presentation
Incredible india presentationIncredible india presentation
Incredible india presentation
 
Excel macro to generate prime numbers
Excel macro to generate prime numbersExcel macro to generate prime numbers
Excel macro to generate prime numbers
 
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

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

Excel macro for solving a polynomial equation

  • 1. Excel Macro for solving a polynomial function of degree 10, using Newton Raphson method. - Upendra Lele/Nov 2014 Create a macro enabled Excel file with name “Solving a Polynomial Equation.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 “Start”. Now click on Developer menu, click on Macros, delete all previous macros and add the following code in a new Macro. Make sure that line continuation delimiter “_” is added for long lines of code. After adding the code, enter some values as coefficients and click on “Start” button to check the result. Copy the following macro: Public i, j, k, iterations, row_no, col_no, chart_row_no As Integer Public coeff(15), der_coeff(15) As Double Public x, fn, der_fn, new_ratio As Double Public chart_range, x_values As String Public chkval As Double Sub Main() ' Solve a polynomial equation using Newton Raphson method ' Set up application progress message Application.DisplayStatusBar = True Application.StatusBar = "Calculations in progress. Please wait" Application.ScreenUpdating = False
  • 2. Application.DisplayAlerts = False cgpi = 0 Call init_params Call solve_eqn If j >= iterations Then If Abs(fn) >= 0.0001 Then Cells(6, 5) = "Solution does not exist" Else Call create_chart End If End If End Sub Sub init_params() ' Open files Workbooks("Solving a Polynomial Equation.xlsm").Activate Worksheets("Data").Activate Call clear_chart Cells(6, 4) = "" Cells(6, 5) = "" Cells(7, 4) = "" Cells(8, 4) = "" row_no = 3 col_no = 3 coeff(0) = 0 der_coeff(0) = 0 k = 5 For i = 1 To 11 coeff(i) = Cells(row_no, col_no) der_coeff(i) = k * Cells(row_no, col_no) col_no = col_no + 1 k = k – 1 Next iterations = 1000 x = 1 chart_row_no = 11 Call compute_fn Cells(chart_row_no, 2) = Round(x, 4) Cells(chart_row_no, 3) = Round(fn, 2) chart_row_no = chart_row_no + 1 End Sub
  • 3. Sub solve_eqn() ' Generate successive approximations of X For j = 1 To iterations If Abs(fn) > 0.0001 Then x = (x - new_ratio) Call compute_fn Cells(chart_row_no, 2) = Round(x, 4) Cells(chart_row_no, 3) = Round(fn, 2) chart_row_no = chart_row_no + 1 Else Cells(5, 4).Value = x Cells(6, 4).Value = fn Cells(7, 4) = j j = iterations End If Next End Sub Sub compute_fn() ' Compute the value of the function fn = ((coeff(1) * x ^ 10) + (coeff(2) * x ^ 9) + (coeff(3) * x ^ 8) + (coeff(4) * x ^ 7) + (coeff(5) * x ^ 6)) + _ ((coeff(6) * x ^ 5) + (coeff(7) * x ^ 4) + (coeff(8) * x ^ 3) + (coeff(9) * x ^ 2) + (coeff(10) * x) + coeff(11)) der_fn = ((der_coeff(1) * x ^ 9) + (der_coeff(2) * x ^ 8) + (der_coeff(3) * x ^ 7) + (der_coeff(4) * x ^ 6) + _ (der_coeff(5) * x ^ 5) + (der_coeff(6) * x ^ 4) + (der_coeff(7) * x ^ 3) + (der_coeff(8) * x ^ 2) + (der_coeff(9) * x) + der_coeff(10)) new_ratio = (fn / der_fn) End Sub Sub create_chart() Sheets("Data").Select Range("F20").Select x_values = "B11:B" + Trim(Str(chart_row_no)) chart_range = "C11:C" + Trim(Str(chart_row_no)) ActiveSheet.Shapes.AddChart.Select With ActiveChart .ChartType = xlLine .SetSourceData Source:=Workbooks(1).Sheets("Data").Range("B10:C1011")
  • 4. .SeriesCollection(1).XValues = Range(x_values) .SeriesCollection(1).Values = Range(chart_range) .Axes(xlCategory).TickLabels.Font.FontStyle = "Bold" ' .Axes(xlCategory).TickLabels.NumberFormat = "3" .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("Solving a Polynomial Equation.xlsm").Activate Worksheets("Data").Activate End Sub Sub clear_chart() On Error Resume Next ActiveSheet.ChartObjects(1).Select Selection.Delete chart_row_no = 11 For i = 1 To 1000 Cells(chart_row_no, 2) = "" Cells(chart_row_no, 3) = "" chart_row_no = chart_row_no + 1 Next End Sub