"Quynh Tram Nghuyen Thi" <email@example.com> wrote in message <firstname.lastname@example.org>... > Problem: Compute DERRIVATIVE of FUNCTION U(x,y) by 1 variable x , domain 2D:RxR > I did: > m-file diff2.m: > function [du1]=diff2(Xi,Yi,Zi,X,Y,h) > if nargin<6; h=1e-4;end; > du1=(interp2(Xi,Yi,Zi,X+h)-interp2(Xi,Yi,Zi,X-h))/(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:
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 X-h 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: