 |
|
List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] same function with different arrangement give different plots?
| [MUG] same function with different arrangement give different plots? |
|
Author: Xiaoyan Li
Posted: Tue, 26 Nov 2002 23:38:16 -0500
|
>> From: Xiaoyan Li "xili"
Hello,
I am trying to figure out why some plotting is not consistent with their
theoretical shape. And I found out the same function with different
arrangement actually give different plot in maple, has anyone find out why
this is the case?
For example, function tmpF1(x) and tmpF2(x) are exactly the same, but the
plot diverge at around x=11.
tmpF1 :=
x->1.543471697*(exp(.3296799540*x^2)*erf(.5741776328*x)-exp(.3296799540*x^2)*erf(1.148355266*x))+x;
tmpF2 :=
x->1.543471697*exp(.3296799540*x^2)*(erf(.5741776328*x)-erf(1.148355266*x))+x;
plot({tmpF1(x),tmpF2(x)},x=0..40);
Originally I thought the x got ignored because of the intermediate
result is too large. But actually by just change the last bit
of the coefficient of tmpF1, it almost comply with tmpF3. This seems too
strange.
tmpF3 :=
x->1.543471698*(exp(.3296799540*x^2)*erf(.5741776328*x)-exp(.3296799540*x^2)*erf(1.148355266*x))+x;
plot({tmpF1(x),tmpF2(x)},x=0..40);
Thanks,
Xiaoyan
==============================
|
| [MUG] Re: same function with different arrangement give different
plots? |
|
Author: Koch-Beuttenmueller
Posted: Thu, 28 Nov 2002 08:52:23 +0100
|
>> From: Koch-Beuttenmueller "Heike.Koch-Beuttenmueller"
> >> From: Xiaoyan Li "xili"
> I am trying to figure out why some plotting is not consistent with their
> theoretical shape. And I found out the same function with different
> arrangement actually give different plot in maple, has anyone find out why
> this is the case?
>
> For example, function tmpF1(x) and tmpF2(x) are exactly the same, but the
> plot diverge at around x=11.
>
> tmpF1 :=
> x->1.543471697*(exp(.3296799540*x^2)*erf(.5741776328*x)-exp(.3296799540*x^2)*erf(1.148355266*x))+x;
>
> tmpF2 :=
> x->1.543471697*exp(.3296799540*x^2)*(erf(.5741776328*x)-erf(1.148355266*x))+x;
>
> plot({tmpF1(x),tmpF2(x)},x=0..40);
>
> Originally I thought the x got ignored because of the intermediate
> result is too large. But actually by just change the last bit
> of the coefficient of tmpF1, it almost comply with tmpF3. This seems too
> strange.
>
> tmpF3 :=
> x->1.543471698*(exp(.3296799540*x^2)*erf(.5741776328*x)-exp(.3296799540*x^2)*erf(1.148355266*x))+x;
>
> plot({tmpF1(x),tmpF2(x)},x=0..40);
On Unix-platforms I get for MapleV R5.1, maple6, maple7 and maple8 no
differences in the plots of the 3 functions. Which Maple and which
platform do you use.
Mit freundlichen Gruessen
Heike Koch-Beuttenmueller
|
| [MUG] Re: same function with different arrangement give different
plots? |
|
Author: Maple User Group
Posted: Wed, 4 Dec 2002 10:24:58 -0500 (
|
>> From: Maple User Group "maple_gr"
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Fri, 29 Nov 2002 15:31:30 +0100 (CET)
From: "elbr"
To: "maple-list"
Subject: same function with different arrangement give different plots?
On 27-Nov-2002 Xiaoyan Li wrote:
> I am trying to figure out why some plotting is not consistent with their
> theoretical shape. And I found out the same function with different
> arrangement actually give different plot in maple, has anyone find out why
> this is the case?
>
> For example, function tmpF1(x) and tmpF2(x) are exactly the same, but the
> plot diverge at around x=11.
>
>
> restart;
The given expressions in your mail from (Nov. 22 2002)
with unevaluated diff and int are:
> Pi*((2*R-x)^2-R^2):
> g := factor(%);
> Fx := exp(-m*g*(1-exp(-n*2)));
> fx := Diff(Fx,x);
> Ex := Int(x*fx,x=0..R);
>
> EQ_c := m = 1/Pi
> , n = 2/10
> ;
g := Pi (3 R - x) (R - x)
Fx := exp(-m Pi (3 R - x) (R - x) (1 - exp(-2 n)))
d
fx := -- exp(-m Pi (3 R - x) (R - x) (1 - exp(-2 n)))
dx
R
/
| /d \
Ex := | x |-- exp(-m Pi (3 R - x) (R - x) (1 - exp(-2 n)))| dx
| \dx /
/
0
1
EQ_c := m = ----, n = 1/5
Pi
To simplify the expressions a factor K (x and R free) is introduced.
> EQ_K := m*Pi*(1-exp(-n*2)) = K;
> EQ_Ki := rhs(%) = lhs(%):
>
> evalf(eval(EQ_Ki, [EQ_c]), 2);
>
>
>
EQ_K := m Pi (1 - exp(-2 n)) = K
K = 0.33
Substitution of the factor K gives:
> Ex_K0 := factor( algsubs(EQ_K, Ex, m));
R
/
| /d \
Ex_K0 := | x |-- exp(-K (3 R - x) (R - x))| dx
| \dx /
/
0
Evaluate the diff and int function to get the
final expression (with abbreviation K):
> value(Ex_K0):
> collect(%, [K, exp], factor):
> Ex_K1 := %;
1/2 1/2 1/2 2
Pi (erf(K R) - erf(2 K R)) exp(K R )
Ex_K1 := R + 1/2 ---------------------------------------------
1/2
K
For the given values of R the critical term (in a numeric sense) is the
difference of the two erf functions since erf(x) ->1 for x -> infinity.
The problem is that two terms near 1 are subtracted. The difference is ca.
exp(-x^2)/(Pi*x) (x = sqrt(K)*R, see below).
To see this, the values of the relevant expression are calculated here
for R = 10, 20.(no autput here)
> R, exp(K*R^2), erf(K^(1/2)*R), erf(2*K^(1/2)*R):
> [%, %[-2] - %[-1]]:
> subs(EQ_Ki, m=1/Pi, n=1/5, %):
> TL := unapply(zip((u,v) -> [u,v], subs(R = ` R`, %%), %), R): # TL(R)
>
> 'TL(10)'; # TL(R)
> evalf(%, 25):
> MATRIX(%);
>
> 'TL(20)'; # TL(R)
> evalf(%, 25):
> MATRIX(%);
>
To avoid the numeric difficulties, the difference of erf(x)-erf(2*x) is
asymptotic expanded to a rational polynomial.
> Order := 6;
> erf(x)-erf(2*x);
> asympt(%, x):
> simplify(%):
> collect(%, Pi, factor):
> d_erf_as := unapply( %, x);
>
Order := 6
erf(x) - erf(2 x)
4 2 2
1 2 (4 x - 2 x + 3) exp(-x )
d_erf_as := x -> O(----) exp(-x ) - 1/4 --------------------------
7 5 1/2
x x Pi
The second summand of Ex (with erf and exp) is therefore approximated by:
> Ex_K1 -R:
> applyrule(erf(x::algebraic) - erf(2*x::algebraic) = d_erf_as(x),%):
> collect(simplify(%), R):
> Delta := %;
1 1/2
O(---------) Pi
(7/2) 7
K R 1 1 3
Delta := 1/2 ------------------ - ----- + ------- - -------
1/2 2 K R 2 3 3 5
K 4 K R 8 K R
and the final approximation of the whole expression Ex (without the error term)
> Ex_K2 := convert(R + Delta, polynom);
1 1 3
Ex_K2 := R - ----- + ------- - -------
2 K R 2 3 3 5
4 K R 8 K R
To show the error of the asymptotic expansion, the rel. difference of the two
forms Ex, Ex_K2, are plotted.
For R > 9 the relative error is less 4*e-6.
The 20 digits are used to damp the 'rounding and cancellation noise' while
evaluating the expression with erf and exp.
> Old_Digits := Digits;
> Digits := 20;
>
> (Ex_K1/Ex_K2 - 1):
> subs(EQ_Ki, m=1/Pi, n=1/5, %):
> plot(%, R=8 .. 10, title = "rel. error of the two forms");
> Digits := Old_Digits;
>
I hope this can help you to work with the above expression.
>
E. Elbraechter
----------------------------------
E-Mail: "elbr"
Date: 29-Nov-2002
Time: 15:22:06
This message was sent by XFMail
----------------------------------
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Fri, 29 Nov 2002 11:03:14 -0800 (PST)
From: Robert Israel "israel"
To: "maple-list"
Subject: same function with different arrangement give different
On this plot it's hard to see the difference (on my computer), but
you can see it more clearly in
> plot([tmpF1(x),tmpF2(x)],x=9.5 .. 10.5,colour=[red,blue]);
The problem is roundoff error. Consider
> tmpF1(x)-tmpF2(x);
2
1.543471697 exp(0.3296799540 x ) erf(0.5741776328 x)
2
- 1.543471697 exp(0.3296799540 x ) erf(1.148355266 x) -
2
1.543471697 exp(0.3296799540 x )
(erf(0.5741776328 x) - erf(1.148355266 x))
So this is of the form A*B - A*C - A*(B-C). Algebraically, of
course, this should be 0. But floating point arithmetic does not
exactly obey the laws of ordinary algebra! And when x is large,
this is the kind of situation where roundoff error is likely to be
severe: you are subtracting two numbers B and C that are both very close
to 1, resulting in a large relative error, and multiplying the result by a
large number A, making this large relative error into a large absolute
error. The actual calculations are done using hardware floating-point
(evalhf), but it may be clearer if I show the results using Maple's
software floating-point at Digits = 10. I'll take x = 8. Then
A = 2248549746., B = .9999999999, C = 1.
B - C = -.1e-9 (accurate to only one significant digit!) so
A*(B - C) = -0.2248549746.
On the other hand, A*B = A*C = 2248549746. Yes, that's right,
A*B with exact arithmetic would be 2248549745.7751450254, which
to 10 digits is rounded to 2248549746. Thus A*B - A*C = 0.
Robert Israel "israel"
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2
|
Previous by date: [MUG] Re: Limit Superior & Limit Inferior, Barsuhn
Next by date: [MUG] Re: maple ps plotoutput and other graphics programs, Timothy Feeman
Previous thread: [MUG] isqrt command, Adalberto Ayjara Dornelles Filho
Next thread: [MUG] maple ps plotoutput and other graphics programs, Dr U Kasper
|
|
|