CppNoddy  0.92
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
NewtonIter.cpp File Reference
#include <Newton_bundle.h>

Go to the source code of this file.

Classes

class  CppNoddy::Example::VCube_root_problem
 Defines the problem: here z^3 -1 = 0, in vector form using real and imaginary parts. More...
 

Namespaces

namespace  CppNoddy
 A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechanics.
 
namespace  CppNoddy::Example
 

Functions

int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 38 of file NewtonIter.cpp.

39{
40 cout << "\n";
41 cout << "=== Newton: vector residual root test ==============\n";
42 cout << "\n";
43
44 // Instantiate the problem
45 Example::VCube_root_problem residual_problem;
46 // A Newton object
47 Newton<double> newton( &residual_problem );
48
49 // Set an initial guess
50 DenseVector<double> guess( 2, 0.0 );
51 guess[ 0 ] = -0.5;
52 guess[ 1 ] = 1.5;
53
54 try
55 {
56 newton.iterate( guess );
57 }
58 catch (const std::runtime_error &error )
59 {
60 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
61 return 1;
62 }
63
64 const double tol = 1.e-7;
65 if ( ( abs( guess[ 0 ] + 0.5 ) > tol ) ||
66 ( abs( guess[ 1 ] - sqrt( 3. ) / 2. ) > tol ) )
67 {
68 cout << "\033[1;31;48m * FAILED \033[0m\n";
69 guess.dump();
70 cout << abs( guess[ 1 ] - sqrt( 3. ) / 2. ) << "\n";
71 cout << abs( guess[ 0 ] + 0.5 ) << "\n";
72 return 1;
73 }
74 cout << "\033[1;32;48m * PASSED \033[0m\n";
75 return 0;
76
77}
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A vector NEWTON iteration class.
Definition: Newton.h:25

References CppNoddy::DenseVector< _Type >::dump(), and CppNoddy::Newton< _Type >::iterate().

© 2012

R.E. Hewitt