lecture16 Programming with Arrays

lecture16 Programming with Arrays - 1 © Janice Regan, CMPT...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 Newton-Raphson 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 N-1 result = (A N X + A N-1 ) X + A N-2 = A N X 2 + A N-1 X + A N-2 result = (A N X N-2 + A N-1 X N-3 + ... +A 2 )X + A 1 = A N X N-1 + A N-1 X N-2 + ... +A 2 X + A 1 result = (A N X N-1 + A N-1 X N-2 + ... +A 2 X +A 1 )X + A = A N X N + A N-1 X N-1 + ... +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 N-1 X N-1 + ... +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 N-1 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.

Page1 / 12

lecture16 Programming with Arrays - 1 © Janice Regan, CMPT...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online