Quintic - cin>> a>> b>> c>> d>> e>>...

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

View Full Document Right Arrow Icon
#include <iostream> #include <cmath> #include <cassert> using namespace std; // Computes ax^5 + bx^4 + cx^3 + dx^2 + ex + f double quintic(double a, double b, double c, double d, double e, double f, double x) { double sum = a; sum *= x; sum += b; sum *= x; sum += c; sum *= x; sum += d; sum *= x; sum += e; sum *= x; sum += f; return sum; } double deriv_quintic(double a, double b, double c, double d, double e, double f, double x) { return quintic(0, 5*a, 4*b, 3*c, 2*d, e, x); } int main() { cout << "Finding a root of ax^5 + bx^4 + cx^3 + dx^2 + ex + f" << endl << endl; double a, b, c, d, e, f, x; cout << "Enter values for a b c d e f (space separated): " << endl;
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cin >> a >> b >> c >> d >> e >> f; cout << "Enter a guess: "; cin >> x; assert(cin); cout << "f(x) = " << quintic(a,b,c,d,e,f,x) << endl; cout << "f'(c) = " << deriv_quintic(a,b,c,d,e,f,x) << endl; double old_x; do { old_x = x; x -= quintic(a,b,c,d,e,f,x) / deriv_quintic(a,b,c,d,e,f,x); } while(fabs(x - old_x) > 0.0001); cout << "zero: " << x << endl; cout << "f(x) = " << quintic(a,b,c,d,e,f,x) << endl; } // (x-4)(x+1)(x-3)(x+6)(x-1) // = x^5 - x^4 - 31x^3 + 73x^2 + 30x - 72 // 1 -1 -31 73 30 -72...
View Full Document

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Page1 / 2

Quintic - cin>> a>> b>> c>> d>> e>>...

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

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