diff --git a/.gitignore b/.gitignore index 3e3461a..942356c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.asv +Romberg.m diff --git a/Legendre.m b/Legendre.m new file mode 100644 index 0000000..da9daba --- /dev/null +++ b/Legendre.m @@ -0,0 +1,39 @@ +function res=Legendre(x_value_list,iterate_times) +% \param first_x_value: start position +% \param iterate_times: max N num of PN +% +% \return res: the root value of Legendre +% ------------------------------------------------------------% +% P1(X)=1 +% P2(X)=X +% ...... +% pN+2(X)= (2*n + 3) / (n + 2) * x * PN+1(x) - (n + 1) / (n + 2) * PN(x) +% ------------------------------------------------------------% +% example: +% >> Legendre([0.93 -0.93 0.66 -0.66 0.23 -0.23],7); +% +% return +% the answer is +% 0.932470 +% -0.932470 +% 0.661209 +% -0.661209 +% 0.238619 +% -0.238619 +% ------------------------------------------------------------% + +syms x; +coefficient_list=sym(zeros(0,iterate_times)); +coefficient_list(1)=1; +coefficient_list(2)=x; + +for index=1:iterate_times-2 + n=index-1; + coefficient_list(index+2)= simplify(... + (2 * n + 3) / (n + 2) * x * coefficient_list(index+1) ... + - (n + 1) / (n + 2) * coefficient_list(index) ... + ); +end +disp(transpose(coefficient_list)); +res=newton_iteration(x_value_list,coefficient_list(iterate_times)); +end \ No newline at end of file diff --git a/README.md b/README.md index a7765e4..2780a39 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,18 @@ |列主元高斯消去法| | `GE_equ.m` | |改进平方根法|对称矩阵的三角分解| `LDL_equ.m` | |Household方法|QR分解| `Household_QR.m`
`Household_equ.m` | +|龙贝格积分| | `Romberg_calculus.m` | + ## 迭代解法 |算法名称 | 文件名 | |:--------:|:--------:| |共轭梯度法 |`CG_equ.m`| +|牛顿迭代法 |`newton_iteration.m`| +|四级RK法 |`Runge_Kutta.m`| + ## 插值 | 算法名称 | | 文件名 | |:----------:|:-----------:|:---------------:| -|三次样条插值 |第一种边界条件
第二种边界条件
第三种边界条件|`Spline1_inter.m`
`Spline2_inter.m`
`Spline3_inter.m` | \ No newline at end of file +|三次样条插值 |第一种边界条件
第二种边界条件
第三种边界条件|`Spline1_inter.m`
`Spline2_inter.m`
`Spline3_inter.m` | diff --git a/Romberg_calculus.m b/Romberg_calculus.m new file mode 100644 index 0000000..74c5700 --- /dev/null +++ b/Romberg_calculus.m @@ -0,0 +1,43 @@ +function res=Romberg_calculus(fx,a,b) +% \param fx: syms expression +% \param a: left bound +% \param b: right bound +% \return res: the fx calculus +% can change precision at the following +eps=1e-6; +buf=zeros(15); % size +% ------------------------------------------------------------% +% example: +% fx=@(x)x^2*exp(x); +% a=0; +% b=0.8; +% Romberg_calculus(fx,a,b); +% +% return +% the answer is +% 0.5697 +% 0.3172 +% 0.3146 +% 0.3146 +% 0.3146 +% ------------------------------------------------------------% +i=1; +buf(1,1)=(b-a)/2*(fx(b)+fx(a)); +while (1) + i=i+1; + buf(1,i)=1/2*buf(1,i-1); + for j=1:2^(i-2) + buf(1,i)=buf(1,i)+(b-a)/(2^(i-1))*fx(a+(2*j-1)*(b-a)/2^(i-1)); % get T_1_i+1 value + end + + for m=2:i + k=i+1-m; + buf(m,k)=(4^(m-1)*buf(m-1,k+1)-buf(m-1,k))/(4^(m-1)-1); + end + if (abs((buf(i,1)-buf(i-1,1)))precision) && (iterate_times<=max_iteration_times) + % if f'x < min_diff_value, + % return + if abs(subs(diff_fx,x,x_before))