splelvis 发表于 2010-2-19 05:39

求助,matlab second derivative approximation,导数逼近

clear all;
nx=50;
ny=30;
hx=pi/nx;
x=linspace(0,pi,nx+1);
y=linspace(0,pi,ny+1);
x_plus_h=x+hx.*ones(1,nx+1);
x_minus_h=x-hx.*ones(1,nx+1);
for i=1:nx+1
    for j=1:ny+1
        f_xx(j,i)=(f9(x_plus_h(i),y(j))-2*f9+f9(x_minus_h(i),y(j)))./(hx.^2);   %原式f(x+hx,y)-2f(x,y)+f(x-hx,y)./(hx^2)
    end;
end;
=meshgrid(x,y);
surf(xx,yy,f_xx);
title('partial derivative w.r.t.xx')


另开一个f9文件,
function l=f9(x,y)
l=exp(sin(x-y));


然后出来说错误了,
??? Input argument "x" is undefined.

Error in ==> f9 at 2
l=exp(sin(x-y));
Error in ==> partial_derivxx at 11
        f_xx(j,i)=(f9(x_plus_h(i),y(j))-2*f9+f9(x_minus_h(i),y(j)))./(hx.^2);

各位要怎么改才对呢

splelvis 发表于 2010-2-19 07:35

我自己找到了问题,f9应该是 f9(x(i),y(j))

douglas8j 发表于 2010-2-19 07:35

abc~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

splelvis 发表于 2010-2-19 07:49

不好意思,我也觉得自己太粗心了

douglas8j 发表于 2010-2-19 07:59

henhaodeyipianwenzhang~~~~~~~~~~~~~~~`
页: [1]
查看完整版本: 求助,matlab second derivative approximation,导数逼近