这个程序是大学三年级学习《数值分析》的时候写的程序,计算机以数学作为基础,很好的了解数有助于我们学习程序设计。
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
#include<stdio.h>
#define M 80
double f(double,double);
//void runge4(double,double,double,double,double);
void runge4(double a,double b,double rk[],double h,double x[])
{
int k,max;
double k1,k2,k3,k4;
max=(int)((b-a)/h);
x[0]=a;
for(k=1;k<=max;k++)//runge-kutta
{
x[k]=x[k-1]+h;
k1=f(x[k-1],rk[k-1]);
k2=f((x[k-1]+h*0.5),(rk[k-1]+h*0.5*k1));
k3=f((x[k-1]+h*0.5),(rk[k-1]+h*0.5*k2));
k4=f((x[k-1]+h),(rk[k-1]+h*k3));
rk[k]=rk[k-1]+h*(k1+2*k2+2*k3+k4)/6;
}
}
void main()
{
double x[M]={0.0},a,b,h,y[M]={0.0},k[5],y0;
int n,i,m;
cout<<"