Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Column Circulant Matrix

A circulant matrix is a square matrix generated from a vector as the first row (or column). Successive rows use the same elements as the first row, but each such row is circularly shifted by one element.

For more detail , check the below link:


Problem Statement:

Create a matrix X, where each column is a shifted copy of the vector v

in->v = (1:5)';
v=
     1
     2
     3
     4
     5
out-> [1 5 4 3 2;2 1 5 4 3;3 2 1 5 4;4 3 2 1 5;5 4 3 2 1]
     1     5     4     3     2
     2     1     5     4     3
     3     2     1     5     4
     4     3     2     1     5
     5     4     3     2     1



MATLAB CODE:

clc
clear all
close all
z=[];
h=input('Enter the array:');
z=[z h'];
a=h;
for i=1:length(h)-1
    a=ci(a);
    z=[z a'];
end
disp(z);


Function :

function a=ci(m)
x1=m;
a=[];
c=length(x1);
a=[a x1(c)];
for i=1:length(x1)-1
    a=[a x1(i)];
end
end

Explanation:




Output:



[Try with other inputs :-)]

No comments

Popular Posts

Followers