http://www.mathworks.com/matlabcentral/newsreader/view_thread/276896
MATLAB Central Newsreader  symbolic toolbox matlabFunction
Feed for thread: symbolic toolbox matlabFunction
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 19 Mar 2010 16:17:05 +0000
symbolic toolbox matlabFunction
http://www.mathworks.com/matlabcentral/newsreader/view_thread/276896#727843
Floris Zoutman
I have a piece of code that looks something like this:<br>
x=zeros(N_x,1);<br>
y=zeros(N_y,1);<br>
sym(x);<br>
sym(y);<br>
H=a differentiable scalar function of vectors y and x;<br>
H_x=simplify(jacobian(H,x)); <br>
H_y=simplify(jacobian(H,y));<br>
f_x=matlabFunction(H_x);<br>
f_y=matlabFunction(H_y);<br>
for i=many values of x and y<br>
x=N_x*1 vector with some values for x<br>
y=N_y*1 vector with some values for y<br>
derivatives_x(:,i)=f_x(x,y);<br>
derivatives_y(:,i)=f_y(x,y);<br>
end<br>
<br>
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:<br>
f_x(x,y)=g(x)+0*y <br>
but I do not know how to get to something like that. Does anybody have any suggestions? Many thanks in advance.<br>
<br>
With kind regards,<br>
<br>
Floris

Fri, 19 Mar 2010 17:04:03 +0000
Re: symbolic toolbox matlabFunction
http://www.mathworks.com/matlabcentral/newsreader/view_thread/276896#727853
Steven Lord
<br>
"Floris Zoutman" <fzoutman@hotmail.com> wrote in message <br>
news:ho0821$t5t$1@fred.mathworks.com...<br>
>I have a piece of code that looks something like this:<br>
> x=zeros(N_x,1);<br>
> y=zeros(N_y,1);<br>
> sym(x);<br>
> sym(y);<br>
> H=a differentiable scalar function of vectors y and x;<br>
> H_x=simplify(jacobian(H,x)); H_y=simplify(jacobian(H,y));<br>
> f_x=matlabFunction(H_x);<br>
> f_y=matlabFunction(H_y);<br>
> for i=many values of x and y<br>
> x=N_x*1 vector with some values for x<br>
> y=N_y*1 vector with some values for y<br>
> derivatives_x(:,i)=f_x(x,y);<br>
> derivatives_y(:,i)=f_y(x,y);<br>
> end<br>
><br>
> Now my problem is that depending on the functional form of H, f_x and f_y <br>
> could be a function of only x or only y or a function of neither. In that <br>
> case the final two lines of my code cannot be executed. Is there any way <br>
> to work around this problem? Suppose that f_x is a function of x only than <br>
> I would be very happy if f_x would look like:<br>
> f_x(x,y)=g(x)+0*y but I do not know how to get to something like that. <br>
> Does anybody have any suggestions? Many thanks in advance.<br>
<br>
Use the 'vars' parameter for matlabFunction. There's an example on the <br>
reference page that uses 'vars' to control the order of the parameters; you <br>
can also use it to require that the function accept input variables that it <br>
doesn't depend on, in order to make its signature match a desired signature.<br>
<br>
<a href="http://www.mathworks.com/access/helpdesk/help/toolbox/symbolic/matlabfunction.html">http://www.mathworks.com/access/helpdesk/help/toolbox/symbolic/matlabfunction.html</a><br>
<br>
 <br>
Steve Lord<br>
slord@mathworks.com<br>
comp.softsys.matlab (CSSM) FAQ: <a href="http://matlabwiki.mathworks.com/MATLAB_FAQ">http://matlabwiki.mathworks.com/MATLAB_FAQ</a>

Fri, 19 Mar 2010 17:05:05 +0000
Re: symbolic toolbox matlabFunction
http://www.mathworks.com/matlabcentral/newsreader/view_thread/276896#727855
Roger Stafford
"Floris Zoutman" <fzoutman@hotmail.com> wrote in message <ho0821$t5t$1@fred.mathworks.com>...<br>
> <br>
> 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. <br>
> ........<br>
<br>
Your symbolic toolbox should be smart enough to get symbolic zeros in those cases you describe. My version is.<br>
<br>
Roger Stafford

Tue, 23 Mar 2010 10:55:22 +0000
Re: symbolic toolbox matlabFunction
http://www.mathworks.com/matlabcentral/newsreader/view_thread/276896#728861
Floris Zoutman
Thanks Steven and Roger, the vars command works!<br>
"Steven Lord" <slord@mathworks.com> wrote in message <ho0apr$g24$1@fred.mathworks.com>...<br>
> <br>
> "Floris Zoutman" <fzoutman@hotmail.com> wrote in message <br>
> news:ho0821$t5t$1@fred.mathworks.com...<br>
> >I have a piece of code that looks something like this:<br>
> > x=zeros(N_x,1);<br>
> > y=zeros(N_y,1);<br>
> > sym(x);<br>
> > sym(y);<br>
> > H=a differentiable scalar function of vectors y and x;<br>
> > H_x=simplify(jacobian(H,x)); H_y=simplify(jacobian(H,y));<br>
> > f_x=matlabFunction(H_x);<br>
> > f_y=matlabFunction(H_y);<br>
> > for i=many values of x and y<br>
> > x=N_x*1 vector with some values for x<br>
> > y=N_y*1 vector with some values for y<br>
> > derivatives_x(:,i)=f_x(x,y);<br>
> > derivatives_y(:,i)=f_y(x,y);<br>
> > end<br>
> ><br>
> > Now my problem is that depending on the functional form of H, f_x and f_y <br>
> > could be a function of only x or only y or a function of neither. In that <br>
> > case the final two lines of my code cannot be executed. Is there any way <br>
> > to work around this problem? Suppose that f_x is a function of x only than <br>
> > I would be very happy if f_x would look like:<br>
> > f_x(x,y)=g(x)+0*y but I do not know how to get to something like that. <br>
> > Does anybody have any suggestions? Many thanks in advance.<br>
> <br>
> Use the 'vars' parameter for matlabFunction. There's an example on the <br>
> reference page that uses 'vars' to control the order of the parameters; you <br>
> can also use it to require that the function accept input variables that it <br>
> doesn't depend on, in order to make its signature match a desired signature.<br>
> <br>
> <a href="http://www.mathworks.com/access/helpdesk/help/toolbox/symbolic/matlabfunction.html">http://www.mathworks.com/access/helpdesk/help/toolbox/symbolic/matlabfunction.html</a><br>
> <br>
>  <br>
> Steve Lord<br>
> slord@mathworks.com<br>
> comp.softsys.matlab (CSSM) FAQ: <a href="http://matlabwiki.mathworks.com/MATLAB_FAQ">http://matlabwiki.mathworks.com/MATLAB_FAQ</a> <br>
>