Path: news.mathworks.com!not-for-mail
From: "Ben Hinkle" <bhinkle.nospam.pretty.please@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: symbolic toolbox diff
Date: Mon, 12 Nov 2007 15:09:40 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 24
Message-ID: <fh9qbk$780$1@fred.mathworks.com>
References: <femgeq$3f7$1@ginger.mathworks.com> <femp7j$lo0$1@ginger.mathworks.com> <fh5bm8$84u$1@fred.mathworks.com>
Reply-To: "Ben Hinkle" <bhinkle.nospam.pretty.please@mathworks.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1194880180 7424 172.30.248.37 (12 Nov 2007 15:09:40 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 12 Nov 2007 15:09:40 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869344
Xref: news.mathworks.com comp.soft-sys.matlab:437103



"Dan Marghitu" <marghitu@auburn.edu> wrote in message
<fh5bm8$84u$1@fred.mathworks.com>...
> How do you take the derivative of a variable function of time?
> For example
> 
> syms t
> x = sym('x(t)')
> f = 2*x
> 
> I want to take the derivative of function f with respect
to &#8216;x(t)&#8217;
> diff(f, x) or diff(f, 'x(t)')

If you want to sometimes treat x as a function of t and
sometimes not then you can define two variables xt =
sym('x(t)') and x = sym('x') and substitute one for the
other when you want to. For example f = 2*x treats f as a
function of x while ft = 2*xt treats f as a function of t.
Then diff(ft) is 2*diff(x(t),t). If you have an expression g
which involves x then you can use subs(g,x,xt) to replace x
with x(t). Similarly you can replace x(t) with x.

Hope that helps,
-Ben