Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
from x_guess to x_feedback

Subject: from x_guess to x_feedback

From: Anna Kaladze

Date: 31 Jul, 2010 10:41:05

Message: 1 of 2

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

Subject: from x_guess to x_feedback

From: Torsten Hennig

Date: 2 Aug, 2010 07:02:12

Message: 2 of 2

> 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.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us