Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Symbolic toolbox - "chain rule"

Subject: Symbolic toolbox - "chain rule"

From: Michal Lukac

Date: 16 Feb, 2012 18:39:12

Message: 1 of 9

Hello, how to apply chain rule with symbolic toolbox.

I have an expression e.g.:
L(t)*sin(fi(t)) and need to differentiate with respect to t

the result should looks like this:
dL(t)/dt * sin(fi(t)) + L(t) * dfi(t)/ft * cos(fi(t))

or the derivatives replaced with a new symbolic variables....

is it possible to do this in sym. toolbox?

thanks
michal

Subject: Symbolic toolbox - "chain rule"

From: Alan Weiss

Date: 16 Feb, 2012 21:15:16

Message: 2 of 9

On 2/16/2012 1:39 PM, Michal Lukac wrote:
> Hello, how to apply chain rule with symbolic toolbox.
>
> I have an expression e.g.:
> L(t)*sin(fi(t)) and need to differentiate with respect to t
>
> the result should looks like this:
> dL(t)/dt * sin(fi(t)) + L(t) * dfi(t)/ft * cos(fi(t))
>
> or the derivatives replaced with a new symbolic variables....
>
> is it possible to do this in sym. toolbox?
>
> thanks
> michal

syms fi(t)
syms L(t)
diff(L(t)*sin(fi(t)))

ans =

sin(fi(t))*diff(L(t), t) + cos(fi(t))*L(t)*diff(fi(t), t)

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: Symbolic toolbox - "chain rule"

From: Christopher Creutzig

Date: 17 Feb, 2012 08:12:08

Message: 3 of 9

On 16.02.12 22:15, Alan Weiss wrote:
> On 2/16/2012 1:39 PM, Michal Lukac wrote:
>> Hello, how to apply chain rule with symbolic toolbox.
>>
>> I have an expression e.g.:
>> L(t)*sin(fi(t)) and need to differentiate with respect to t

> syms fi(t)
> syms L(t)

That's the nice way of doing it, but requires 2012a (prerelease). The
“old” way, if Michal doesn't have the shiny new toys ;-), would be

>> diff(sym('L(t)*sin(fi(t))'))

ans =

sin(fi(t))*diff(L(t), t) + cos(fi(t))*L(t)*diff(fi(t), t)



Christopher

Subject: Symbolic toolbox - "chain rule"

From: Michal Lukac

Date: 17 Feb, 2012 09:10:17

Message: 4 of 9

> That's the nice way of doing it, but requires 2012a (prerelease). The
> “old” way, if Michal doesn't have the shiny new toys ;-), would be
>
> >> diff(sym('L(t)*sin(fi(t))'))
>
> ans =
>
> sin(fi(t))*diff(L(t), t) + cos(fi(t))*L(t)*diff(fi(t), t)
>
> Christopher


thanks, Christopher, yes I have 2011. I couldn't find that in help..

Subject: Symbolic toolbox - "chain rule"

From: Nasser M. Abbasi

Date: 17 Feb, 2012 09:47:56

Message: 5 of 9

On 2/17/2012 2:12 AM, Christopher Creutzig wrote:

> That's the nice way of doing it, but requires 2012a (prerelease). The
> “old” way, if Michal doesn't have the shiny new toys ;-), would be

hi;

Is it possible to read somewhere on what will be new in Matlab 2012a?

--Nasser

Subject: Symbolic toolbox - "chain rule"

From: Christopher Creutzig

Date: 17 Feb, 2012 15:42:49

Message: 6 of 9

On 17.02.12 10:47, Nasser M. Abbasi wrote:
> On 2/17/2012 2:12 AM, Christopher Creutzig wrote:
>
>> That's the nice way of doing it, but requires 2012a (prerelease). The
>> “old” way, if Michal doesn't have the shiny new toys ;-), would be
>
> hi;
>
> Is it possible to read somewhere on what will be new in Matlab 2012a?

Log in to mathworks.com, go to “My Account” and check out the 2012a
prerelease, which includes release notes, which may or may not be in
their final state. If you do not have an account there or are not
displayed the option of downloading the prerelease, then I don't think
so, no.


