0

I'm going to perform some symbolic calculus for a project and I'm starting with something simple. I'm ttrying to calculate the derivative of L function in respect to variable fi, but using the following code I get the error shown.

syms x(t) y(t) fi(t) m IR t;

L = 1/2*(m*(diff(x(t),t)^2+diff(y(t),t)^2) + IR*diff(fi(t),t)^2)
D1 = diff(L,diff(fi(t),t))

ERROR: Error using sym/diff (line 70) Second argument must be a variable or a nonnegative integer specifying the number of differentiations.

Could anyone tell me what's going on? Thanks. [1]: https://i.stack.imgur.com/fTpEM.png

  • @PeterSmith I solved the problem differently by using a different matlab version. The post post referred to matlab2018a, now I'm using 2020b and it works perfectly. In any case I'm still interested in your reply and i guess i could have solved the problem with this: L = 1/2*(m*(diff(x(t),t)^2+diff(y(t),t)^2) + IR*diff(fi(t),t)^2) fidot = diff(fi(t),t) D1 = diff(L,diff(fi(t),t)) Is it correct? – Michelangelo Festa Dec 01 '20 at 16:26

1 Answers1

0

You have a nested diff in the second line. For the outer diff, the second argument cannot be the inner diff - it should be a variable or non-negative integer.

falopsy
  • 636
  • 7
  • 16