/*以下消除了楼主源程序编译时的5个warning*/
/*至于其专业功能正常与否需要楼主自行判断*/
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
main()
{
long i=1,n=2;//原先楼主错将n定义为double型
double omga,l,g=9.8,t=0,beta,F,miu; //A,deta冗余
double seta[3],dydx[3],yout[3],h,dt=0.01;//n移出
FILE *fp; //fpdata冗余
void function(double t,double seta[],double dydx[],double omga,double beta,double F,double miu);
void rk4(double y[],double yn[],int n,double t,double h,double yout[],double omga,double beta,double F,double miu);
system("cls");
l=1.0;
omga=sqrt(g/l);
beta=0.25;
miu=2.0/3;
seta[1]=1;
seta[2]=0;
F=1.15;
if((fp=fopen("seta.txt","w"))==NULL)
{
printf("the file:seta.txt can not open:Press any key to exit:");
getch();
exit(1);
}
function(t,seta,dydx,omga,beta,F,miu);
h=dt;
fprintf(fp,"%.5lf\t%.5lf\t%.5lf\t%.5lf\n",t,seta[1],seta[2],miu*t);
do
{
function(t,seta,dydx,omga,beta,F,miu);
t+=dt;
rk4(seta,dydx,n,t,h,yout,omga,beta,F,miu);
seta[1]=yout[1];
seta[2]=yout[2];
i++;
fprintf(fp,"%.5lf\t%.5lf\t%.5lf\t%.5lf\n",t,yout[1],yout[2],miu*t);
}
while(!kbhit());
getch();
printf("F=%.5lf\tend\nPress any key to continue:",F);
fclose(fp);
printf("i=%ld\n",i);
printf("beta=%.7lf\nmiu=%.7lf\nF=%.7lf\nomga=%.7lf\n",beta,miu,F,omga);
getch();
}
void rk4(double y[],double yn[],int n,double t,double h,double yout[],double omga,double beta,double F,double miu)
{
int i;
double ytemp[3],k2[3],k3[3],k4[3],th,h2,h6;
h2=h*0.5;
h6=h*1.0/6;
th=t+h2;
for(i=1;i<3;i++)
{
ytemp[i]=0;
k2[i]=0;
k3[i]=0;
k4[i]=0;
}
for(i=1;i<=n;i++)
ytemp[i]=y[i]+h2*yn[i];
function(th,ytemp,k2,omga,beta,F,miu);
for(i=1;i<=n;i++)
ytemp[i]=y[i]+h2*k2[i];
function(th,ytemp,k3,omga,beta,F,miu);
for(i=1;i<=n;i++)
ytemp[i]=y[i]+h*k3[i];
function(t+h,ytemp,k4,omga,beta,F,miu);
for(i=1;i<=n;i++)
yout[i]=y[i]+h6*(yn[i]+2.0*k2[i]+2.0*k3[i]+k4[i]);
}
void function(double t,double seta[],double dydx[],double omga,double beta,double F,double miu)
{
dydx[1]=seta[2];
dydx[2]=-omga*omga*sin(seta[1]);
}
落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。