No BSD License  

Highlights from
fulldiff.m

4.66667

4.7 | 6 ratings Rate this file 29 Downloads (last 30 days) File Size: 6.02 KB File ID: #7174
image thumbnail

fulldiff.m

by Tim Jorris

 

17 Mar 2005 (Updated 03 Mar 2006)

Symbolically computes full derivative wrt time using chain rule and time variables.

| Watch this File

File Information
Description

Symbolically computes full time derivative of given function and time dependant variables. It's an expansion of the partial derivative functionality of DIFF. Chain rule application automatically creates necessary higher order derivatives. Only base dependent variable need to be input, eg {x y}, dx and dy, etc. are assumed time dependant and d2x and d2y are created if required. This is motivated by the combination of partial derivative and full derivative required to compute Lagrange?s equations of motion.

Acknowledgements
This submission has inspired the following:
ddt, Dynamics Simulator for Kinematic Chains
Required Products Symbolic Math Toolbox
MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
03 Feb 2006 Bruno Guerreiro

This function is extremly useful!

However I think I found a bug. Try this sequence and observe that the two last lines should give the same result:

syms m g R a real; y = 1/m*R*a + g; fulldiff(y,{R,a},2)
syms m g R a real; y = 1/m*R*a + g; fulldiff(y,{R,a},3)
syms m g R dR d2R a da d2a real; d2y = 2/m*da*dR+1/m*a*d2R+1/m*R*d2a; fulldiff(d2y,{R,a})

According to my calculus, only the last result is correct. I conclude that there's a bug with the multiple derivatives.

Matlab should think of including this kind of calculus into the symbolic toolbox, as well as "undefined" matrix and vector symbolic calculus.

20 Nov 2006 Daichi Nozaki  
29 Nov 2006 Francesco Igino Cosco

thank to your code I was able to do my work without translate my code in Mathematica.

01 Feb 2007 Peter Pott

Hi Tim,

this piece of code seems to be the answer to all my (matlab) problems! But it produces an error message:
??? Undefined function or variable 'true'.
Error in ==> C:\path\fulldiff.m
On line 87 ==> while true
Is it a matlab-release-numer incompatibility or my fault?

Best regards

Peter
(pppott_at_web.de)

20 Jun 2008 Scott Boynton

Very nicely done and effective. I'm also working with the Lagrange equations and it saved me a lot of time. Thank you.

22 Aug 2011 Bassam Jalgha

Really useful! I just used your code to develop a dynamics simulator for kinematic chains.

08 Apr 2012 Amr

I am having a problem running this code on Matlab 2010a.
I even tried the example in the mfile
clc
clear all
close all
 syms x y dx d2y

 f = x*y*(dx^2)*(d2y)
 fulldiff(f) % (assumes x only) produces
 % 3
 % y dx d2y + 2 x y dx d2y d2x
 % whereas
 fulldiff(f,{x, y}) % produces
 % 3 2 2
 % y dx d2y + 2 x y dx d2y d2x + x dx d2y dy + x y dx d3y
But I keep getting the following error:
??? Error using ==> strfind
Inputs must be character arrays.

Error in ==> fulldiff>findhigher at 153
cid=strfind(allvar,',');

Error in ==> fulldiff at 120
    dvars=findhigher(fun,vars,dvars);

Please advise

Please login to add a comment or rating.
Updates
28 Mar 2005

Improved to properly captures higher (>2) order derivatives

03 Mar 2006

Bug fixed identified by Bruno in review. Both methods of 3rd order derivative now match (3rd of 1st and 1st of 2nd).

Tag Activity for this File
Tag Applied By Date/Time
symbolic math Tim Jorris 22 Oct 2008 07:43:35
full Tim Jorris 22 Oct 2008 07:43:35
derivative Tim Jorris 22 Oct 2008 07:43:35
diff Tim Jorris 22 Oct 2008 07:43:35
partial Tim Jorris 22 Oct 2008 07:43:35
time Tim Jorris 22 Oct 2008 07:43:35
symbolic Tim Jorris 22 Oct 2008 07:43:35

Contact us at files@mathworks.com