Strange for me it prints out this
Testing the Complex class..
Problem 1: Testing
This is the value of z1: (1,2)
This is the value of z2: (3,5)
Result evaluated at z1: (3,-6)
Result evaluated at z2: (9,-15)
Result of log of z1: (0.804719,1.10715)
Result of log of z2: (1.76318,1.03038)
Result of multiplication of z1 and z2: (-7,11)
Result of z1 raised to the 2nd power: (-3,4)
Result of z2 raised to the 2nd power: (-16,30)
Problem 2: Newton's method
test (0,0)
test2 (4,0)
done.
Press any key to continue . . .
the only other things I did to the program was comment out these libraries.
//#include "stdafx.h"
//#include <Image.h>
and I also change
using namespace System; -> using namespace std;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
//#include "stdafx.h"
#include <iostream>
#include <complex>
#include <cmath>
#include <vector>
//#include <Image.h>
using namespace std;
using std::cout;
using std::endl;
using std::complex;
using std::conj;
using std::vector;
// This function computes a trivial function of one complex variable, and it returns
// a single complex value.
complex<double> evaluate( complex<double> z )
{
complex<double> w;
w = 3.0 * conj(z);
return w;
}
complex<double> logs( complex<double> z )
{
complex<double> logResult;
logResult = log(z);
return logResult;
}
complex<double> multiplication( complex<double> y, complex<double> z )
{
complex<double> multiplication;
multiplication = y * z;
return multiplication;
}
complex<double> expo( complex<double> z )
{
complex<double> exponent;
exponent = pow(z , 2);
return exponent;
}
complex<double> f( complex<double> x )
{
return complex<double>( x * x * x * x - 1.0);
}
complex<double> f_dot( complex<double> x)
{
return complex<double>( 4.0 * x * x * x);
}
vector <complex <double> > NewtonIteration( complex<double> z, double tolerance)
{
vector <complex <double> >newton;
//for(int i = 0; i <= 100 && f(z) <= tolerance ; i++)
for(int i = 0; i <= 100; i++)
{
z = z - (f(z) / f_dot(z));
newton.push_back(z);
}
return newton;
}
int main()
{
cout << "Testing the Complex class.." << endl;
// Declare several complex variables...
complex<double> z1( 1, 2 ), z2( 3, 5 );
complex<double> x(1, 2);
// Print out the varialbes, and a function value...
cout << "Problem 1: Testing" << endl;
cout << "This is the value of z1: " << z1 << endl;
cout << "This is the value of z2: " << z2 << endl;
cout << "Result evaluated at z1: " << evaluate( z1 ) << endl;
cout << "" << endl;
cout << "Result evaluated at z2: " << evaluate( z2 ) << endl;
cout << "" << endl;
cout << "Result of log of z1: " << logs(z1) << endl;
cout << "Result of log of z2: " << logs(z2) << endl;
cout << "" << endl;
cout << "Result of multiplication of z1 and z2: " << multiplication(z1, z2) << endl;
cout << "" << endl;
cout << "Result of z1 raised to the 2nd power: " << expo(z1) << endl;
cout << "Result of z2 raised to the 2nd power: " << expo(z2) << endl;
cout << "" << endl;
cout << "Problem 2: Newton's method" << endl;
cout << "test " << f(1) << endl;
cout << "test2 " << f_dot(1) << endl;
cout << "done." << endl;
system("PAUSE");
return 0;
}
|
Maybe try a new project? (I am sure you probably tried that)
Other then that I am not sure with out getting the error myself.