Please could you give some feed back ll my inputs are double
Please could you give some feed back
ll my inputs are doubles instead of integers. Is it going to be a problem? Also, in my output I have both the real parts and the imaginary parts. Is it suppose to be like this?
// ConsoleApplication1.cpp : Defines the entry point for the console
application.
//
#include \"stdafx.h\"
#include <math.h>
#include <iostream>
#include <iomanip>
#include<complex>
#include<vector>
using namespace std;
#define PI 3.14159265
int main()
{
int N;
cout << \"Please enter the length of your vector f: \";
cin >> N;
double *f = new double[N];
cout << \"Please enter the elements of the vector f: \";
for (int i = 0; i < N; i++)
{
cin >> f[i];
}
std::complex<double> F[100];
std::complex<double> W[100][100];
std::complex<double> sum = 0.0;
for (int n = 0; n < N;n++)
{
for (int k = 0; k < N; k++)
{
W[n][k] = std::complex<double>((cos((2 * PI*n) / N)), (-sin((2
* PI*n) / N)));
sum = f[k] * pow(W[n][k], k);
F[n] = sum + F[n];
}
cout << F[n] << endl;
}
int M;
cout << \"Please enter the length of your vector g: \";
cin >> M;
double *g = new double[M];
cout << \"Please enter the elements of the vector g: \";
for (int i = 0; i < M; i++)
{
cin >> g[i];
}
std::complex<double> G[100];
std::complex<double> W1[100][100];
std::complex<double> sum1 = 0.0;
for (int n = 0; n < M; n++)
{
for (int k = 0; k < M; k++)
{
W1[n][k] = std::complex<double>((cos((2 * PI*n) / M)), (-
sin((2 * PI*n) / M)));
sum1 = g[k] * pow(W1[n][k], k);
G[n] = sum1 + G[n];
}
cout << G[n] << endl;
}
std::complex<double> V[100];
for (int i = 0; i < N; i++)
{
V[i] = F[i] * G[i]; cout << V[i] << endl;
}
std::complex<double> v[100];
for (int n = 0; n < N; n++)
{
for (int k = 0; k < N; k++)
{
W[n][k] = std::complex<double>((cos((2 * PI*n) / N)), (sin((2
* PI*n) / N)));
sum = ((V[k]/std::complex<double> (N,0)) * pow(W[n][k], k));
v[n] = sum + v[n];
}
cout << v[n] << endl;
}
system(\"pause\");
return 0;
Solution
1)
lf my inputs are doubles instead of integers. Is it going to be a problem? .
There wont be any probelm if the input is double or integer, as it is already declared double, it would work for any input.
2)Also, in my output I have both the real parts and the imaginary parts. Is it suppose to be like this?
That is how the complex number should be(real+imaginary parts). The output for the problem is correct.
/* sample output
*/


