Why is my plot not showing?
3 views (last 30 days)
Show older comments
Only axes are appearing but plot is not showing. Please help me to detect the error i am making in the program. Apologies for a long code.
clear all; close all; clc;
test_points=3;
start_point=1000;
x_rec(1)=x(start_point);
x_real(1)=x(start_point);
c1=ksaix(1);
c2=ksaix(2);
c3=ksaix(3);
c4=ksaix(4);
c5=ksaix(5);
c6=ksaix(6);
c7=ksaix(7);
c8=ksaix(8);
c9=ksaix(9);
c10=ksaix(10);
c11=ksaix(11);
c12=ksaix(12);
c13=ksaix(13);
c14=ksaix(14);
c15=ksaix(15);
c16=ksaix(16);
c17=ksaix(17);
c18=ksaix(18);
c19=ksaix(19);
c20=ksaix(20);
c21=ksaix(21);
c22=ksaix(22);
c23=ksaix(23);
c24=ksaix(24);
c25=ksaix(25);
error=0;
DN=0;
for i=4:test_points
x_rec(i)=c1+c2*x_rec(i-1)+c3*x_rec(i-1)^2+c4*x_rec(i-1)^3+c5*x_rec(i-1)^4+c6*x_rec(i-1)^5+c7*x_rec(i-1)^6+c8*x_rec(i-1)^7+c9*x_rec(i-1)^8+c10*x_rec(i-1)^9+c11*x_rec(i-1)^10+c12*x_rec(i-1)^11+c13*x_rec(i-1)^12+c14*x_rec(i-1)^13+c15*x_rec(i-1)^14+c16*x_rec(i-1)^15+c17*x_rec(i-1)^16+c18*x_rec(i-1)^17+c19*x_rec(i-1)^18+c20*x_rec(i-1)^19+c21*x_rec(i-1)^20+c22*x_rec(i-1)^21+c23*x_rec(i-1)^22+c24*x_rec(i-1)^23+c25*x_rec(i-1)^24;
error=error+(x_rec(i)-x_real(i))^2;
DN=DN+x_real(i)^2;
end
Error_x(count)=sqrt(error)/sqrt(DN);
end
figure
hold on
plot (Data,Error_x,'s-r')
6 Comments
dpb
on 17 Oct 2020
Edited: dpb
on 18 Oct 2020
x_rec(i)=c1+c2*x_rec(i-1) + c3*x_rec(i-1)^2 + c4*x_rec(i-1)^3 + c5*x_rec(i-1)^4 + ...
c6*x_rec(i-1)^5 + c7*x_rec(i-1)^6 + c8*x_rec(i-1)^7 + c9*x_rec(i-1)^8 + ...
c10*x_rec(i-1)^9+c11*x_rec(i-1)^10+c12*x_rec(i-1)^11+c13*x_rec(i-1)^12+ ...
c14*x_rec(i-1)^13+c15*x_rec(i-1)^14+c16*x_rec(i-1)^15+c17*x_rec(i-1)^16+ ...
c18*x_rec(i-1)^17+c19*x_rec(i-1)^18+c20*x_rec(i-1)^19+c21*x_rec(i-1)^20+ ...
c22*x_rec(i-1)^21+c23*x_rec(i-1)^22+c24*x_rec(i-1)^23+c25*x_rec(i-1)^24;
is
x_rec(i)=polyval(flip(ksaix),x_rec(i-1));
NB: polyval is defined as
Y = C(1)*X^N + C(2)*X^(N-1) + ... + C(N)*X + C(N+1)
so must reverse order of coefficient array.
dpb
on 17 Oct 2020
As for the original question, anything that uses a polynomial to the 24th power is just asking for numerical troubles--either over- or underflow and imprecision.
As another said, probably you're ending up with NaN or Inf as results.
Answers (1)
Image Analyst
on 17 Oct 2020
Look at the first few lines:
clear all; close all; clc;
test_points=3;
start_point=1000;
x_rec(1)=x(start_point);
Now you try to get x(start_point) but you never defined it. SO that throws an error. Or if you did (in another script), you blew it away with the clear all command.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!