How to overcome the problem with the function diff used to approximate matrix derivative.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I have an issue using diff function to calculate the derivative of a matrix.
Using diff(X), where X is a matrix m x n matrix, I obtain in output a matrix with m-1 rows. The problem is that I need to concatenate the result of the derivative operation with the X matrix along the columns. In other words, I need to obtain a m x 2n matrix where the first n columns are referring to the X matrix and the last n columns are referring to the derivatives of X's columns along the rows.
How can I deal with this problem? Is it rigth to add a row of zeros before applying the diff function or after applying it in order to have the same numebr of rows before concatenating?
1 comentario
Bjorn Gustavsson
el 20 de Mayo de 2022
For this you have to decide what your application of this requires. What are you trying to achieve? what will you use that final matrix for? Maybe you can use what you suggested, maybe you could use the gradient function instead and have central differences in the main part and single-sided differences along the edge. Only you can decide, since only you know what the use-case is.
Respuestas (1)
Ver también
Categorías
Más información sobre Calculus en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!