⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r_k.cpp

📁 数值计算方法中几个重要的算法用VC++实现
💻 CPP
字号:
/******************************************/
/*                                        */
/*              4阶经典R-K算法            */
/*                                        */
/******************************************/
#include<stdio.h>
#define type "%lf"
typedef double Dtype;
Dtype f(Dtype x,Dtype y,Dtype erf)
{
    return erf*y-erf*x+1;
}
void main()
{
	int a,b,n,i;
	Dtype x0,x1,y0,y1,erf,h,K1,K2,K3,K4;
	
	printf("Please input a,b,n,erf:\n");
	scanf("%d%d%d"type,&a,&b,&n,&erf);

	/*-利用经典R_K算法计算x,y-*/
	h=(b-a)/(double)n;
	x0=a;y0=erf;
	for(i=1;i<=n;i++)
	{
		x1=x0+h;
		K1=f(x0,y0,erf);
		K2=f(x0+h/2,y0+(h/2)*K1,erf);
		K3=f(x0+h/2,y0+(h/2)*K2,erf);
		K4=f(x1,y0+h*K3,erf);
		y1=y0+h/6*(K1+2*K2+2*K3+K4);
		printf("x="type",    y="type"\n",x1,y1);
		x0=x1,y0=y1;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -