In this programe of line fitting for y=mx+c , i get problem in "cfit". plz help me to get right program for this y=mx+c.
Mostra commenti meno recenti
x=[0:100]';
y=x;
n=randn(101,1);
yi=y+n;
m=input('inital value slope');
dm=input('incremental value in m');
c=input('inital value contsant');
dc=input('incremental value in c');
niter=input('no. of iterstions');
for a=1:niter;
mx=[m-dm,m,m+dm];
cx=[c-dc,c,c+dc];
for b=1:3;
e=1:3;
my=mx(b);
cy=cx(e);
yfit=my*x;
cfit=my*x*n+cy*(mx);
yerr(b,e)=sum((cfit-yi).^2);
end;
[z indx]=sort(yerr);
m= mx(indx(1));
dm=dm/2;
end;
yfit1=m*x;
plot(x,yfit1,'r');
hold on
plot(x,yi,'x');
Risposte (1)
Arthur
il 12 Set 2013
0 voti
The dimensions of your arrays in not consistent. In order to add or multiply two variables, they have to have the same dimensions, or to be scalars. But in your script, my is 1x1, x is 101x1, n is 101x1, cy is 3x1 and mx is 3x1.
I'm not sure what you're trying to achieve, but probably you should fix the dimensions of cy and mx.
Categorie
Scopri di più su Linear Regression in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!