while and for cicle
1 回表示 (過去 30 日間)
古いコメントを表示
hi guys.
I'm working on a data set of points (x,y) and i have to write an algorithm that compute the linear regression of this points till a lower and/or an upper bound are exceeded.
So i use lsqlin with upper and lower bounds..... but i have to write a for cicle to work in this way:
-Starting from the first 3 points, if the linear regression respect the bounds i add them the fourth point, and so on.... till the constraints are not satisfied; if for example the last point for which the constraints are satisfied is the 10-th, the next iteration must restart from the 11-th point to the 13-th and start over, till the constraints continue to be satisfied. (if the first 3 points of a group doesn't respect the constraints, i exclude the first point and try with 2, 3 and 4, and so on)
i wrote this part of code but i have some problems, because i need to restart the value of jj when i restart the iteration.
for jj=2:length(s)-i
k=i+jj;
S=s(i:k);
Y=y(i:k);
C=[S,ones(length(S),1)];
[X,resnorm,residual,exitflag]=lsqlin(C,Y,A,b,Aeq,beq,lb,ub); %ad ogni I-esima iterazione vado ad allocare nella I-esima colonna di X il coeff angolare K e l'intercetta b della I-esima tangente
if exitflag>0
xprog=S;
yprog=X(1)*xprog+X(2);
DELTA_Y=Y-yprog;
plot(xprog,yprog,'r--',C(:,1),Y,'.b')
else if k+1<length(s)-2
i=k+1;
hold on
end
end
end
2 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Polynomials についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!