?? impr_eul.cpp
字號:
////////////////////////////////////////////////////
//注釋請參看Euler法程序 Euler.cpp
////////////////////////////////////////////////////
// 程序4.2 — 改進的歐拉方法
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
//#include <graphics.h>
#include <math.h>
#include "expressi.cpp"
void Improved_Euler(char FxyString[],float x0,float y0,float h,int n)
{
int i;
float yi,tmp;
if(CreateFxy(FxyString)) return;
yi = y0;
for(i=1;i<n;++i)
{
tmp = yi;
yi = yi+h*f(x0+(i-1)*h,yi);//Euler公式
yi = tmp+h/2*(f(x0+(i-1)*h,tmp)+f(x0+i*h,yi)); //梯型公式
printf("\ny%d=%f",i,yi);
}
}
void main()
{
float x0,y0,h;
int n;
char FxyString[200];
printf("\nInput function,x0,y0,h,n: ");
scanf("%s %f %f %f %d",FxyString,&x0,&y0,&h,&n);
Improved_Euler(FxyString,x0,y0,h,n);
getch();
}
/*
運行實例
Input function,x0,y0,h,n: y-2*x/y 0 1 0.1 11
y1=1.095909
y2=1.184097
y3=1.266201
y4=1.343360
y5=1.416402
y6=1.485956
y7=1.552514
y8=1.616475
y9=1.678167
y10=1.737868
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -