Matlab实现数值微分

来源:互联网 发布:传感器数据采集系统 编辑:程序博客网 时间:2024/05/18 13:31

基本证明就不说啦,基本上就是运用泰勒公式实现对函数的近似运算。

对于f(x)=-u‘’(x),u=sinx这个例子,代码如下

a(1)=2;a(2)=-1;for i=3:99    a(i)=0;endfor i=1:97    for j=1:99        C(i,j)=0;    endendfor i=1:97     C(i,i)=-1;     C(i,i+1)=2;     C(i,i+2)=-1;endfor i=1:97    c(i)=0;endc(98)=-1;c(99)=2;A=[a;C;c];x=0:0.01:1;u=sin(x);f=-diff(u,2);b(1)=sin(0)+1/100^2*f(1);b(99)=sin(1)+1/100^2*f(99);for i=2:98    b(i)=1/100^2*f(i);endU=inv(A)*b';plot(U,'r*')%近似的二次导图像hold onplot(sin(x),'b+')%精确的二次导图像

做出图像


3 0