--%>

Problem on Vectors

Create a vector representing x coordinates of a measurement with 20 points between 0 and 10. Create another vector y representing fake measurements which are related to the above x values as y = 2.3 x – 1.2. Next add random (normal, Gaussian) noise to the vector y. Plot on the same graph both versions of vector y in different colors. Next use attached linregr.m function to find a least square fit (linear regression) for your fake experimental data.

E

Expert

Verified

Calculations:

x=0:0.5:10;

y = 2.3*x - 1.2;

x1=x.^2;

xvar=mean(x1)-((mean(x)).^2);

xstd=sqrt(xvar);

noise= 1/(sqrt(2*pi*xstd))*exp(-((x-mean(x)).^2)/(2*xvar));

y1=y+noise

plot(x,y,x,y1,'g');

legend('Normal Y vector','Noise additive Y vector');

XLABEL('x')

YLABEL('Normal Y vector=2.3*x-1.2')

[a, r2]= linregr(x,y);


Results:

502_2013a.jpg


Least square fit Results gives the Least regression for the fake experimental results a = vector of slope, a(1)- → 2.3, and intercept a(2)-→ -1.2
r2 = coefficient of determination = 1

 

2061_2013b.jpg

   Related Questions in Programming Languages