Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Does anyone know how to do any of these programs?
Date: Sun, 30 Nov 2008 03:44:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <ggt262$gq5$1@fred.mathworks.com>
References: <8659463.1227927779634.JavaMail.jakarta@nitrogen.mathforum.org> <ggqdus$bu7$1@fred.mathworks.com> <ggs6oh$hrq$1@fred.mathworks.com> <ggsovl$svb$1@fred.mathworks.com> <ggstg1$nae$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228016642 17221 172.30.248.35 (30 Nov 2008 03:44:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 30 Nov 2008 03:44:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:503871


"john " <john@yahoo.com> wrote in message <ggstg1$nae$1@fred.mathworks.com>...
> ........
> Changed version:
> clc; clear all; close all;
> y=inline('(x^2)-(2*x)+(0.9)');
>
> X1=1;
> X2=-2;
> Xm=(0.5)*(X1+X2);
> d=X2-X1;
> Xnewm=X1+(0.5*d);
> if sign(y(X1)) ~= sign((Xm))
>     X2=Xm;
> else
>     if sign(y(X2)) ~= sign((Xm))
>         X1=Xm;
>     elseif y(Xm)==0
>         disp(Xm);
>     end
> end
> 
> when i run it, it does not display Xm at the end. 
------------------
  I will limit my response to just a few observations, John.  1) You have not implemented the 'while' loop you need to do the necessary iterating.  It only does its computation once.  2) You are comparing the sign of y(X1) with that of Xm which makes no sense.  3) You are waiting for y(Xm) to equal zero to display Xm which may never happen no matter how many iterations you have done.  4) You do a comparison with the sign of y(X2) after your comparison with the sign of y(X1).  If you know that they remain always opposite in sign, this is totally unnecessary.  5) In bringing the 'while' loop to a halt you would need the absolute value of the difference in y's.  This difference may never reach zero and you may not know in advance which sign it will have.  6) The quantity Xnewm is identically equal to Xm and is wholly redundant. 

Roger Stafford