<分区>
我是 C++
编程新手,写过这段 C++
代码:
//colpitts high freq 1 GHz working with delay
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;
const double pi = 3.1415926;
int main(){
double c0, dx, dt,C1,C2,L,fs,Ceq, freq, tau, Rload, gload, Re, ge,gm,gc1,gc2,ic1,ic2,il,gl ;
c0=20000000000;
dx=0.01;
dt=dx/(2 * c0);
cout<<dt<<"\n";
double V1 [1000000]={};
double V2 [1000000]={};
V1[0]=1e-3;
C1=1e-12;
C2=5e-12;
L=30.4e-9;
fs=4e12;
Ceq=(C1 * C2)/(C1+C2);
cout<<Ceq<<"\n";
freq=1/(2 * pi * (sqrt(L*Ceq)));
cout<<freq<<"\n";
tau=1/freq;
cout<<tau<<"\n";
Rload=50;
Re=1e6;
ge=1/Re;
cout<<ge<<"\n";
gm=0;
gc1=(C1)/dt;
cout<<gc1<<"\n";
ic1=-((C1)/dt) * V1[0];
cout<<ic1<<"\n";
gc2=(C2)/dt;
cout<<gc2<<"\n";
ic2=-((C2)/dt) * V2[0];
cout<<ic2<<"\n";
gl=dt/(L);
cout<<gl<<"\n";
il=gl * (V2[0]-V1[0]);
cout<<il<<"\n";
gload=1/Rload;
cout<<gload<<"\n";
return (0);
}
当我在 Linux 机器上运行它时,它会抛出段错误(核心已转储)的错误,但是当我将数组更改为 100000 时,不会抛出任何错误并且程序会按预期执行。我知道问题出在分配给我的物理内存上,但是有办法解决吗?有人可以指导我需要进行哪些修改吗?