改进的欧拉方法求解微分方程

题目要求:

已知微分方程的初值问题如下:

c语言计算回归方程(c语言改进的欧拉法求解微分方程和雅可比迭代公式求解线性方程组)(1)

求y(1)的值。

#include "stdio.h" #include "math.h" double NewtonFun(double x) { return x-(x-exp(-x))/(1 x); } double getResult(double x1,double accuracy) { double x2 = 0.0; x2 = NewtonFun(x1); while(fabs(x2-x1)>=accuracy) { x1 = x2; x2 = NewtonFun(x1); } return x2; } main() { double x1,accuracy; printf("Please input the initial value\n"); /*输入迭代初值*/ scanf("%lf",&x1); printf("Please input accuracy\n"); /*输入迭代精度*/ scanf("%lf",&accuracy); printf("The result of function is %lf\n",getResult(x1,accuracy)); getche(); }

雅可比迭代公式求解线性方程组

题目要求:

求解线性方程组:

c语言计算回归方程(c语言改进的欧拉法求解微分方程和雅可比迭代公式求解线性方程组)(2)

#include "stdio.h" float func(float x,float y) { return y - 2*x / y; } float getResult(float x0,float y0,float h,float xn) { float yn; while(x0<xn) { yn = y0 h*func(x0,y0); y0 = yn; x0 = x0 h; } return yn; } main() { float x0,y0,h,xn; printf("Please input the initial value x0 & y0\n"); /*输入初始值x0和y0*/ scanf("%f %f",&x0,&y0); printf("Please input the step length\n"); /*输入步长值h*/ scanf("%f",&h); printf("Please input Xn\n"); /*输入要求的y(xn)的xn*/ scanf("%f",&xn); printf("The result of the function is %f\n",getResult(x0,y0,h,xn)); getche(); }

,