Search code examples
matlabmatrixspectral

Matlab - Spectral Method (Matrix Syntax)


I'm reading Trefethen's Spectral Methods in Matlab.

When creating the differentiation matrices,

column= [ anything ]

D=toeplitz(column,column([1 N:-1:2]))

Can someone please explain what exactly is happening inside the [ ... ] in the line above.

I understand you are shifting the columns but I don't understand that syntax.


Solution

  • Are you referring to the 2nd line with: [1 N:-1:2] ?

    If so, lets look at an example, let N = 4 and just calculate:

    N = 4; [1 N:-1:2]

    ans =

     1     4     3     2
    

    Which creates a vector with the first element being 1. Next the values start at 4 and decrement by 1 until you reach 2.

    This is a basic Matlab syntax, [a:b:c], creates a vector with starting value a, increasing (or decreasing if -b) to c in steps of b.

    Is this what you are referring to?