Differential Operator in Matlab in 1 Dimension
57 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MarshallSc
el 12 de Dic. de 2021
Comentada: Walter Roberson
el 7 de En. de 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 comentarios
asdsa sad
el 7 de En. de 2022
Have you solved this problem? Is there a suitable way to express differential operators? I need d2/dt2
Walter Roberson
el 7 de En. de 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
Respuesta aceptada
Walter Roberson
el 12 de Dic. de 2021
You would need to create a new MATLAB class to handle everything related to this. MATLAB has no support for this built-in.
0 comentarios
Más respuestas (1)
Chris
el 12 de Dic. de 2021
Editada: Chris
el 12 de Dic. de 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
diff(y,z) % d/dz
ddz = @(a) diff(a,z); % Inline d/dz
ddz(y)
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
2 comentarios
Walter Roberson
el 12 de Dic. de 2021
The poster is referring to a branch of mathematics which deals with "operators" that look like expressions. One of the common ways of writing the differential operator is D . Something like
(D+2*D^2+1) * (sin(x))
would be intended to mean
diff(sin(x),x) + 2 * diff(sin(x),x,x) + sin(x)
but the (D+2*D^2 +1) would be held in a variable (or array), not as a function handle or symbolic function, and application of the derivatives would be by using the multiplication operator.
You can, in part, use symbolic expressions in a variable named D, but at some point you need to apply the derivative operations.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!