Thread Subject: definite integral

Subject: definite integral

From: Semih

Date: 7 Aug, 2008 09:05:04

Message: 1 of 9

Hello! I want to compute the following equation numerically
from 0 to 1 and I tried it with "quad" command. Then I took
an error which says "it must have an feval method" which I
can not understand. If I try with "int" command it gives
elliptic functions. Can you advice any other method to
perform this numerical integral operation?

I=sqrt((1-x^2)/(((1-rho)^-1)-x^2)) with taking rho=0.8

Subject: definite integral

From: Steven Lord

Date: 7 Aug, 2008 12:53:21

Message: 2 of 9


"Semih " <gereksizbirsuruseyicin@gmail.com> wrote in message
news:g7edrv$c51$1@fred.mathworks.com...
> Hello! I want to compute the following equation numerically
> from 0 to 1 and I tried it with "quad" command. Then I took
> an error which says "it must have an feval method" which I
> can not understand. If I try with "int" command it gives
> elliptic functions. Can you advice any other method to
> perform this numerical integral operation?
>
> I=sqrt((1-x^2)/(((1-rho)^-1)-x^2)) with taking rho=0.8

QUAD expects the integrand to be a function handle. From the fact that you
mentioned this works with INT, I suspect that I is a sym object. If you
want to obtain a double precision value from INT, specify limits of
integration and use the DOUBLE function -- if you want a "sym object that is
a number" use VPA.


syms x
rho = 0.8;
I=sqrt((1-x^2)/(((1-rho)^-1)-x^2));
value = int(I, x, 0, 1)
doubleValue = double(value) % This is the double representation of value
vpaValue = vpa(value) % This is value calculated to some number of decimal
places


If instead you wanted to use QUAD, you would need to use a function handle:


rho = 0.8;
% I'm assuming you're using MATLAB 7.0 (R14) or later, and so have access to
anonymous functions
% If not, see Q4.13 in the newsgroup FAQ:
% http://matlabwiki.mathworks.com/MATLAB_FAQ
% for how to pass rho into your integrand function
If= @(x) sqrt((1-x.^2)./(((1-rho)^-1)-x.^2));
value2 = quad(If, 0, 1)


Note value2, doubleValue, and vpaValue will not be identical -- QUAD
calculates the integral to within a tolerance, while value (from which
doubleValue and vpaValue are calculated) is computed exactly symbolically.

--
Steve Lord
slord@mathworks.com

Subject: definite integral

From: Semih

Date: 7 Aug, 2008 13:55:20

Message: 3 of 9

Thank you very much for the solution. Now it works well !!!

"Steven Lord" <slord@mathworks.com> wrote in message
<g7er81$olm$1@fred.mathworks.com>...
>
> "Semih " <gereksizbirsuruseyicin@gmail.com> wrote in message
> news:g7edrv$c51$1@fred.mathworks.com...
> > Hello! I want to compute the following equation numerically
> > from 0 to 1 and I tried it with "quad" command. Then I took
> > an error which says "it must have an feval method" which I
> > can not understand. If I try with "int" command it gives
> > elliptic functions. Can you advice any other method to
> > perform this numerical integral operation?
> >
> > I=sqrt((1-x^2)/(((1-rho)^-1)-x^2)) with taking rho=0.8
>
> QUAD expects the integrand to be a function handle. From
the fact that you
> mentioned this works with INT, I suspect that I is a sym
object. If you
> want to obtain a double precision value from INT, specify
limits of
> integration and use the DOUBLE function -- if you want a
"sym object that is
> a number" use VPA.
>
>
> syms x
> rho = 0.8;
> I=sqrt((1-x^2)/(((1-rho)^-1)-x^2));
> value = int(I, x, 0, 1)
> doubleValue = double(value) % This is the double
representation of value
> vpaValue = vpa(value) % This is value calculated to some
number of decimal
> places
>
>
> If instead you wanted to use QUAD, you would need to use a
function handle:
>
>
> rho = 0.8;
> % I'm assuming you're using MATLAB 7.0 (R14) or later, and
so have access to
> anonymous functions
> % If not, see Q4.13 in the newsgroup FAQ:
> % http://matlabwiki.mathworks.com/MATLAB_FAQ
> % for how to pass rho into your integrand function
> If= @(x) sqrt((1-x.^2)./(((1-rho)^-1)-x.^2));
> value2 = quad(If, 0, 1)
>
>
> Note value2, doubleValue, and vpaValue will not be
identical -- QUAD
> calculates the integral to within a tolerance, while value
(from which
> doubleValue and vpaValue are calculated) is computed
exactly symbolically.
>
> --
> Steve Lord
> slord@mathworks.com
>
>

Subject: definite integral

From: surya makireddi

Date: 21 Sep, 2008 03:13:07

Message: 4 of 9

"Semih " <gereksizbirsuruseyicin@gmail.com> wrote in message <g7eus8$8a4$1@fred.mathworks.com>...
> Thank you very much for the solution. Now it works well !!!
>
> "Steven Lord" <slord@mathworks.com> wrote in message
> <g7er81$olm$1@fred.mathworks.com>...
> >
> > "Semih " <gereksizbirsuruseyicin@gmail.com> wrote in message
> > news:g7edrv$c51$1@fred.mathworks.com...
> > > Hello! I want to compute the following equation numerically
> > > from 0 to 1 and I tried it with "quad" command. Then I took
> > > an error which says "it must have an feval method" which I
> > > can not understand. If I try with "int" command it gives
> > > elliptic functions. Can you advice any other method to
> > > perform this numerical integral operation?
> > >
> > > I=sqrt((1-x^2)/(((1-rho)^-1)-x^2)) with taking rho=0.8
> >
> > QUAD expects the integrand to be a function handle. From
> the fact that you
> > mentioned this works with INT, I suspect that I is a sym
> object. If you
> > want to obtain a double precision value from INT, specify
> limits of
> > integration and use the DOUBLE function -- if you want a
> "sym object that is
> > a number" use VPA.
> >
> >
> > syms x
> > rho = 0.8;
> > I=sqrt((1-x^2)/(((1-rho)^-1)-x^2));
> > value = int(I, x, 0, 1)
> > doubleValue = double(value) % This is the double
> representation of value
> > vpaValue = vpa(value) % This is value calculated to some
> number of decimal
> > places
> >
> >
> > If instead you wanted to use QUAD, you would need to use a
> function handle:
> >
> >
> > rho = 0.8;
> > % I'm assuming you're using MATLAB 7.0 (R14) or later, and
> so have access to
> > anonymous functions
> > % If not, see Q4.13 in the newsgroup FAQ:
> > % http://matlabwiki.mathworks.com/MATLAB_FAQ
> > % for how to pass rho into your integrand function
> > If= @(x) sqrt((1-x.^2)./(((1-rho)^-1)-x.^2));
> > value2 = quad(If, 0, 1)
> >
> >
> > Note value2, doubleValue, and vpaValue will not be
> identical -- QUAD
> > calculates the integral to within a tolerance, while value
> (from which
> > doubleValue and vpaValue are calculated) is computed
> exactly symbolically.
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> >
> >
>

Subject: definite integral

From: surya makireddi

Date: 21 Sep, 2008 03:13:07

Message: 5 of 9

this is a problem about definite integrals.
say, g=int(f,x,a,b) where f is the expression,v is the variable.(i put g in the while loop so that i have a range of g values)i change x into a symbolic to perform the integration.later i wanted to plot g,x.but i cant because of the 'syms x' i did before.
any help would be used
thanks
sunny

Subject: definite integral

From: amaren

Date: 22 Sep, 2008 12:38:19

Message: 6 of 9

On Sep 21, 8:13=A0am, "surya makireddi" <vitha...@yahoo.com.au> wrote:
> this is a problem about definite integrals.
> say, g=3Dint(f,x,a,b) where f is the expression,v is the variable.(i put =
g in the while loop so that i have a range of g values)i change x into a sy=
mbolic to perform the integration.later i wanted to plot g,x.but i cant bec=
ause of the 'syms x' i did before.
> any help would be used
> thanks
> sunny

how can u plot w.r.t x it is a pseudo variable used only for
integration. x is not aarray of values.

Subject: definite integral

From: Walter Roberson

Date: 22 Sep, 2008 13:57:38

Message: 7 of 9

amaren wrote:
> On Sep 21, 8:13 am, "surya makireddi" <vitha...@yahoo.com.au> wrote:
>> this is a problem about definite integrals.
>> say, g=int(f,x,a,b) where f is the expression,v is the variable.(i put g
>> in the while loop so that i have a range of g values)i change x into a
>> symbolic to perform the integration.later i wanted to plot g,x.but i cant
>> because of the 'syms x' i did before.

> how can u plot w.r.t x it is a pseudo variable used only for
> integration. x is not aarray of values.

What I got out of the posting is that Surya has calculated a formula
symbolically and now wants to plot the calculated formula over a range
of values.

I don't know the expected Matlab way of doing this. If I were using
Maple directly, then Maple's plot() accepts a function or symbolic
expression; or in Maple I would use seq() or subs() or eval() or
map() to get a list of values to plot.

Subject: definite integral

From: Steven Lord

Date: 22 Sep, 2008 14:38:11

Message: 8 of 9


"surya makireddi" <vithalsm@yahoo.com.au> wrote in message
news:gb4e43$dc3$1@fred.mathworks.com...
> this is a problem about definite integrals.
> say, g=int(f,x,a,b) where f is the expression,v is the variable.(i put g
> in the while loop so that i have a range of g values)i change x into a
> symbolic to perform the integration.later i wanted to plot g,x.but i cant
> because of the 'syms x' i did before.
> any help would be used
> thanks
> sunny

Two options:

1) Use EZPLOT.

2) SUBS numeric values for x into the symbolic expression g, convert it to a
DOUBLE if necessary, then PLOT the double array.

Take a look at the HELP for any of the words in all caps above for more
information.

--
Steve Lord
slord@mathworks.com

Subject: definite integral

From: surya makireddi

Date: 24 Sep, 2008 13:29:02

Message: 9 of 9

thanks a lot for the reply steve. infact i tried using ezplot and the subs,maybe i should go over it again.
thanks
sunny

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com