数学建模社区-数学中国

标题: 求助,matlab second derivative approximation,导数逼近 [打印本页]

作者: splelvis    时间: 2010-2-19 05:39
标题: 求助,matlab second derivative approximation,导数逼近
clear all;. w  i$ S/ j' t1 \* o  P
nx=50;
/ B3 m2 d) g9 hny=30;$ A% K- m" s" u& c+ `1 d
hx=pi/nx;1 N( k3 w5 f9 W
x=linspace(0,pi,nx+1);$ {2 w& }( s+ p4 J* m+ e/ \' ~1 L
y=linspace(0,pi,ny+1);
! r+ Q) d* D4 _- _9 g( F1 h7 S$ g9 ?x_plus_h=x+hx.*ones(1,nx+1);* d$ B$ \  W% D3 o1 a
x_minus_h=x-hx.*ones(1,nx+1);
( U1 G  s2 y& s% ifor i=1:nx+1- F# b6 t$ c2 E1 q: ]7 y2 d
    for j=1:ny+1
6 T$ Q( F: ]1 S0 W1 V% o' i& Z$ E        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)  B# `2 V* [- \. A8 c
    end;  |  e/ E: b* ]: T% U0 B
end;0 s; w7 s, g7 b0 F6 |, o) b4 n
[xx,yy]=meshgrid(x,y);  ?2 b2 v# q1 n# O8 b
surf(xx,yy,f_xx);+ l- A+ G$ z& e- Y
title('partial derivative w.r.t.xx')5 d; i9 z! w% j
. @* u; D2 r" g0 F) b# d+ z

+ s& o- f( g  g' C另开一个f9文件,
1 m# O/ V( r+ |0 P2 ~$ Vfunction l=f9(x,y)
! ]- K: U/ i/ `, s9 h2 Q5 v. c' F( Vl=exp(sin(x-y));
+ t2 S( }* A" l2 W3 }0 ^
6 R0 D# h' T( g$ E7 q4 n( R
. [, W3 R* k) Z# Q# ]) d3 ]然后出来说错误了,; K3 L1 [$ F  b2 I5 g- S, ~7 ?
??? Input argument "x" is undefined.
7 O/ k/ m  S/ g2 S
, s( r/ `1 `; O# }* g2 f: [; A2 ]( OError in ==> f9 at 2
9 Z$ I$ G9 B- J7 c% k6 {8 Cl=exp(sin(x-y));
: }( K' |( e1 yError in ==> partial_derivxx at 11/ @8 u1 [  p7 I, ~! z4 ]  L
        f_xx(j,i)=(f9(x_plus_h(i),y(j))-2*f9+f9(x_minus_h(i),y(j)))./(hx.^2);# P5 E9 F/ D& u+ _. T

- G$ f0 D! H! s# x: x- f各位要怎么改才对呢
作者: 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~~~~~~~~~~~~~~~`




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5