代码改变世界

随笔档案-2013年6月11日

计算方法之用变步长梯形求积公式求定积分

2013-06-11 13:02 by java20130722, 1197 阅读, 收藏,
摘要: /* * * 用变步长梯形求积公式求定积分 * 1 * ∫ (x/(4+x^2))dx * 0 */ #include #include #include #include #include #define epsilon 0.00001 float f(float x) { return(x/(4+x*x)); } float computeT(float a,float b) { float T=0,h=(b-a)/2; T=h*(f(a)+2*T+f(b))/2; return(T); } main() { int i; ... 阅读全文

计算方法之改进的欧拉法计算常微分方程

2013-06-11 13:01 by java20130722, 1017 阅读, 收藏,
摘要: /*********************** * *改进的欧拉法计算常微分方程 * y'=(1/x)*y-(1/x)*y^2, 1 #include #include float f(float x, float y) { return (y / x - y * y / x); } float Euler(float x0, float xn, float y0, int n) { int i; float yp, yc, x = x0, y = y0, h; h = (xn - x0) / n; for (i = 1; i <= n; i++) { yp = y... 阅读全文

计算方法之用雅克比法求线性方程组

2013-06-11 12:59 by java20130722, 245 阅读, 收藏,
摘要: /************************************* * 用雅克比法求线性方程组 * * 5*x1 + 2*x2 + 1*x3 = -12 *{-1*x1 + 4*x2 + 2*x3 = 20 * 2*x1 - 3*x2 +10*x3 = 3 * **************************************/ #include #include #include #define N 3 #define kmax 100 #define eps 1e-5 static double aa[N][N] = { { 5, 2, 1 }, { -1, ... 阅读全文

计算方法之用追赶法求线性方程组

2013-06-11 12:57 by java20130722, 532 阅读, 收藏,
摘要: /************************************* * 用追赶法求线性方程组 * * |- -| |- -| |- -| * | 2 -1 | | x1 | | 3 | * |-1 3 -2 | | x2 | | 1 | * | -2 4 -2 |*| x3 | = | 0 | * | -2 5 | | x4 | | -5 | * |- -| |- -| |- -| * ***************************... 阅读全文

计算方法之用高斯列主元消去法求线性方程组

2013-06-11 12:56 by java20130722, 492 阅读, 收藏,
摘要: /************************************* * 用高斯列主元消去法求线性方程组 * * 2*x1 + 2*x2 + 3*x3 = 3 *{4*x1 + 7*x2 + 7*x3 = 1 * -2*x1+ 4*x2 + 5*x3 = -7 * **************************************/#include #include #include #include #define N 3 int main() { static double a[N][N] = { { 2, 2, 3 }, { 4, 7, 7 }, { -2, 4... 阅读全文

计算方法之牛顿迭代法求方程根

2013-06-11 12:54 by java20130722, 547 阅读, 收藏,
摘要: /************************************* * 用牛顿迭代法求非线性方程 * f(x)=x-e^(-x)=0 * 在区间[0,1]的根,取ξ=10^(-5),x0 = 0.5 **************************************/ #include #include #include #define maxrept 1000 float f(float x) { return x - exp(-x); } float df(float x) { return 1 + exp(-x); } float iterate(float ... 阅读全文

计算方法之迭代法求方程根

2013-06-11 12:51 by java20130722, 602 阅读, 收藏,
摘要: /************************ * 用迭代法求方程 * f(x)=e^(-x)-x+1=0 * 的根 *************************/ #include #include #include float fa(float); float dd(float); int main() { float x0; printf("input data x0 = "); scanf("%f", &x0); printf("The root of f(x) = 0 is x = \t%f\n", dd( 阅读全文

计算方法之二分法求方程根

2013-06-11 12:48 by java20130722, 854 阅读, 收藏,
摘要: /************************ * 用二分法求方程 * f(x)=x^3-2x-5=0 * 在区间[2,3]内的根 *************************/ #include #include #include float f(float x) { float a; a = x * x * x - 2 * x - 5; return a; } int main() { float a, b, e, x; printf("\nplease input data a = "); scanf("%f", &a); pri 阅读全文