"firecube" <firecube@myrealbox.com> wrote in message
news:19f3723f.0208281457.9e85435@posting.google.com...
> > If you have the Symbolic Toolbox:
> > x = sym('x'); y=sym('y');
> >
> > diff(sin(x*y),x)
> > ans =
> > cos(x*y)*y
> >
> > diff(sin(x*y),y)
> > ans =
> > cos(x*y)*x
>
> Thanks for your answer. It really helped me. So I am going to you use
> Symbolic Toolbox for that. But how can I have the "ans" (e.g in your
> examples) as a function so I can calculate a function value later? For
> example: I want to have f(x,y)=cos(x*y)*y after executing the diff
> function, so I can calculate the: f(0,1) or calculating the derivative
> of the new function after that.
>
> Thanks again.
I'm sure there are other ways, but:
%Declare your variables as symbolics (note that you may also put constraints
on them: real, positive, etc. See help sym)
>> x= sym('x'); y=sym('y');
%Define your function
>> f=y*sin(x*y);
%Convert symbolic function to string, and write as an inline function
>> fxy=inline(char(f)) fxy =
Inline function:
fxy(x,y) = y*sin(x*y)
%Now solve for specific values of x, y
>> fxy(pi,2/3)
ans =
0.5774
OR
>> sym(fxy(pi,2/3))
ans =
sqrt(1/3)
Cheers,
Brett
