How can I create a 5x5 matrix with the following criterion: aij = 2cos(0.4(i-j)π)

 Accepted Answer

A bit more efficiently, using meshgrid:
[i,j] = meshgrid(1:5);
a = 2*cos(0.4*(i-j)*pi);

2 Comments

Thank you very much. It works out great!
My pleasure!
The meshgrid function can make a number of matrix calculations easier.

Sign in to comment.

More Answers (1)

jgg
jgg on 12 Feb 2016
Try this
A = 2*cos(0.4.*pi.*(repmat([1:5]',1,5) - repmat([1:5],5,1)));

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!