欧拉方法解微分方程,欧拉平衡微分方程

首页 > 机动车 > 作者:YD1662023-11-12 07:32:38

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

题目要求:

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

欧拉方法解微分方程,欧拉平衡微分方程(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(); }

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

题目要求:

求解线性方程组:

欧拉方法解微分方程,欧拉平衡微分方程(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(); }

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.