Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Math Forum
»
Discussions
»
Software
»
comp.softsys.matlab
Notice: We are no longer accepting new posts, but the forums will continue to be readable.
Topic:
1 variable Derrivative of 2 D function...but Error..why??
Replies:
1
Last Post:
Dec 27, 2012 8:15 PM




Re: 1 variable Derrivative of 2 D function...but Error..why??
Posted:
Dec 27, 2012 8:15 PM


"Quynh Tram Nghuyen Thi" <lovelyeverything@yahoo.com.vn> wrote in message <kbhsun$1k$1@newscl01ah.mathworks.com>... > Problem: Compute DERRIVATIVE of FUNCTION U(x,y) by 1 variable x , domain 2D:RxR > I did: > mfile diff2.m: > function [du1]=diff2(Xi,Yi,Zi,X,Y,h) > if nargin<6; h=1e4;end; > du1=(interp2(Xi,Yi,Zi,X+h)interp2(Xi,Yi,Zi,Xh))/(2*h) > ......... > diff2(u,v,z,u,v) > ===>>>ERROR:Error using ==> interp2 at 140 > Wrong number of input arguments.           The error message is telling you what is wrong. The interp2 function does not accept four arguments. Check its documentation. I believe what you need is:
du1=(interp2(Xi,Yi,Zi,X+h,Y)interp2(Xi,Yi,Zi,Xh,Y))/(2*h);
As you have the code at present, you are not using diff2's Y input argument at all, and consequently interp2 has no way of telling what the precise y values are to be at the points where the partial derivatives with respect to x are to be taken. The values of y in Yi are in general offset from the correct locations. In any case interp2 does not know what to do here and is complaining.
I would also suggest that you beware of letting X+h and Xh fall out of range of Xi  otherwise you will receive NaNs from interp2.
Also I would suggest that your nomenclature for diff2 should probably be altered to show that differentiation is with respect to x and not y to prevent it from being misused in the future. Or perhaps you need to output both derivatives, one with respect to x and the other with respect to y:
[dx,dy] = diff2(....)
Roger Stafford



