Why I am not getting anything from the plot?

The plot is supposed to be two waves x1_rec and x2_rec. But I am not getting anything from the code. Can anyone please elaborate why?
clear all; close all; clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Simulation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%value of constants
a1=0.1;a2=0.2;
omega1=5;omega2=4;
G=1;C12=0.01;C21=0.02;
dt=0.01; %step size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x1(1)=0.5;
y1(1)=0.5;
x2(1)=1;
y2(1)=1;
for i=2:1000
x1(i)=x1(i-1)+((a1-x1(i-1)^2-y1(i-1)^2)*x1(i-1)-omega1*y1(i-1)+G*C12*(x2(i-1)-x1(i-1)))*dt;
y1(i)=y1(i-1)+((a1-x1(i-1)^2-y1(i-1)^2)*y1(i-1)+omega1*x1(i-1)+G*C12*(y2(i-1)-y1(i-1)))*dt;
x2(i)=x2(i-1)+((a2-x2(i-1)^2-y2(i-1)^2)*x2(i-1)-omega2*y2(i-1)+G*C21*(x1(i-1)-x2(i-1)))*dt;
y2(i)=y2(i-1)+((a2-x2(i-1)^2-y2(i-1)^2)*y2(i-1)+omega2*x2(i-1)+G*C21*(y1(i-1)-y2(i-1)))*dt;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Observation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N_measurements=31;
N_basis=31;
index=randi([100,999],1,N_measurements);
Xdot1=zeros([1,N_measurements]);
Ydot1=zeros([1,N_measurements]);
Xdot2=zeros([1,N_measurements]);
Ydot2=zeros([1,N_measurements]);
for ni=1:N_measurements
Xdot1(ni)=(x1(index(ni)+1)-x1(index(ni)))/dt;
Ydot1(ni)=(y1(index(ni)+1)-y1(index(ni)))/dt;
Xdot2(ni)=(x2(index(ni)+1)-x2(index(ni)))/dt;
Ydot2(ni)=(y2(index(ni)+1)-y2(index(ni)))/dt;
end
M=zeros([N_measurements,N_basis]);
for i=1:N_measurements
for j=1:N_basis
if j==1
M(i,j)=1;
elseif j==2
M(i,j)=x1(index(i));
elseif j==3
M(i,j)=y1(index(i));
elseif j==4
M(i,j)=x2(index(i));
elseif j==5
M(i,j)=y2(index(i));
elseif j==6
M(i,j)=x1(index(i))^2;
elseif j==7
M(i,j)=x2(index(i))^2;
elseif j==8
M(i,j)=y1(index(i))^2;
elseif j==9
M(i,j)=y2(index(i))^2;
elseif j==10
M(i,j)=x1(index(i))*x2(index(i));
elseif j==11
M(i,j)=x1(index(i))*y1(index(i));
elseif j==12
M(i,j)=x1(index(i))*y2(index(i));
elseif j==13
M(i,j)=x2(index(i))*y1(index(i));
elseif j==14
M(i,j)=x2(index(i))*y2(index(i));
elseif j==15
M(i,j)=y1(index(i))*y2(index(i));
elseif j==16
M(i,j)=x1(index(i))^3;
elseif j==17
M(i,j)=y1(index(i))^3;
elseif j==18
M(i,j)=x2(index(i))^3;
elseif j==19
M(i,j)=y2(index(i))^3;
elseif j==20
M(i,j)=x1(index(i))^2*x2(index(i));
elseif j==21
M(i,j)=x1(index(i))^2*y1(index(i));
elseif j==22
M(i,j)=x1(index(i))^2*y2(index(i));
elseif j==23
M(i,j)=x2(index(i))^2*x1(index(i));
elseif j==24
M(i,j)=x2(index(i))^2*y1(index(i));
elseif j==25
M(i,j)=x2(index(i))^2*y2(index(i));
elseif j==26
M(i,j)=y1(index(i))^2*x1(index(i));
elseif j==27
M(i,j)=y1(index(i))^2*x2(index(i));
elseif j==28
M(i,j)=y1(index(i))^2*y2(index(i));
elseif j==29
M(i,j)=y2(index(i))^2*x1(index(i));
elseif j==30
M(i,j)=y2(index(i))^2*x2(index(i));
else j==31
M(i,j)=y2(index(i))^2*y1(index(i));
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% RIP %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Norms=zeros([1,N_basis]);
for j=1:N_basis
Norms(j)=norm(M(:,j));
end
for i=1:N_measurements
for j=1:N_basis
M(i,j)=M(i,j)/Norms(j);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x1_rec(1)= x1(1);
x2_rec(1)= x2(1);
y1_rec(2)= y1(1);
y2_rec(2)= y2(1);
a1=0.0000;
a2=0.0900;
a3=-5.0000;
a4=0.0100;
a5=0.0000;
a6=0.0000;
a7=0.0000;
a8=0.0000;
a9=0.0000;
a10=0.0000;
a11=0.0000;
a12=0.0000;
a13=0.0000;
a14=0.0000;
a15=0.0000;
a16=-1.0000;
a17=0.0000;
a18=0.0000;
a19=0.0000;
a20=0.0000;
a21=0.0000;
a22=0.0000;
a23=0.0000;
a24=0.0000;
a25=0.0000;
a26=-1.0000;
a27=0.0000;
a28=0.0000;
a29=0.0000;
a30=0.0000;
a31=0.0000;
%b=y1
b1=0.0000;
b2=5.0000;
b3=0.0900;
b4=0.0000;
b5=0.0100;
b6=0.0000;
b7=0.0000;
b8=0.0000;
b9=0.0000;
b10=0.0000;
b11=0.0000;
b12=0.0000;
b13=0.0000;
b14=0.0000;
b15=0.0000;
b16=0.0000;
b17=-1.0000;
b18=0.0000;
b19=0.0000;
b20=0.0000;
b21=-1.0000;
b22=0.0000;
b23=0.0000;
b24=0.0000;
b25=0.0000;
b26=0.0000;
b27=0.0000;
b28=0.0000;
b29=0.0000;
b30=0.0000;
b31=0.0000;
%c=x2
c1=0.0000;
c2=0.0200;
c3=0.0000;
c4=0.1800;
c5=-4.0000;
c6=0.0000;
c7=0.0000;
c8=0.0000;
c9=0.0000;
c10=0.0000;
c11=0.0000;
c12=0.0000;
c13=0.0000;
c14=0.0000;
c15=0.0000;
c16=0.0000;
c17=0.0000;
c18=-1.0000;
c19=0.0000;
c20=0.0000;
c21=0.0000;
c22=0.0000;
c23=0.0000;
c24=0.0000;
c25=0.0000;
c26=0.0000;
c27=0.0000;
c28=0.0000;
c29=0.0000;
c30=-1.0000;
c31=0.0000;
%d=y2
d1=0.0000;
d2=0.0000;
d3=0.0200;
d4=4.0000;
d5=0.1800;
d6=0.0000;
d7=0.0000;
d8=0.0000;
d9=0.0000;
d10=0.0000;
d11=0.0000;
d12=0.0000;
d13=0.0000;
d14=0.0000;
d15=0.0000;
d16=0.0000;
d17=0.0000;
d18=0.0000;
d19=-1.0000;
d20=0.0000;
d21=0.0000;
d22=0.0000;
d23=0.0000;
d24=0.0000;
d25=-1.0000;
d26=0.0000;
d27=0.0000;
d28=0.0000;
d29=0.0000;
d30=0.0000;
d31=0.0000;
for i=2:32
y1_rec(i)= b1+b2*x1_rec(i-1)+b3*y1_rec(i-1)+b4*x2_rec(i-1)+b5*y2_rec(i-1)+b6*x1_rec(i-1)^2+b7*x2_rec(i-1)^2+b8*y1_rec(i-1)^2+b9*y2_rec(i-1)^2+b10*x1_rec(i-1)*x2_rec(i-1)+b11*x1_rec(i-1)*y1_rec(i-1)+b12*x1_rec(i-1)*y2_rec(i-1)+b13*x2_rec(i-1)*y1_rec(i-1)+b14*x2_rec(i-1)*y2_rec(i-1)+b15*y1_rec(i-1)*y2_rec(i-1)+b16*x1_rec(i-1)^3+b17*y1_rec(i-1)^3+b18*x2_rec(i-1)^3+b19*y2_rec(i-1)^3+b20*x1_rec(i-1)^2*x2_rec(i-1)+b21*x1_rec(i-1)^2*y1_rec(i-1)+b22*x1_rec(i-1)^2*y2_rec(i-1)+b23*x2_rec(i-1)^2*x1_rec(i-1)+b24*x2_rec(i-1)^2*y1_rec(i-1)+b25*x2_rec(i-1)^2*y2_rec(i-1)+b26*y1_rec(i-1)^2*x1_rec(i-1)+b27*y1_rec(i-1)^2*x2_rec(i-1)+b28*y1_rec(i-1)^2*y2_rec(i-1)+b29*y2_rec(i-1)^2*x1_rec(i-1)+b30*y2_rec(i-1)^2*x2_rec(i-1)+b31*y2_rec(i-1)^2*y1_rec(i-1);
y2_rec(i)= d1+d2*x1_rec(i-1)+d3*y1_rec(i-1)+d4*x2_rec(i-1)+d5*y2_rec(i-1)+d6*x1_rec(i-1)^2+d7*x2_rec(i-1)^2+d8*y1_rec(i-1)^2+d9*y2_rec(i-1)^2+d10*x1_rec(i-1)*x2_rec(i-1)+d11*x1_rec(i-1)*y1_rec(i-1)+d12*x1_rec(i-1)*y2_rec(i-1)+d13*x2_rec(i-1)*y1_rec(i-1)+d14*x2_rec(i-1)*y2_rec(i-1)+d15*y1_rec(i-1)*y2_rec(i-1)+d16*x1_rec(i-1)^3+d17*y1_rec(i-1)^3+d18*x2_rec(i-1)^3+d19*y2_rec(i-1)^3+d20*x1_rec(i-1)^2*x2_rec(i-1)+d21*x1_rec(i-1)^2*y1_rec(i-1)+d22*x1_rec(i-1)^2*y2_rec(i-1)+d23*x2_rec(i-1)^2*x1_rec(i-1)+d24*x2_rec(i-1)^2*y1_rec(i-1)+d25*x2_rec(i-1)^2*y2_rec(i-1)+d26*y1_rec(i-1)^2*x1_rec(i-1)+d27*y1_rec(i-1)^2*x2_rec(i-1)+d28*y1_rec(i-1)^2*y2_rec(i-1)+d29*y2_rec(i-1)^2*x1_rec(i-1)+d30*y2_rec(i-1)^2*x2_rec(i-1)+d31*y2_rec(i-1)^2*y1_rec(i-1);
x1_rec(i)= a1+a2*x1_rec(i-1)+a3*y1_rec(i-1)+a4*x2_rec(i-1)+a5*y2_rec(i-1)+a6*x1_rec(i-1)^2+a7*x2_rec(i-1)^2+a8*y1_rec(i-1)^2+a9*y2_rec(i-1)^2+a10*x1_rec(i-1)*x2_rec(i-1)+a11*x1_rec(i-1)*y1_rec(i-1)+a12*x1_rec(i-1)*y2_rec(i-1)+a13*x2_rec(i-1)*y1_rec(i-1)+a14*x2_rec(i-1)*y2_rec(i-1)+a15*y1_rec(i-1)*y2_rec(i-1)+a16*x1_rec(i-1)^3+a17*y1_rec(i-1)^3+a18*x2_rec(i-1)^3+a19*y2_rec(i-1)^3+a20*x1_rec(i-1)^2*x2_rec(i-1)+a21*x1_rec(i-1)^2*y1_rec(i-1)+a22*x1_rec(i-1)^2*y2_rec(i-1)+a23*x2_rec(i-1)^2*x1_rec(i-1)+a24*x2_rec(i-1)^2*y1_rec(i-1)+a25*x2_rec(i-1)^2*y2_rec(i-1)+a26*y1_rec(i-1)^2*x1_rec(i-1)+a27*y1_rec(i-1)^2*x2_rec(i-1)+a28*y1_rec(i-1)^2*y2_rec(i-1)+a29*y2_rec(i-1)^2*x1_rec(i-1)+a30*y2_rec(i-1)^2*x2_rec(i-1)+a31*y2_rec(i-1)^2*y1_rec(i-1);
x2_rec(i)= c1+c2*x1_rec(i-1)+c3*y1_rec(i-1)+c4*x2_rec(i-1)+c5*y2_rec(i-1)+c6*x1_rec(i-1)^2+c7*x2_rec(i-1)^2+c8*y1_rec(i-1)^2+c9*y2_rec(i-1)^2+c10*x1_rec(i-1)*x2_rec(i-1)+c11*x1_rec(i-1)*y1_rec(i-1)+c12*x1_rec(i-1)*y2_rec(i-1)+c13*x2_rec(i-1)*y1_rec(i-1)+c14*x2_rec(i-1)*y2_rec(i-1)+c15*y1_rec(i-1)*y2_rec(i-1)+c16*x1_rec(i-1)^3+c17*y1_rec(i-1)^3+c18*x2_rec(i-1)^3+c19*y2_rec(i-1)^3+c20*x1_rec(i-1)^2*x2_rec(i-1)+c21*x1_rec(i-1)^2*y1_rec(i-1)+c22*x1_rec(i-1)^2*y2_rec(i-1)+c23*x2_rec(i-1)^2*x1_rec(i-1)+c24*x2_rec(i-1)^2*y1_rec(i-1)+c25*x2_rec(i-1)^2*y2_rec(i-1)+c26*y1_rec(i-1)^2*x1_rec(i-1)+c27*y1_rec(i-1)^2*x2_rec(i-1)+c28*y1_rec(i-1)^2*y2_rec(i-1)+c29*y2_rec(i-1)^2*x1_rec(i-1)+c30*y2_rec(i-1)^2*x2_rec(i-1)+c31*y2_rec(i-1)^2*y1_rec(i-1);
end
figure
hold on
plot(x1_rec,'Y')
plot(x2_rec,'b')

5 Comments

Are you not getting anything, or not getting what you expected? When I run it, I get the following plot (Note that yellow is really hard to see).
Do you mean "waves" like a oscillating wave like sin or cos, or "waveforms" like some arbitrary signal like the one Cris says your code produces?
Why do you say "I am not getting anything" when it clearly DOES produce a plot?
But they WOULDN'T spend time getting on HERE to ask the QUESTION, right? So IT doesn't WORK on THEIR side, right?
Without a clear description of what 'not working' means, we tend to assume the code will result in an error or an empty plot. Neither is the case here. So either it does work, or the OP should describe what is actually the problem.
With such a large number of numbered variables it is not hard to imagine there is a typo somewhere in there resulting in an unexpected shape of the graph. The first line of code is also a 'code smell'.
The waves should be like this but I am getting the straight lines.

Sign in to comment.

Answers (0)

Asked:

on 8 Dec 2020

Commented:

on 9 Dec 2020

Community Treasure Hunt

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

Start Hunting!