格式八为格式五的变形泰勒展开
非对称但是相对前者更精准
代码解决:
function [result] = duijiao(x0,x1,h,q1,q2,f,u0,un) xx = x0:h:x1; len=(x1-x0)/h+1; Q1 = matlabFunction(q1); Q2 = matlabFunction(q2); F = matlabFunction(f); A=diag(Q1(xx(2:len-1)))+diag(Q2(xx(3:len-1)),1)+diag(Q2(xx(2:len-2)),-1); b = F(xx(2:len-1)); b(1)=b(1)+u0; b(len-2)=b(len-2)+un; result = inv(A)*(b'); end
题目:(第二问)
标准答案
ff = exp(x^2) >> FF=matlabFunction(ff) FF = 包含以下值的 function_handle: @(x)exp(x.^2) >> FF(1.05:0.05:1.95) ans = 1 至 8 列 3.0117 3.3535 3.7528 4.2207 4.7707 5.4195 6.1873 7.0993 9 至 16 列 8.1866 9.4877 11.0508 12.9358 15.2183 17.9933 21.3809 25.5337 17 至 19 列 30.6459 36.9661 44.8131
数值解答案:
syms x >> h=0.05 h = 0.0500 >> q1 = (2+5/6*h*h*4*x^2) q1 = x^2/120 + 2 >> q2 = h*h/12*4*x*x-1 q2 = x^2/1200 - 1 >> f=h*h/12*((-2*exp((x+h)^2))+10*(-2*exp(x*x))+(-2*exp((x-h)^2))) f = - exp(x^2)/240 - exp((x - 1/20)^2)/2400 - exp((x + 1/20)^2)/2400 duijiao(1,2,h,q1,q2,f,exp(1),(1-h*h/12*4*exp(2))*exp(4)) ans = 3.0114 3.3506 3.7474 4.2126 4.7599 5.4057 6.1703 7.0788 8.1622 9.4589 11.0169 12.8961 15.1717 17.9386 21.3165 25.4575 30.5556 36.8585 44.6844
对比::