数学建模社区-数学中国
标题:
求助,matlab second derivative approximation,导数逼近
[打印本页]
作者:
splelvis
时间:
2010-2-19 05:39
标题:
求助,matlab second derivative approximation,导数逼近
clear all;
! L& h" B' K/ d$ Q$ ?! J- W
nx=50;
@! G' W; g! L3 b, `
ny=30;
4 v# |: T9 q9 _2 j3 M E. c
hx=pi/nx;
/ R4 X, s/ a7 Z3 r+ Q, G+ o
x=linspace(0,pi,nx+1);
6 W# N; l* e% H8 S$ `( e8 H2 Z$ k
y=linspace(0,pi,ny+1);
7 C; ^. d% S3 w+ {0 O/ b- i+ t8 k7 _
x_plus_h=x+hx.*ones(1,nx+1);
2 d, c$ J" a* o4 z( w
x_minus_h=x-hx.*ones(1,nx+1);
Q7 v; J+ V' F2 P0 O2 Z
for i=1:nx+1
4 u n* o5 F0 L$ o. [
for j=1:ny+1
$ L4 L3 d! m9 }2 L/ N& s n
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)
! U" _; v5 [3 Y& a4 i% a
end;
& \" E: h4 ?" m" }& T5 M# O
end;
0 C7 \) I& ]" Q% n2 g5 U- m
[xx,yy]=meshgrid(x,y);
! _% h5 {8 L1 m4 N. p# P
surf(xx,yy,f_xx);
' e7 I# q3 R6 S& ?
title('partial derivative w.r.t.xx')
) W( G/ s( x5 L0 _5 g
,
( @' N1 S+ p' A* [
% R# c' }- J! L9 U/ {
另开一个f9文件,
& Q0 B* f6 i4 l' _' u4 ]7 h
function l=f9(x,y)
5 O+ R/ n6 }! O# }- E* f9 L
l=exp(sin(x-y));
3 m( [( \; l, b% ?% r" ~
: G! G7 c1 e; N# @
" D8 ?8 h* p1 r; p
然后出来说错误了,
. ]* k6 x: T0 e" T! m
??? Input argument "x" is undefined.
G' t2 y1 l* ~
# w+ X' M4 k( m) V2 t7 N
Error in ==> f9 at 2
( J3 t1 o9 E! q6 M! y9 H) V
l=exp(sin(x-y));
5 s- o6 G' r# d5 G0 {
Error in ==> partial_derivxx at 11
# \% l# x9 e0 l$ D
f_xx(j,i)=(f9(x_plus_h(i),y(j))-2*f9+f9(x_minus_h(i),y(j)))./(hx.^2);
; d7 |4 m' V" o
4 H$ z9 {$ q4 G4 K8 Q8 p% 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