tft每日頭條

 > 圖文

 > c語言計算回歸方程

c語言計算回歸方程

圖文 更新时间:2024-07-25 22:53:15

改進的歐拉方法求解微分方程

題目要求:

已知微分方程的初值問題如下:

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(); }

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关圖文资讯推荐

热门圖文资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved