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

madhan ravi
madhan ravi 2020년 10월 16일
Please explain why someone should answer your question, when you’re going to edit the question completely after getting a proper answer for your homework?
David Goodmanson
David Goodmanson 2020년 10월 16일
편집: David Goodmanson 2020년 10월 17일
Hello Heya,
Actually since you have put in the work and provided the code it would be fairly easy to take a look at this. Unfortunately the code is not plain vanilla Matlab since it utilizes cvx software. Could you provide a workaround?
The thing to do first, though, is carefully examine Data and Error_x. Probably the most common reason for the no-plot effect is that one of the x or y array is either the empty array or is full of NaNs.
dpb
dpb 2020년 10월 16일
It wouldn't be nearly so long if you would use MATLAB like MATLAB instead of Visual Basic...
for i=1:N_measurements
for j=1:N_basis
if j==1
M(i,j)=1;
elseif j==2
M(i,j)=x(index(i));
elseif j==3
M(i,j)=x(index(i))^2;
...
elseif j==24
M(i,j)=x(index(i))^23;
else
M(i,j)=x(index(i))^24;
end
end
end
is
for i=1:N_measurements
M(:,j)=x(index(i)).^[0:24];
end
keeping the I loop; it could be reduced by vectorizing the index variable over i as well.
Similarly in all the remainder with a zillion named variables instead of arrays.
Heya :)
Heya :) 2020년 10월 17일
Thank you!
dpb
dpb 2020년 10월 17일
편집: dpb 2020년 10월 18일
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
dpb 2020년 10월 17일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2020년 10월 17일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2020년 10월 16일

편집:

dpb
2020년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by