嗨,我得到了错误的预期结果,我认为这是对 std::complex 的影响,这是我应该根据matlab得到的结果,如果你运行下面的代码,这是结果,这是我得到的结果,基本上一切都是只是南,我哪里做错了?
#include<cmath>
#include<complex>
#include<new>
#include<iostream>
int sign(double x){
if(x > 0) {
return 1;
}
else if(x < 0) {
return -1;
}
else {
return 0;
}
}
int main(){
double alpha = 1.8;
double beta = .35;
double sigma = 1;
double mu = 0.5;
double PI = 3.1416;
int N = 8192;
double h = 0.01;
std::complex<double>phi[N];
double* in_t2= new double[N];
double* abs_t = new double [N];
double* sign_t = new double [N];
std::complex<double> I(0,1);
double s = 0.01;
s = 1/(h*N);
std::cout<<s;
for (int i=1; i<=N; i++) {
in_t2[i-1] = 2*PI * (i - 1 - N/2)*s; // x1
}
for (int i = 0; i < N; i++){
abs_t[i] = std::abs(in_t2[i]);
}
for (int i = 0; i < N; i++){
sign_t[i] = sign(in_t2[i]);
}
for (int i = 0; i < N; i++){
//where i suspect the error is..
phi[i] = pow(abs_t[i],sign_t[i]);
}
for ( int i = 0; i< N; i++){
if (in_t2[i] == 0){
phi[i] = 0;
}
phi[i] = std::exp(phi[i]);
}
return 0;
}