Error for some reasons

// TestComplex.cpp : main project file.

#include "stdafx.h"
#include <iostream>
#include <complex>
#include <cmath>
#include <vector>
#include <Image.h>

using namespace System;
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++)
{
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;
}


//It prints out this errors

1>.\TestComplex.cpp(60) : error C2143: syntax error : missing ';' before '<'
1>.\TestComplex.cpp(60) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\TestComplex.cpp(61) : error C2143: syntax error : missing ';' before '{'
1>.\TestComplex.cpp(61) : error C2447: '{' : missing function header (old-style formal list?)

Line 60 is the only one that starts with vector < complex <double > > can anyone help identify what's the problem? Thank you in advance
When I ran it and I followed the error it led me to this line. I took the tolerance off and it ran fine for me. Hope this helps.

1
2
3
4
5
6
7
8
9
10
11
12
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;
}
Last edited on
thnx for your help, but it seems the same error still occurs on mine. I tried with other programs, but none seems to work also. Any other alternatives?
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.
Last edited on
i got it to work. Yeah, i actually did tried a new project before, but it didn't work then. Now I just typed the whole thing over again, it works now -_-" Thanks for your help though :D
Topic archived. No new replies allowed.