gpt4 book ai didi

C 重定位 0 具有无效的符号索引

转载 作者:太空宇宙 更新时间:2023-11-04 08:49:35 25 4
gpt4 key购买 nike

首先,对于我的代码中可能出现的废话,我深表歉意,我还只是个初学者。我正在尝试用

编译这段代码
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

//initial conditions
//#define rs0 2.064594102e11
//#define re0 5.064594102e16
//#define vs0 2.929599982
//#define ve0 29295.99982
#define ms 1.9891e30
#define me 5.9736e24
#define a 149598261e3
#define e 0.0167112303531389
#define G 6.67428e-11
#define Tday 86164.1
//#define Tyear 31552844.28
#define I1 8.008e37
#define I3 8.034e37
#define Theta0 24.45




typedef void (*vector_function)(double* y, double t, double* f);

void integrator(vector_function f, int n, double* y,
double t, double dt, double* yn)
{
double k1[n],k2[n],k3[n],k4[n],ytmp[n];
double deriv[n]; // note that dynamic arrays are
// a C99 feature -- check your compiler flags
f(y, t, deriv);
for (int i=0; i<n; ++i)
{
k1[i] = deriv[i] * dt;
ytmp[i]=y[i]+0.5*dt*deriv[i];
//diff[i]=deriv[i];
}
f(ytmp,t+0.5*dt,deriv);
for(int i=0;i<n;++i)
{
k2[i]=dt*deriv[i];
ytmp[i]=y[i]+0.5*dt*deriv[i];
}
f(ytmp,t+0.5*dt,deriv);
for(int i=0;i<n;++i)
{
k3[i]=dt*deriv[i];
ytmp[i]=y[i]+dt*deriv[i];
}
f(ytmp,t+dt,deriv);
for(int i=0;i<n;++i) k4[i]=dt*deriv[i];

for(int i=0;i<n;++i)
{
yn[i]=y[i]+(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6;
}
for (int i=0; i<12; ++i)
{
y[i] = yn[i];
}
}


void F(double *y, double t, double* f)
{
double re0 = (a*(1+e)*ms)/(me+ms);
double rs0 = (-me*re0)/ms;
double kE = (G*ms*me/a)*(-0.5 + (1/(1+e)));
double ve0 = sqrt((2*kE)/(me*(1+(me/ms))));
double vs0 = -me*ve0/ms;
double Tyear = (2*3.141592*pow(a, 2/3))/sqrt(G*(ms+me));

double d[3] = {y[0]-y[6], y[1]-y[7], y[5]-y[8]};
double dcube = pow((y[0]-y[6])*(y[0]-y[6])+(y[1]-y[7])*(y[1]-y[7])+(y[5]-y[8])* (y[5]-y[8]), 3);


for (int i = 0; i<3; ++i)
{
//Force Earth
f[i] = G*ms*d[i]/dcube;

//Velocity Earth
f[3+i] = y[3+i];

//Force Sun
f[6+i] = -G*me*d[i]/dcube;

//Velocity Sun
f[9+i] = y[9+i];
}



int main(int argc, char ** argv)
{
int Tmax, m;
//printf("Please input number of the years\n");
//scanf("%i",&y);
Tmax = Tyear;
printf("please input the number of steps \n");
scanf("%d",&m);

// y[11] = {re0, 0, 0, 0, ve0, 0, rs0, 0, 0, 0, vs0, 0};
double y[11], yn[11];
//,sum[2];

y[0]=re0;
y[1]=0;
y[2]=0;
y[3]=0;
y[4]=ve0;
y[5]=0;
y[6]=rs0;
y[7]=0;
y[8]=0;
y[9]=0;
y[10]=vs0;
y[11]=0;


double t=0;
double dt=( Tmax-t )/m;
// the runge-kuta integrator starts from here
for (int k=0; k<m;k++)
{
t=t+dt;
integrator(F, 12, y, t, dt, yn);
printf("%e %e %e %e\n", t, y[0], y[1], y[2]);
for(int i=0; i<3; ++i) y[i] = yn[i];
}
printf("the intigrated components of the radius-vector and the velosity of the Earth are:\n");
for (int i=0; i<6; ++i)
{
printf("%lf", yn[i]);
}

printf("the intigrated components of the radius-vector and the velosity of the Sun are:\n");
for (int i=6; i<12; ++i)
{
printf("%lf", yn[i]);
}

/* printf("the intigrated vr is %lf\n",yn[1]);
printf("the intigrated theta is %lf\n",yn[2]);*/
//fprintf(f,"%lf/t%lf/n",y[0],y[2]);
//fclose(f);
return 0;
}
}

然后我编译它:

Main: main.c
gcc -c main.c -o main -std=c99 -lm

它不会创建执行文件,我得到的权限被拒绝。

A 还尝试在没有 -c 的情况下使用相同的 makefiel.. 不起作用并产生主题中所述的一堆错误。帮助=(

最佳答案

所以,至少有两个问题:

  1. 如果缩进代码,您会发现 F() 函数缺少右大括号。
  2. 不要在编译行中使用 -c

关于C 重定位 0 具有无效的符号索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20159094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com