reshaping multi dimensional array and central difference method
Show older comments
Hello members,
I have the arrays
A1=[-1.1, -1, -0.9, -0.1, 0, 0.1, 0.9, 1, 1.1];
A2=[-1.1, -1, -0.9, -0.1, 0, 0.1, 0.9, 1, 1.1];
I create a 2D grid using these arrays, like below in this image(just for presentation. I mean, I have a gridded data in workspace).

I have matrix data at all these grid points (at both dark and smaller dots). I want to apply central difference scheme for matrices at dark dots. For example, lets say my matrix is 'T'. To get T_dot at (-1,-1) I have to write
T_dot(-1,-1)= (T(-0.9,-1)-T(-1.1,-1))/0.2... % Central difference applied in 2 direction
+ (T(-1,-0.9)-T(-1,-1.1))/0.2
Hence,I want derivatives of T at all these dark dots(That is for 9 points here in the image).
T_dot(0,-1) = ...
.
.
T_dot(1,1) = ...
I want to automate this for N dimensional grids. The array value will be same in all direction. So how can I write a flexible code for this in MATLAB? My bet would be on using ndgrid, reshape functions and using a single for loop and later reshape it back. But I am kind of stuck with writing indices in the loop.
Could you kindly help me?
Thanks a lot
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!