From: "Steven Lord" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: symbolic toolbox matlabFunction
Date: Fri, 19 Mar 2010 13:04:03 -0400
Organization: The MathWorks, Inc.
Lines: 40
Message-ID: <ho0apr$g24$>
References: <ho0821$t5t$>
Reply-To: "Steven Lord" <>
X-Trace: 1269018235 16452 (19 Mar 2010 17:03:55 GMT)
NNTP-Posting-Date: Fri, 19 Mar 2010 17:03:55 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
X-RFC2646: Format=Flowed; Response
Xref: comp.soft-sys.matlab:618294

"Floris Zoutman" <> wrote in message 
>I have a piece of code that looks something like this:
> x=zeros(N_x,1);
> y=zeros(N_y,1);
> sym(x);
> sym(y);
> H=a differentiable scalar function of vectors y and x;
> H_x=simplify(jacobian(H,x)); H_y=simplify(jacobian(H,y));
> f_x=matlabFunction(H_x);
> f_y=matlabFunction(H_y);
> for i=many values of x and y
> x=N_x*1 vector with some values for x
> y=N_y*1 vector with some values for y
> derivatives_x(:,i)=f_x(x,y);
> derivatives_y(:,i)=f_y(x,y);
> end
> Now my problem is that depending on the functional form of H, f_x and f_y 
> could be a function of only x or only y or a function of neither. In that 
> case the final two lines of my code cannot be executed. Is there any way 
> to work around this problem? Suppose that f_x is a function of x only than 
> I would be very happy if f_x would look like:
> f_x(x,y)=g(x)+0*y but I do not know how to get to something like that. 
> Does anybody have any suggestions? Many thanks in advance.

Use the 'vars' parameter for matlabFunction.  There's an example on the 
reference page that uses 'vars' to control the order of the parameters; you 
can also use it to require that the function accept input variables that it 
doesn't depend on, in order to make its signature match a desired signature.

Steve Lord
comp.soft-sys.matlab (CSSM) FAQ: