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:
Problem estimating integral

Subject: Problem estimating integral

From: Andrew

Date: 26 Jan, 2010 23:06:20

Message: 1 of 8

Hi

Below is a sequence of steps I've tried so far, without success ... am first trying symbolic integration and then numerical integration using quad. I have followed the help for the latter part and am a little stuck now. Hope someone can help.

syms x
problem = (2^(1/2)*cos(2*x))/(pi^(1/2)*exp(2*(pi/2 - x)^2))
int(problem, -inf, inf)
int(problem, pi/2-.1, pi/2+.1)

"Warning: Explicit integral could not be found." in both cases.

problemvectorized = vectorize(problem)
problemvectorized = (2.^(1./2).*cos(2.*x))./(pi.^(1./2).*exp(2.*(pi./2 - x).^2))
inlineproblemvectorized = @(x)problemvectorized
quad(inlineproblemvectorized, pi/2-.1, pi/2+.1)

"Warning: Maximum function count exceeded; singularity likely. ans = 9.6235"

If we look at the graph it should be about -0.16. Any ideas?

Thanks for taking a look,

Andrew

Subject: Problem estimating integral

From: Walter Roberson

Date: 26 Jan, 2010 23:22:54

Message: 2 of 8

Andrew wrote:

> Below is a sequence of steps I've tried so far, without success ... am
> first trying symbolic integration and then numerical integration using
> quad. I have followed the help for the latter part and am a little stuck
> now. Hope someone can help.

> syms x
> problem = (2^(1/2)*cos(2*x))/(pi^(1/2)*exp(2*(pi/2 - x)^2))
> int(problem, -inf, inf)

Maple easily simplifies that to -exp(-1/2), which is about -.6065306597

> int(problem, pi/2-.1, pi/2+.1)

In that form, with the decimal number, Maple immediately gives back a numeric
answer. If the .1 is changed to 1/10 then after a trivial factoring, Maple gives:

-(1/2)*exp(-1/2) * (erf((1/10)*2^(1/2)+((1/2)*I)*2^(1/2)) +
erf((1/10)*2^(1/2)-((1/2)*I)*2^(1/2)))

where I is sqrt(-1). The imaginary numbers cancel out somehow, leaving a
numeric approximation of -.1574703436

Subject: Problem estimating integral

From: Andrew

Date: 30 Jan, 2010 11:49:02

Message: 3 of 8

Walter Roberson <roberson@hushmail.com> wrote in message <hjntuc$nuq$1@canopus.cc.umanitoba.ca>...
> Andrew wrote:
>
> > Below is a sequence of steps I've tried so far, without success ... am
> > first trying symbolic integration and then numerical integration using
> > quad. I have followed the help for the latter part and am a little stuck
> > now. Hope someone can help.
>
> > syms x
> > problem = (2^(1/2)*cos(2*x))/(pi^(1/2)*exp(2*(pi/2 - x)^2))
> > int(problem, -inf, inf)
>
> Maple easily simplifies that to -exp(-1/2), which is about -.6065306597
>
> > int(problem, pi/2-.1, pi/2+.1)
>
> In that form, with the decimal number, Maple immediately gives back a numeric
> answer. If the .1 is changed to 1/10 then after a trivial factoring, Maple gives:
>
> -(1/2)*exp(-1/2) * (erf((1/10)*2^(1/2)+((1/2)*I)*2^(1/2)) +
> erf((1/10)*2^(1/2)-((1/2)*I)*2^(1/2)))
>
> where I is sqrt(-1). The imaginary numbers cancel out somehow, leaving a
> numeric approximation of -.1574703436

Thankyou very much for your answer, Walter!

I don't have access to Maple. I do have Maxima and it couldn't solve the integral either, just restates it. Mathematica, via wolfram alpha, is successful though.

Why is Matlab not able to do this? Should I raise a bug?

Andrew

Subject: Problem estimating integral

From: Andrew

Date: 6 Feb, 2010 15:34:14

Message: 4 of 8

"Andrew " <removethis@removethis.com> wrote in message <hk16be$1lq$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <hjntuc$nuq$1@canopus.cc.umanitoba.ca>...
> > Andrew wrote:
> >
> > > Below is a sequence of steps I've tried so far, without success ... am
> > > first trying symbolic integration and then numerical integration using
> > > quad. I have followed the help for the latter part and am a little stuck
> > > now. Hope someone can help.
> >
> > > syms x
> > > problem = (2^(1/2)*cos(2*x))/(pi^(1/2)*exp(2*(pi/2 - x)^2))
> > > int(problem, -inf, inf)
> >
> > Maple easily simplifies that to -exp(-1/2), which is about -.6065306597
> >
> > > int(problem, pi/2-.1, pi/2+.1)
> >
> > In that form, with the decimal number, Maple immediately gives back a numeric
> > answer. If the .1 is changed to 1/10 then after a trivial factoring, Maple gives:
> >
> > -(1/2)*exp(-1/2) * (erf((1/10)*2^(1/2)+((1/2)*I)*2^(1/2)) +
> > erf((1/10)*2^(1/2)-((1/2)*I)*2^(1/2)))
> >
> > where I is sqrt(-1). The imaginary numbers cancel out somehow, leaving a
> > numeric approximation of -.1574703436
>
> Thankyou very much for your answer, Walter!
>
> I don't have access to Maple. I do have Maxima and it couldn't solve the integral either, just restates it. Mathematica, via wolfram alpha, is successful though.
>
> Why is Matlab not able to do this? Should I raise a bug?
>
> Andrew

