From: Anna Kaladze on
Dear All,
I am very new to programming and to MATLAB and with the help of some of you, I put up together a code where the idea is: given an arbitrary guess vector (x_old), keep updating it, so that x_feedback ends up being equal to x_old. For this particular problem, looks like the answer is x_old=(0.0000..., -0.25...), but I am not getting it. My problem is NOT so much to know the answer for THIS particular problem, but to correct the code below so that it equilzes x_feeback and x_old as fast as possible given that tol=0.01. Thanks a lot!
------------------
count = 0;
maxcount = 1000;
tol = 0.01;
q=9;
error = 1.0;
x_lower = -20.0;
x_upper = 20.0;
x_old(1) = 1;
x_old(2) = -1;
while error > tol
count = count+1;
if count > maxcount
disp('Reached maximum iterations before error within tolerance');
break
end
% prepare variables for next iteration
y_array(1) = x_old(1)+x_old(2);
y_array(2) = x_old(2)^2-x_old(1);
y = @(x) -(y_array(1)-x^2-x*x_old(1));
z = @(x) -(y_array(2)^2-x^2-x);
x_new(1) = fminbnd(y,x_lower,x_upper);
x_new(2) = fminbnd(z,x_lower,x_upper);
x_feedback(1)=x_old(1)-x_new(1);
x_feedback(2)=x_old(2)-x_new(2);
error = norm(x_old-x_feedback);
x_old = x_old.*(1+error/q);
end
From: Torsten Hennig on
> Dear All,
> I am very new to programming and to MATLAB and with
> the help of some of you, I put up together a code
> where the idea is: given an arbitrary guess vector
> (x_old), keep updating it, so that x_feedback ends up
> being equal to x_old. For this particular problem,
> looks like the answer is x_old=(0.0000..., -0.25...),
> but I am not getting it. My problem is NOT so much to
> know the answer for THIS particular problem, but to
> correct the code below so that it equilzes x_feeback
> and x_old as fast as possible given that tol=0.01.
> Thanks a lot!
> ------------------
> count = 0;
> maxcount = 1000;
> tol = 0.01;
> q=9;
> error = 1.0;
> x_lower = -20.0;
> x_upper = 20.0;
> x_old(1) = 1;
> x_old(2) = -1;
> while error > tol
> count = count+1;
> if count > maxcount
> disp('Reached maximum iterations before error within
> tolerance');
> break
> end
> % prepare variables for next iteration
> y_array(1) = x_old(1)+x_old(2);
> y_array(2) = x_old(2)^2-x_old(1);
> y = @(x) -(y_array(1)-x^2-x*x_old(1));
> z = @(x) -(y_array(2)^2-x^2-x);
> x_new(1) = fminbnd(y,x_lower,x_upper);
> x_new(2) = fminbnd(z,x_lower,x_upper);
> x_feedback(1)=x_old(1)-x_new(1);
> x_feedback(2)=x_old(2)-x_new(2);
> error = norm(x_old-x_feedback);
> x_old = x_old.*(1+error/q);
> end

This iteration will never converge.
You want to archieve that x_old -> x_feedback.
This means that x_new -> 0
(since x_new = x_old - x_feedback).
But from x_new(2) = fminbnd(z,x_lower,x_upper),
you will always get x_new(2) = -0.5 (which does not
equal 0).

Please explain again in your own words what you try
to do.

Best wishes
Torsten.
 | 
Pages: 1
Prev: import an ascii with repeated header
Next: Error