Home > Archive > Matlab > November 2005 > symbolic vs approximate integral
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
symbolic vs approximate integral
|
|
|
| Hi,
I am trying to understand Matlab's symbolic toolbox and here is the
problem I've encountered:
The symbolic integration method below yields
0.4665 + 0.0873i
The quad command yields 0.4665.
If you look at the integral, it's obvious that there should be no
imaginary part to the result if lam<0, yet the symbolic
integration clearly has logs of negative values in it for the given
values.
also, I assume its a bit more than a coincidince that the real part
of the symbolic integration and the result of quad are equal. Could
someone shed some light on this for me? I don't know if I can trust
the equation I get from int, especially if I am going to perform
further symbolic operations on it.
SYMBOLIC INTEGRATION
-----------------------------------------------------------
G3 = int(sqrt(c^2-x^2)/(c*sqrt(c^2-lam^2)),c,lam*(1+eps),1-eps);
res=subs(G3,'x',0.05);
res=subs(res,'lam',0.9);
-----------------------------------------------------------
QUADRATURE APPROXIMATION
-----------------------------------------------------------
test2 = quad(@(c)
sqrt(c.^2-0.05^2)./(c.*sqrt(c.^2-0.9^2)),0.9*(1+eps),1-eps)
-----------------------------------------------------------
| |
| Litvinov Sergey 2005-11-26, 7:01 pm |
| Ilya wrote:
> -----------------------------------------------------------
> G3 = int(sqrt(c^2-x^2)/(c*sqrt(c^2-lam^2)),c,lam*(1+eps),1-eps);
> res=subs(G3,'x',0.05);
> res=subs(res,'lam',0.9);
Maybe this code give you a hint.
You can specify that lam<1 using this trick.
But I think it is better to use maple functions (mhelp).
clear all
syms c x lam 'real'
syms one_minus_lam 'positive'
ex = sqrt(c^2-x^2)/(c*sqrt(c^2-lam^2));
ex_for_int = simple(subs(ex, lam, 1 - one_minus_lam));
G3 = simple(int(ex_for_int, c, 1 - one_minus_lam, 1));
G3 = limit(G3, one_minus_lam, 1 - lam)
res=subs(G3, {'x', 'lam'}, {0.05, 0.9})
| |
| Roger Stafford 2005-11-26, 7:01 pm |
| In article <ef1cb6e.-1@webx.raydaftYaTP>, Ilya <ibarshai@yahoo.com> wrote:
> Hi,
> I am trying to understand Matlab's symbolic toolbox and here is the
> problem I've encountered:
>
> The symbolic integration method below yields
> 0.4665 + 0.0873i
> The quad command yields 0.4665.
>
> If you look at the integral, it's obvious that there should be no
> imaginary part to the result if lam<0, yet the symbolic
> integration clearly has logs of negative values in it for the given
> values.
>
> also, I assume its a bit more than a coincidince that the real part
> of the symbolic integration and the result of quad are equal. Could
> someone shed some light on this for me? I don't know if I can trust
> the equation I get from int, especially if I am going to perform
> further symbolic operations on it.
>
> SYMBOLIC INTEGRATION
> -----------------------------------------------------------
> G3 = int(sqrt(c^2-x^2)/(c*sqrt(c^2-lam^2)),c,lam*(1+eps),1-eps);
> res=subs(G3,'x',0.05);
> res=subs(res,'lam',0.9);
> -----------------------------------------------------------
> QUADRATURE APPROXIMATION
> -----------------------------------------------------------
> test2 = quad(@(c)
> sqrt(c.^2-0.05^2)./(c.*sqrt(c.^2-0.9^2)),0.9*(1+eps),1-eps)
> -----------------------------------------------------------
...............................
Hello Ilya,
I can partially account for the imaginary portion of 'int's answer.
Consulting an integral table (together with some sweat with paper and
pen,) results in an indefinite integral for your function of c of the
terrifying form:
F(c) = 1/2*log( sqrt((c^2-x^2)*(c^2-lam^2)) + c^2 - (x^2+lam^2)/2 ) + ...
1/2*x/lam*log( (x^2+lam^2)/(2*x*lam) - ...
(sqrt((c^2-x^2)*(c^2-lam^2))+x*lam)/c^2 );
With x = .05 and lam = .9, the definite integral from c = lam to c = 1 is:
0.07394059899788-(-0.39253155264579) = 0.46647215164367 ,
so the real part of your 'int's answer is correct.
This is a tough integral. I think the problem is that 'int' uses a form
of the indefinite integral in the second logarithm that has the wrong sign
for its argument in the range of values you are using. My own integral
table gave the wrong sign for it and I had to deliberately reverse it to
get the above expression. (Both log(z) and log(-z) have the same formal
derivative, namely 1/z, but for different ranges of z values.) This
results in obtaining an imaginary branch for the indefinite integral
values. That is, if you take log(-7), you get log(7) + pi*i. What I
don't understand is why the two imaginary parts didn't cancel out when
they were subtracted in obtaining the definite integral. They should both
have been the same value, namely 1/2*x/lam*pi*i = 0.08726646259972*i.
Apparently in your case that imaginary value occurred for the upper value
but not for the lower one, leaving you with a non zero imaginary part of
the answer in the definite integral of that amount. You ought to take a
p at the form of your indefinite integral and see what the imaginary
part looks like. It should be exactly the one I have described,
1/2*x/lam*pi*i, and not depend on c.
Probably someone in Mathworks should look into the matter for you and
find out why this inconsistency occurs between your upper and lower
values.
With my own ancient version of matlab's Symbolic Math Toolbox, 'int'
takes the cowardly way out and refuses to give any answer at all (hence
the need to consult integral tables,) so perhaps you should consider
yourself lucky to have gotten even this far with it.
(Remove "xyzzy" and ".invalid" to send me email.)
Roger Stafford
|
|
|
|
|