Would someone from Mathworks like to respond? It's been a week.

Andrew

Subject: Problem estimating integral

From: Steven Lord

Date: 8 Feb, 2010 16:13:19

Message: 5 of 8


"Andrew " <removethis@removethis.com> wrote in message
news:hkk25m$t54$1@fred.mathworks.com...

*snip*

> Would someone from Mathworks like to respond? It's been a week.

You should submit this as an official Technical Support request using the
Contact Us link at the top of http://www.mathworks.com.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Problem estimating integral

From: Peter

Date: 8 Feb, 2010 18:04:56

Message: 6 of 8

On Jan 26, 3:06 pm, "Andrew " <removet...@removethis.com> wrote:
> Hi
>
> Below is a sequence of steps I've tried so far, without success ... am first trying symbolic integration and then numerical integration using quad. I have followed the help for the latter part and am a little stuck now. Hope someone can help.
>
> syms x
> problem = (2^(1/2)*cos(2*x))/(pi^(1/2)*exp(2*(pi/2 - x)^2))
> int(problem, -inf, inf)
> int(problem, pi/2-.1, pi/2+.1)
>
> "Warning: Explicit integral could not be found." in both cases.
>
> problemvectorized = vectorize(problem)
> problemvectorized = (2.^(1./2).*cos(2.*x))./(pi.^(1./2).*exp(2.*(pi./2 - x).^2))
> inlineproblemvectorized = @(x)problemvectorized
> quad(inlineproblemvectorized, pi/2-.1, pi/2+.1)
>
> "Warning: Maximum function count exceeded; singularity likely. ans = 9.6235"
>
> If we look at the graph it should be about -0.16. Any ideas?
>
> Thanks for taking a look,
>
> Andrew

Perhaps the problem with your numerical evaluation is the fact that
you defined problem to be a symbolic object. Proceeding without the
symbolic definition...

>> problem = @(x)(2^(1/2)*cos(2*x))/(pi^(1/2)*exp(2*(pi/2 - x)^2))
problem =
    @(x)(2^(1/2)*cos(2*x))/(pi^(1/2)*exp(2*(pi/2-x)^2))
>> problemvectorized = vectorize(problem)
problemvectorized =
@(x)(2.^(1./2).*cos(2.*x))./(pi.^(1./2).*exp(2.*(pi./2-x).^2))
>> quad(problemvectorized, pi/2-.1, pi/2+.1)
ans =
   -0.0534

--Peter

Subject: Problem estimating integral

From: Andrew

Date: 13 Feb, 2010 19:19:05

Message: 7 of 8

"Steven Lord" <slord@mathworks.com> wrote in message <hkpd6s$88h$1@fred.mathworks.com>...
>
> "Andrew " <removethis@removethis.com> wrote in message
> news:hkk25m$t54$1@fred.mathworks.com...
>
> *snip*
>
> > Would someone from Mathworks like to respond? It's been a week.
>
> You should submit this as an official Technical Support request using the
> Contact Us link at the top of http://www.mathworks.com.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Thanks Steve for confirming that I'm not making an obvious mistake. Will submit support request!

Cheers,

Andrew

Subject: Problem estimating integral

From: Andrew

Date: 13 Feb, 2010 19:27:06

Message: 8 of 8

Peter <petersamsimon2@hotmail.com> wrote in message <2be5c57b-215f-417f-ae4a-92ee3b96cf37@m35g2000prh.googlegroups.com>...
> On Jan 26, 3:06 pm, "Andrew " <removet...@removethis.com> wrote:
> > Hi
> >
> > Below is a sequence of steps I've tried so far, without success ... am first trying symbolic integration and then numerical integration using quad. I have followed the help for the latter part and am a little stuck now. Hope someone can help.
> >
> > syms x
> > problem = (2^(1/2)*cos(2*x))/(pi^(1/2)*exp(2*(pi/2 - x)^2))
> > int(problem, -inf, inf)
> > int(problem, pi/2-.1, pi/2+.1)
> >
> > "Warning: Explicit integral could not be found." in both cases.
> >
> > problemvectorized = vectorize(problem)
> > problemvectorized = (2.^(1./2).*cos(2.*x))./(pi.^(1./2).*exp(2.*(pi./2 - x).^2))
> > inlineproblemvectorized = @(x)problemvectorized
> > quad(inlineproblemvectorized, pi/2-.1, pi/2+.1)
> >
> > "Warning: Maximum function count exceeded; singularity likely. ans = 9.6235"
> >
> > If we look at the graph it should be about -0.16. Any ideas?
> >
> > Thanks for taking a look,
> >
> > Andrew
>
> Perhaps the problem with your numerical evaluation is the fact that
> you defined problem to be a symbolic object. Proceeding without the
> symbolic definition...
>
> >> problem = @(x)(2^(1/2)*cos(2*x))/(pi^(1/2)*exp(2*(pi/2 - x)^2))
> problem =
> @(x)(2^(1/2)*cos(2*x))/(pi^(1/2)*exp(2*(pi/2-x)^2))
> >> problemvectorized = vectorize(problem)
> problemvectorized =
> @(x)(2.^(1./2).*cos(2.*x))./(pi.^(1./2).*exp(2.*(pi./2-x).^2))
> >> quad(problemvectorized, pi/2-.1, pi/2+.1)
> ans =
> -0.0534
>
> --Peter

Answer's supposed to be -.1574703436 though ... I checked your input above and it seems ok though!

Any other ideas?

Andrew

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