Christopher

Subject: Symbolic toolbox - "chain rule"

From: Nasser M. Abbasi

Date: 17 Feb, 2012 21:28:49

Message: 7 of 9

On 2/17/2012 9:42 AM, Christopher Creutzig wrote:
> On 17.02.12 10:47, Nasser M. Abbasi wrote:
>> On 2/17/2012 2:12 AM, Christopher Creutzig wrote:
>>
>>> That's the nice way of doing it, but requires 2012a (prerelease). The
>>> “old” way, if Michal doesn't have the shiny new toys ;-), would be
>>
>> hi;
>>
>> Is it possible to read somewhere on what will be new in Matlab 2012a?
>

> Log in to mathworks.com, go to “My Account” and check out the 2012a
> prerelease, which includes release notes, which may or may not be in
> their final state. If you do not have an account there or are not
> displayed the option of downloading the prerelease, then I don't think
> so, no.


I logged in my account now, but I do not see 2012a anywhere. I looked
into http://www.mathworks.com/products/ also, and nothing there. I only
see R2011b.

Where exactly is it? I do not see any mention of 2012a. Is it
becuase I am student I do not see it even though I am logged in?

thanks,
--Nasser

Subject: Symbolic toolbox - "chain rule"

From: alonsovg

Date: 3 Oct, 2012 02:38:07

Message: 8 of 9

Hi Christopher,

do you know if there is a way to make that Matlab treats the results from diff(L(t),t) as a symbolic argument.

I would like to after getting

sin(fi(t))*diff(L(t), t) + cos(fi(t))*L(t)*diff(fi(t), t)

solve the equation for say diff(L(t), t) ,

assuming sin(fi(t))*diff(L(t), t) + cos(fi(t))*L(t)*diff(fi(t), t)=0 for example.

Thank you!
Alonso


Christopher Creutzig <Christopher.Creutzig@mathworks.com> wrote in message <4F3E0BD8.6010509@mathworks.com>...
> On 16.02.12 22:15, Alan Weiss wrote:
> > On 2/16/2012 1:39 PM, Michal Lukac wrote:
> >> Hello, how to apply chain rule with symbolic toolbox.
> >>
> >> I have an expression e.g.:
> >> L(t)*sin(fi(t)) and need to differentiate with respect to t
>
> > syms fi(t)
> > syms L(t)
>
> That's the nice way of doing it, but requires 2012a (prerelease). The
> “old” way, if Michal doesn't have the shiny new toys ;-), would be
>
> >> diff(sym('L(t)*sin(fi(t))'))
>
> ans =
>
> sin(fi(t))*diff(L(t), t) + cos(fi(t))*L(t)*diff(fi(t), t)
>
>
>
> Christopher

Subject: Symbolic toolbox - "chain rule"

From: Christopher Creutzig

Date: 30 Oct, 2012 14:44:37

Message: 9 of 9

On 03.10.12 04:38, alonsovg wrote:
> Hi Christopher,
>
> do you know if there is a way to make that Matlab treats the results from diff(L(t),t) as a symbolic argument.
>
> I would like to after getting
>
> sin(fi(t))*diff(L(t), t) + cos(fi(t))*L(t)*diff(fi(t), t)
>
> solve the equation for say diff(L(t), t) ,
>
> assuming sin(fi(t))*diff(L(t), t) + cos(fi(t))*L(t)*diff(fi(t), t)=0 for example.

You could always temporarily replace such an expression by a new name:

>> syms fi(t) L(t)
>> term = sin(fi(t))*diff(L(t), t) + cos(fi(t))*L(t)*diff(fi(t), t)

term =

sin(fi(t))*diff(L(t), t) + cos(fi(t))*L(t)*diff(fi(t), t)

>> syms dfi dL
>> solve(subs(term, [diff(fi(t), t), diff(L(t), t)], [dfi, dL]), dL)

ans =

-(dfi*cos(fi(t))*L(t))/sin(fi(t))

>> subs(ans, dfi, diff(fi(t), t))

ans =

-(cos(fi(t))*L(t)*diff(fi(t), t))/sin(fi(t))


HTH,
Christopher

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us