Dear all,
I'm writing a code to solve a system of PDEs with finite differencing. I'm using a two dimensional grid, with one spatial and one time dimension and I'm using arrays with two indices for my physical variables (e.g. R(i,n), where i is the spatial and n is the time index). Some of the arrays have to be averaged to give a value at a half grid point (e.g. (R(i+1,n)+R(i,n))/2 ). Since I have to do this for many functions, I would like to define the averaging function such that it accepts any array and returns me the averaged value. I tried using a placeholder variable "a" for the arrays and tested it for a one dimensional array like this:
function testreturn = test_average(n,a)
t_n = (a(n+2)+a(n+1))/2.;
testreturn = t_n;
end
But when I replace "a" by an array, I'm getting the error: "Undefined function 'test_average' for input arguments of type 'double'." I would appreciate any tips :) I guess the solution is quite easy, but it is my first time programming with Matlab and I'm still getting used to it.
Thank you all