# Differential Operator in Matlab in 1 Dimension

63 views (last 30 days)
MarshallSc on 12 Dec 2021
Commented: Walter Roberson on 7 Jan 2022
In common, the differential operation is defined as "dy/dx" which means differentiate y with respect to x and in matlab it's defined by "diff()". But how can we define "d/dx" which means differentiate with respect to x. Basically it shows an operation in 1 dimension rather 2. This definition is used in many fields such as Einstein theories and geometry. For example, If we have a scalar as [a1] in initial point and [a2] at the secondary position, d/dx denotes how much a2 changed with respect to a1. Does Matlab has a specific operator for this or any way that we can define it so that it can be used in higher order differential equations?
There was a post here:
But there was no correct answer.
I'd appreciate any opinions!
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 7 Jan 2022
No, there is no way in MATLAB to express differential operators without writing your own class or writing functions on top of the Symbolic Toolbox

Walter Roberson on 12 Dec 2021
You would need to create a new MATLAB class to handle everything related to this. MATLAB has no support for this built-in.

Chris on 12 Dec 2021
Edited: Chris on 12 Dec 2021
I'm not a math major so there's probably something technically wrong about this statement, but "d/dx" is essentially "dy/dx", replacing y with an arbitrary function of x. The only operators Matlab has by default are listed here. Most everything else is a function, which means the code it operates on likely needs to be enclosed in parentheses.
If you're using the symbolic toolbox, I believe the diff function should suffice for what you're asking. You could also define an inline function to describe exactly the derivative you want.
syms y(x,z) x z
y = x^2 + 5*z;
diff(y) % d/dx
ans =
diff(y,z) % d/dz
ans =
5
ddz = @(a) diff(a,z); % Inline d/dz
ddz(y)
ans =
5
There is also the numerical (vs. symbolic) diff, which might work for the situation you describe:
h = 2; % Step size
aa = [5,10,14]; % Vector of values
ddx = diff(aa)/h
ddx = 1×2
2.5000 2.0000
Some common items that employ derivatives are the Jacobian and the Hessian
##### 2 CommentsShowHide 1 older comment
MarshallSc on 12 Dec 2021
Thanks @Chris for your answer. I'm looking at it from the perspective @Walter Roberson, in a sense, just described. It is related to the measuring distances in Manifolds (Geodesics) that does not consider extrinsic view of the system, instead intrinsic properites are considered. In which, a differential equation is given and the possible solutions which are basis vectors (due to the lack of existance of position vectors) are analyzed (with assuming 2D basis vectors embedded in the coordinate information).

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!