This preview shows pages 1–6. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 1 © Janice Regan, CMPT 128 January 2007 CMPT 128: Introduction to Computing Science for Engineering Students Programming with Arrays © Janice Regan, CMPT 128 January 2007 2 Example 1: problem statement Write a C++ program to find a root of a polynomial of positive order N using the NewtonRaphson method. Your program should contain three functions which complete the following tasks: 1. Evaluate the polynomial for a value X 2. Evaluate the derivative of the polynomial for a value X 3. Find the root of the polynomial using the Newton Raphson method. (needs 1 and 2) © Janice Regan, CMPT 128 January 2007 3 Evaluating a polynomial result = A N result = A N X + A N1 result = (A N X + A N1 ) X + A N2 = A N X 2 + A N1 X + A N2 result = (A N X N2 + A N1 X N3 + ... +A 2 )X + A 1 = A N X N1 + A N1 X N2 + ... +A 2 X + A 1 result = (A N X N1 + A N1 X N2 + ... +A 2 X +A 1 )X + A = A N X N + A N1 X N1 + ... +A 2 X 2 + A 1 X + A © Janice Regan, CMPT 128 January 2007 4 Evaluating a polynomial Consider a polynomial of the form result = A N X N + A N1 X N1 + ... +A 1 X + A Use Horner’s method to evaluate Set result = A N Repeat the following steps while N>0 Multiply result by X Add A N1 to result Decrement N © Janice Regan, CMPT 128 January 2007 5 Function for evaluating a polynomial Need the following pieces of information within...
View
Full
Document
This note was uploaded on 05/18/2010 for the course CMPT 128 taught by Professor Regan during the Spring '08 term at Simon Fraser.
 Spring '08
 REGAN

Click to edit the document details