Path: news.mathworks.com!not-for-mail
From: "Marcelo Tames" <jmarcelo.tb@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how come matlab drew this?
Date: Sun, 24 Feb 2008 21:03:06 +0000 (UTC)
Organization: M&#65533;lardalen University
Lines: 80
Message-ID: <fpsm2a$lvc$1@fred.mathworks.com>
References: <fps18k$dh3$1@fred.mathworks.com> <fpsjlc$q6q$1@fred.mathworks.com>
Reply-To: "Marcelo Tames" <jmarcelo.tb@mathworks.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1203886986 22508 172.30.248.38 (24 Feb 2008 21:03:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 24 Feb 2008 21:03:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1272310
Xref: news.mathworks.com comp.soft-sys.matlab:453429


"Roger Stafford" 
<ellieandrogerxyzzy@mindspring.com.invalid> wrote in 
message <fpsjlc$q6q$1@fred.mathworks.com>...
> "Marcelo Tames" <jmarcelo.tb@mathworks.com> wrote in 
message <fps18k
> $dh3$1@fred.mathworks.com>...
> > Hi I saw a exercise in a book and asked me to plot 
these 
> > graphs togheter as abs(y1-y2):
> > 
> > y1(x) =sqrt(x^2 + 1)- 1 
> > 
> > and 
> > 
> > y2(x) =x^2/sqrt(x^2 + 1) + 1
> > 
> > and I did the following:
> > 
> > delta=10^(-3);
> > x=linspace(10^(-4),10^(-3),100);
> > y1 = sqrt(x.^2+1)-1;
> > y2 = x.^2./(sqrt(x.^2+1)+1);
> > z = abs(y1-y2)
> > plot(x,z)
> > ylabel('value');
> > xlabel('x');
> > title('compare');
> > 
> > I get a graph but I don?t really understand why is 
that, I 
> > mean if one solves abs(y1-y2) by hand everything 
becomes 
> > zero, can anyone explain to me why matlab still graphs 
> > something and is what I did wrong? I?m a beginner so 
please 
> > understand that my reasoning is not that advanced
> > 
> > thanks 
> --------
>   I assume from your remarks that you are aware that the 
two expressions in 
> question are mathematically identically equal to one 
another, so you are 
> apparently asking why you didn't get a graph showing a 
horizontal line of 
> height zero.  If that is your question, the answer is 
round off error in 
> computing the two quantities.  These involve differing 
mathematical 
> operations and will produce slightly different results 
because of this round off 
> error.  Note that the values you are getting in the graph 
are of size 
> somewhere in the neighborhood of 10^(-16) which is a very 
small value 
> indeed.  If you were to accompany this graph with another 
one that assumes 
> values in the neighborhood of 1, the first graph would be 
squeezed down to 
> the horizontal line you are expecting.
> 
>   If you are asking why the two expressions are 
identical, try multiplying the 
> numerator and denominator of  y2 by (sqrt(x^2+1)-1) and 
simplify the result.  
> What you arrive at is precisely y1.
> 
>   By the way, in the first expression for y2, you appear 
to have left out a pair 
> of parentheses, though that is corrected in the code.
> 
> Roger Stafford
> 

thanks Roger, I was suspecting that about the error but 
wasn?t sure. I?ll discuss these with my classmates. thanks 
again

best regards 
Marcelo