The Math Forum

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.soft-sys.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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Roger Stafford

Posts: 5,929
Registered: 12/7/04
Re: 1 variable Derrivative of 2 D function...but Error..why??
Posted: Dec 27, 2012 8:15 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Quynh Tram Nghuyen Thi" <> wrote in message <kbhsun$1k$>...
> 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:

[dx,dy] = diff2(....)

Roger Stafford

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.