You are on page 1of 1

clear; amin = -4; amax = 4; bmin = amin; bmax = amax; increment = .

2; xaxis=amin:increment:amax; %(x-axis) yaxis=bmin:increment:bmax; %(y-axis) points=length(xaxis); [X,Y]=meshgrid(xaxis,yaxis); iterations=1000; Z=zeros(points,points); theta=pi/3; u = 0; v = 0; for j = 1:points; for k = 1:points; a = amin + increment * (j-1); b = bmin + increment * (k-1); zeta = 0; for i=1:iterations x = randn() + .3; y = randn() - .1; u = 1.1*x; v = 2.1*y; utmp = cos(theta)*u + sin(theta)*v; v = -sin(theta)*u + cos(theta)*v; u = utmp; e = a*u + b - v; zeta = zeta + e*e; end zeta = zeta / iterations; Z(j,k) = zeta; end end colormap(gray); mesh(X,Y,Z); % contourf(X,Y,Z); % Now, let's find the minimum mean square error values: best = 10000; besta = 0; bestb = 0; for j = 1:points for k = 1:points if (Z(j,k) < best) best = Z(j,k); besta=amin + increment * (j-1); bestb=bmin + increment * (k-1); end end end disp(best); disp(besta); disp(bestb);

You might also like