Differential Operator in Matlab in 1 Dimension
48 次查看(过去 30 天)
显示 更早的评论
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 个评论
asdsa sad
2022-1-7
Have you solved this problem? Is there a suitable way to express differential operators? I need d2/dt2
Walter Roberson
2022-1-7
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
2021-12-12
You would need to create a new MATLAB class to handle everything related to this. MATLAB has no support for this built-in.
0 个评论
更多回答(1 个)
Chris
2021-12-12
编辑:Chris
2021-12-12
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 个评论
Walter Roberson
2021-12-12
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!