Closed HayaaAli closed 3 years ago
Hi, I am trying to resolve this issue since past two weeks. Please help me to modify the code or error. Many thanks.
close all; clear all; clc; %initializing x,y,t h=0.01; %step size t=0:h:300; x1 = zeros(1,numel(t)); y1 = x1; x2 = x1; y2 = x1; x1(1)=1; y1(1)=1; x2(1)=2; y2(1)=2; %value of constants a=0.1; b=0.3; omega=4; Cnp=0.2; G=1; %ode p=@(x1,y1,x2,y2) (a-x1^2-y1^2)x1-omegay1+GCnp(x2-x1); q=@(x1,y1,x2,y2) (a-x1^2-y1^2)y1+omegax1+GCnp(y2-y1); %loop for i=1:(length(t)-1) k1=p(x1(i),y1(i),x2(i),y2(i)); l1=q(x1(i),y1(i),x2(i),y2(i));
k2=p((x1(i)+(h/2)*k1),(y1(i)+(h/2)*l1),(x2(i)+(h/2)*k1),(y2(i)+(h/2)*l1)); l2=q((x1(i)+(h/2)*k1),(y1(i)+(h/2)*l1),(x2(i)+(h/2)*k1),(y2(i)+(h/2)*l1)); k3=p((x1(i)+(h/2)*k2),(y1(i)+(h/2)*l2),(x2(i)+(h/2)*k2),(y2(i)+(h/2)*l2)); l3=q((x1(i)+(h/2)*k2),(y1(i)+(h/2)*l2),(x2(i)+(h/2)*k2),(y2(i)+(h/2)*l2)); k4=p((x1(i)+k3*h),(y1(i)+l3*h),(x2(i)+k3*h),(y2(i)+l3*h)); l4=q((x1(i)+k3*h),(y1(i)+l3*h),(x2(i)+k3*h),(y2(i)+l3*h)); x1(i+1) = x1(i) + h*(k1+2*k2+2*k3+k4)/6; y1(i+1) = y1(i) + h*(l1+2*l2+2*l3+l4)/6; x2(i+1) = x2(i) + h*(k1+2*k2+2*k3+k4)/6; y2(i+1) = y2(i) + h*(l1+2*l2+2*l3+l4)/6;
end %draw plot(t,x1,'r',t,x2,'y') xlabel('t','fontsize',14,'fontweight','bold') ylabel('x1 & x2','fontsize',14,'fontweight','bold') set(gca,'Color','k') legend('x1','x2','TextColor','w') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% x1=x1(101:300); y1=y1(101:300); x2=x2(101:300); y2=y2(101:300); X1dot=(x1(2:101)-x1(1:100))/h; X2dot=(x2(2:101)-x2(1:100))/h; Y1dot=(y1(2:101)-y1(1:100))/h; Y2dot=(y2(2:101)-y2(1:100))/h; hold on M=zeros([100,10]); for i=1:100 for j=1:32 if j==1 M(i,j)=1; elseif j==2 M(i,j)=x1(i); elseif j==3 M(i,j)=x2((i)); elseif j==4 M(i,j)=y1((i)); elseif j==5 M(i,j)=y2((i)); elseif j==6 M(i,j)=x1(i)x2(i); elseif j==7 M(i,j)=y1((i))y2((i)); elseif j==8 M(i,j)=x1((i))y1((i)); elseif j==9 M(i,j)=x1((i))y2((i)); elseif j==10 M(i,j)=x2((i))y1((i)); elseif j==11 M(i,j)=x2((i))y2((i)); elseif j==12 M(i,j)=x1(i)x2(i)y1(i); elseif j==13 M(i,j)=x1(i)x2(i)y2(i); elseif j==14 M(i,j)=x1(i)y1(i)y2(i); elseif j==15 M(i,j)=x2(i)y1(i)y2(i); elseif j==16 M(i,j)=x1(i)x2(i)y1(i)y2(i); elseif j==17 M(i,j)=x1(i)^2; elseif j==18 M(i,j)=x2(i)^2; elseif j==19 M(i,j)=y1(i)^2; elseif j==20 M(i,j)=y2(i)^2; elseif j==21 M(i,j)=x1(i)^2x2(i); elseif j==22 M(i,j)=x1(i)^2y1(i); elseif j==23 M(i,j)=x1(i)^2y2(i); elseif j==24 M(i,j)=x2(i)^2x1(i); elseif j==25 M(i,j)=x2(i)^2y1(i); elseif j==26 M(i,j)=x2(i)^2y2(i); elseif j==27 M(i,j)=y1(i)^2x1(i); elseif j==28 M(i,j)=y1(i)^2x2(i); elseif j==29 M(i,j)=y1(i)^2y2(i); elseif j==30 M(i,j)=y2(i)^2x1(i); elseif j==31 M(i,j)=y2(i)^2x2(i); else M(i,j)=y2(i)^2y1(i); end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Reconstructed Signal % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% x1_rec(1)=x1(1); y1_rec(1)=y1(1); x2_rec(1)=x2(1); y2_rec(1)=y2(1); %value of constants %a1=x1 a1=0.0305; a2=0.0000; a3=0.0000; a4=-3.2154; a5=0.0000; a6=0.0000; a7=0.0000; a8=0.0000; a9=0.0000; a10=-0.5857; a11=0.0000; a12=0.0000; a13=0.0000; a14=0.0000; a15=0.0000; a16=0.0000; a17=0.0000; a18=0.0000; a19=0.0000; a20= 0.2412; a21=0.0000; a22=0.0000; a23=0.0000; a24=0.0000; a25=0.0000; a26=0.0000; a27=0.0000; a28=0.0000; a29=0.0000; a30=0.0000; a31=0.0000; a32=0.0000; %c=x2 c1=0.0305; c2=0.0000; c3=0.0000; c4=-3.2154; c5=0.0000; c6=0.0000; c7=0.0000; c8=0.0000; c9=0.0000; c10=-0.5857; c11=0.0000; c12=0.0000; c13=0.0000; c14=0.0000; c15=0.0000; c16=0.0000; c17=0.0000; c18=0.0000; c19=0.0000; c20=0.2412; 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=0.0000; c31=0.0000; c32=0.0000; h=0.01; %step size t=0:h:200; %ode p=@(x1_rec,y1_rec,x2_rec,y2_rec) a1+a2x1_rec+a3x2_rec+a4y1_rec+a5y2_rec+a6x1_recx2_rec+a7y1_recy2_rec+a8x1_recy1_rec+a9x1_recy2_rec+a10x2_recy1_rec+a11x2_recy2_rec+a12x1_recx2_recy1_rec+a13x1_recx2_recy2_rec+a14x1_recy1_recy2_rec+a15x2_recy1_recy2_rec+a16x1_recx2_recy1_recy2_rec+a17x1_rec^2+a18x2_rec^2+a19y1_rec^2+a20y2_rec^2+a21x1_rec^2x2_rec+a22x1_rec^2y1_rec+a23x1_rec^2y2_rec+a24x2_rec^2x1_rec+a25x2_rec^2y1_rec+a26x2_rec^2y2_rec+a27y1_rec^2x1_rec+a28y1_rec^2x2_rec+a29y1_rec^2y2_rec+a30y2_rec^2x1_rec+a31y2_rec^2x2_rec+a32y2_rec^2y1_rec; q=@(x1_rec,y1_rec,x2_rec,y2_rec) c1+c2x1_rec+c3x2_rec+c4y1_rec+c5y2_rec+c6x1_recx2_rec+c7y1_recy2_rec+c8x1_recy1_rec+c9x1_recy2_rec+c10x2_recy1_rec+c11x2_recy2_rec+c12x1_recx2_recy1_rec+c13x1_recx2_recy2_rec+c14x1_recy1_recy2_rec+c15x2_recy1_recy2_rec+c16x1_recx2_recy1_recy2_rec+c17x1_rec^2+c18x2_rec^2+c19y1_rec^2+c20y2_rec^2+c21x1_rec^2x2_rec+c22x1_rec^2y1_rec+c23x1_rec^2y2_rec+c24x2_rec^2x1_rec+c25x2_rec^2y1_rec+c26x2_rec^2y2_rec+c27y1_rec^2x1_rec+c28y1_rec^2x2_rec+c29y1_rec^2y2_rec+c30y2_rec^2x1_rec+c31y2_rec^2x2_rec+c32y2_rec^2*y1_rec; %loop for i=1:(length(t)-1) k1=p(x1_rec(i),y1_rec(i),x2_rec(i),y2_rec(i)); l1=q(x1_rec(i),y1_rec(i),x2_rec(i),y2_rec(i));
k2=p((x1_rec(i)+(h/2)*k1),(y1_rec(i)+(h/2)*l1),(x2_rec(i)+(h/2)*k1),(y2_rec(i)+(h/2)*l1)); l2=q((x1_rec(i)+(h/2)*k1),(y1_rec(i)+(h/2)*l1),(x2_rec(i)+(h/2)*k1),(y2_rec(i)+(h/2)*l1)); k3=p((x1_rec(i)+(h/2)*k2),(y1_rec(i)+(h/2)*l2),(x2_rec(i)+(h/2)*k2),(y2_rec(i)+(h/2)*l2)); l3=q((x1_rec(i)+(h/2)*k2),(y1_rec(i)+(h/2)*l2),(x2_rec(i)+(h/2)*k2),(y2_rec(i)+(h/2)*l2)); k4=p((x1_rec(i)+k3*h),(y1_rec(i)+l3*h),(x2_rec(i)+k3*h),(y2_rec(i)+l3*h)); l4=q((x1_rec(i)+k3*h),(y1_rec(i)+l3*h),(x2_rec(i)+k3*h),(y2_rec(i)+l3*h)); x1_rec(i+1) = x1_rec(i) + h*(k1+2*k2+2*k3+k4)/6; x2_rec(i+1) = x2_rec(i) + h*(k1+2*k2+2*k3+k4)/6;
end plot(x1_rec(1:length(x1)),'r','LineWidth',2) plot(x2_rec(1:length(x2)),'b','LineWidth',2)
Hi sorry I am not sure what you are trying to solve. Is this something related to MIN1PIPE?
Hi, I am trying to resolve this issue since past two weeks. Please help me to modify the code or error. Many thanks.
close all; clear all; clc; %initializing x,y,t h=0.01; %step size t=0:h:300; x1 = zeros(1,numel(t)); y1 = x1; x2 = x1; y2 = x1; x1(1)=1; y1(1)=1; x2(1)=2; y2(1)=2; %value of constants a=0.1; b=0.3; omega=4; Cnp=0.2; G=1; %ode p=@(x1,y1,x2,y2) (a-x1^2-y1^2)x1-omegay1+GCnp(x2-x1); q=@(x1,y1,x2,y2) (a-x1^2-y1^2)y1+omegax1+GCnp(y2-y1); %loop for i=1:(length(t)-1) k1=p(x1(i),y1(i),x2(i),y2(i)); l1=q(x1(i),y1(i),x2(i),y2(i));
end %draw plot(t,x1,'r',t,x2,'y') xlabel('t','fontsize',14,'fontweight','bold') ylabel('x1 & x2','fontsize',14,'fontweight','bold') set(gca,'Color','k') legend('x1','x2','TextColor','w') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% x1=x1(101:300); y1=y1(101:300); x2=x2(101:300); y2=y2(101:300); X1dot=(x1(2:101)-x1(1:100))/h; X2dot=(x2(2:101)-x2(1:100))/h; Y1dot=(y1(2:101)-y1(1:100))/h; Y2dot=(y2(2:101)-y2(1:100))/h; hold on M=zeros([100,10]); for i=1:100 for j=1:32 if j==1 M(i,j)=1; elseif j==2 M(i,j)=x1(i); elseif j==3 M(i,j)=x2((i)); elseif j==4 M(i,j)=y1((i)); elseif j==5 M(i,j)=y2((i)); elseif j==6 M(i,j)=x1(i)x2(i); elseif j==7 M(i,j)=y1((i))y2((i)); elseif j==8 M(i,j)=x1((i))y1((i)); elseif j==9 M(i,j)=x1((i))y2((i)); elseif j==10 M(i,j)=x2((i))y1((i)); elseif j==11 M(i,j)=x2((i))y2((i));
elseif j==12 M(i,j)=x1(i)x2(i)y1(i); elseif j==13 M(i,j)=x1(i)x2(i)y2(i); elseif j==14 M(i,j)=x1(i)y1(i)y2(i); elseif j==15 M(i,j)=x2(i)y1(i)y2(i);
elseif j==16 M(i,j)=x1(i)x2(i)y1(i)y2(i);
elseif j==17 M(i,j)=x1(i)^2; elseif j==18 M(i,j)=x2(i)^2; elseif j==19 M(i,j)=y1(i)^2; elseif j==20 M(i,j)=y2(i)^2; elseif j==21 M(i,j)=x1(i)^2x2(i); elseif j==22 M(i,j)=x1(i)^2y1(i); elseif j==23 M(i,j)=x1(i)^2y2(i); elseif j==24 M(i,j)=x2(i)^2x1(i); elseif j==25 M(i,j)=x2(i)^2y1(i);
elseif j==26 M(i,j)=x2(i)^2y2(i); elseif j==27 M(i,j)=y1(i)^2x1(i); elseif j==28 M(i,j)=y1(i)^2x2(i); elseif j==29 M(i,j)=y1(i)^2y2(i); elseif j==30 M(i,j)=y2(i)^2x1(i); elseif j==31 M(i,j)=y2(i)^2x2(i); else M(i,j)=y2(i)^2y1(i);
end end end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Reconstructed Signal % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% x1_rec(1)=x1(1); y1_rec(1)=y1(1); x2_rec(1)=x2(1); y2_rec(1)=y2(1); %value of constants %a1=x1 a1=0.0305; a2=0.0000; a3=0.0000; a4=-3.2154; a5=0.0000; a6=0.0000; a7=0.0000; a8=0.0000; a9=0.0000; a10=-0.5857; a11=0.0000; a12=0.0000; a13=0.0000; a14=0.0000; a15=0.0000; a16=0.0000; a17=0.0000; a18=0.0000; a19=0.0000; a20= 0.2412; a21=0.0000; a22=0.0000; a23=0.0000; a24=0.0000; a25=0.0000; a26=0.0000; a27=0.0000; a28=0.0000; a29=0.0000; a30=0.0000; a31=0.0000; a32=0.0000; %c=x2 c1=0.0305; c2=0.0000; c3=0.0000; c4=-3.2154; c5=0.0000; c6=0.0000; c7=0.0000; c8=0.0000; c9=0.0000; c10=-0.5857; c11=0.0000; c12=0.0000; c13=0.0000; c14=0.0000; c15=0.0000; c16=0.0000; c17=0.0000; c18=0.0000; c19=0.0000; c20=0.2412; 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=0.0000; c31=0.0000; c32=0.0000; h=0.01; %step size t=0:h:200; %ode p=@(x1_rec,y1_rec,x2_rec,y2_rec) a1+a2x1_rec+a3x2_rec+a4y1_rec+a5y2_rec+a6x1_recx2_rec+a7y1_recy2_rec+a8x1_recy1_rec+a9x1_recy2_rec+a10x2_recy1_rec+a11x2_recy2_rec+a12x1_recx2_recy1_rec+a13x1_recx2_recy2_rec+a14x1_recy1_recy2_rec+a15x2_recy1_recy2_rec+a16x1_recx2_recy1_recy2_rec+a17x1_rec^2+a18x2_rec^2+a19y1_rec^2+a20y2_rec^2+a21x1_rec^2x2_rec+a22x1_rec^2y1_rec+a23x1_rec^2y2_rec+a24x2_rec^2x1_rec+a25x2_rec^2y1_rec+a26x2_rec^2y2_rec+a27y1_rec^2x1_rec+a28y1_rec^2x2_rec+a29y1_rec^2y2_rec+a30y2_rec^2x1_rec+a31y2_rec^2x2_rec+a32y2_rec^2y1_rec; q=@(x1_rec,y1_rec,x2_rec,y2_rec) c1+c2x1_rec+c3x2_rec+c4y1_rec+c5y2_rec+c6x1_recx2_rec+c7y1_recy2_rec+c8x1_recy1_rec+c9x1_recy2_rec+c10x2_recy1_rec+c11x2_recy2_rec+c12x1_recx2_recy1_rec+c13x1_recx2_recy2_rec+c14x1_recy1_recy2_rec+c15x2_recy1_recy2_rec+c16x1_recx2_recy1_recy2_rec+c17x1_rec^2+c18x2_rec^2+c19y1_rec^2+c20y2_rec^2+c21x1_rec^2x2_rec+c22x1_rec^2y1_rec+c23x1_rec^2y2_rec+c24x2_rec^2x1_rec+c25x2_rec^2y1_rec+c26x2_rec^2y2_rec+c27y1_rec^2x1_rec+c28y1_rec^2x2_rec+c29y1_rec^2y2_rec+c30y2_rec^2x1_rec+c31y2_rec^2x2_rec+c32y2_rec^2*y1_rec; %loop for i=1:(length(t)-1) k1=p(x1_rec(i),y1_rec(i),x2_rec(i),y2_rec(i)); l1=q(x1_rec(i),y1_rec(i),x2_rec(i),y2_rec(i));
end plot(x1_rec(1:length(x1)),'r','LineWidth',2) plot(x2_rec(1:length(x2)),'b','LineWidth',2)