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:
Calculating the limit of an integral

Subject: Calculating the limit of an integral

From: Haojie

Date: 29 Mar, 2012 22:15:16

Message: 1 of 5

Hi all, I'm new to matlab. I have a implicit equation that the limit (t) is unknow. And t is also in the integrand. x is the variable
The equation is like
int(sqrt(A*x^(2/7)-A*t^(2/7)),0,t)-int(sqrt(A*t^(2/7)-A*x^(2/7),t,1)=0
It might not be in the matlab grammar.
I want to solve for t numerically but im stuck and dont know how to do that.

Thanks in advance.

Subject: Calculating the limit of an integral

From: Roger Stafford

Date: 30 Mar, 2012 00:50:47

Message: 2 of 5

"Haojie" wrote in message <jl2mtk$a37$1@newscl01ah.mathworks.com>...
> ..... I have a implicit equation that the limit (t) is unknow. And t is also in the integrand. x is the variable
> The equation is like
> int(sqrt(A*x^(2/7)-A*t^(2/7)),0,t)-int(sqrt(A*t^(2/7)-A*x^(2/7),t,1)=0
> I want to solve for t numerically .......
- - - - - - - - -
  I assume A is a negative scalar. Otherwise you would be taking the square roots of negative quantities. Other than that I don't see the purpose in including A here. The square root of -A can be factored out.

  Also you are missing a right parenthesis on the second square root.

  You can probably solve this using matlab's 'fzero' routine. However, its function handle will have to be written so as to perform numerical quadrature on a vector of different t values passed to it, two integrations for each t element.

Roger Stafford

Subject: Calculating the limit of an integral

From: Haojie

Date: 30 Mar, 2012 13:52:12

Message: 3 of 5

"Roger Stafford" wrote in message <jl3017$adm$1@newscl01ah.mathworks.com>...
> "Haojie" wrote in message <jl2mtk$a37$1@newscl01ah.mathworks.com>...
> > ..... I have a implicit equation that the limit (t) is unknow. And t is also in the integrand. x is the variable
> > The equation is like
> > int(sqrt(A*x^(2/7)-A*t^(2/7)),0,t)-int(sqrt(A*t^(2/7)-A*x^(2/7),t,1)=0
> > I want to solve for t numerically .......
> - - - - - - - - -
> I assume A is a negative scalar. Otherwise you would be taking the square roots of negative quantities. Other than that I don't see the purpose in including A here. The square root of -A can be factored out.
>
> Also you are missing a right parenthesis on the second square root.
>
> You can probably solve this using matlab's 'fzero' routine. However, its function handle will have to be written so as to perform numerical quadrature on a vector of different t values passed to it, two integrations for each t element.
>
> Roger Stafford
Thanks for your reply.
Do you mean I should write like this?
function y1 = f1(x);
function y2 = f2(x);
y1 = sqrt(t^(2/7)-x^(2/7));
y2 = sqrt(x^(2/7)-t^(2/7));
Q1 = quad(@f1,0,t);
Q2 = quad(@f2,t,1);
But then I dont know how to use fzero to calculate t, because Q1 - Q2=0 is not a function so cannot be used in fzero. I dont know if you mean this or please correct me if I understand wrong

Subject: Calculating the limit of an integral

From: Roger Stafford

Date: 30 Mar, 2012 21:02:11

Message: 4 of 5

"Haojie" wrote in message <jl4dqc$f8c$1@newscl01ah.mathworks.com>...
> But then I dont know how to use fzero to calculate t, because Q1 - Q2=0 is not a function so cannot be used in fzero. I dont know if you mean this or please correct me if I understand wrong
- - - - - - - - - -
  Do something like this. First write a function:

function q = Haojiefun(t)
 q = quad(@(x) sqrt(t^(2/7)-x.^(2/7)),0,t) ...
    -quad(@(x) sqrt(x.^(2/7)-t^(2/7)),t,1);
return

This constitutes a perfectly respectable function of t. For each possible value of t between 0 and 1 there is a corresponding value of q. (You may want to use other quadrature functions, quadl or quadgk. Also you may want to specify error tolerances in them.)

  Then use this function as a handle into 'fzero'.

 T = fzero(@Haojiefun,[0,1]);

It should return with the desired T root. It is a good practice to first use your (Haojiefun) function (in a for-loop) to make a plot of q versus t to see if there are multiple roots (or any at all) between 0 and 1.

  (Note: Earlier I asserted that your function (Haojiefun) would have to be able to accept vector inputs, but that is not true. The variable t sent to it by 'fzero' will just be a scalar. However, the functions called on by 'quad' do need to accept vectors, and hence the "x.^(2/7)" notation.)

Roger Stafford

Subject: Calculating the limit of an integral

From: Haojie

Date: 2 Apr, 2012 16:09:13

Message: 5 of 5

"Roger Stafford" wrote in message <jl570j$qfs$1@newscl01ah.mathworks.com>...
> "Haojie" wrote in message <jl4dqc$f8c$1@newscl01ah.mathworks.com>...
> > But then I dont know how to use fzero to calculate t, because Q1 - Q2=0 is not a function so cannot be used in fzero. I dont know if you mean this or please correct me if I understand wrong
> - - - - - - - - - -
> Do something like this. First write a function:
>
> function q = Haojiefun(t)
> q = quad(@(x) sqrt(t^(2/7)-x.^(2/7)),0,t) ...
> -quad(@(x) sqrt(x.^(2/7)-t^(2/7)),t,1);
> return
>
> This constitutes a perfectly respectable function of t. For each possible value of t between 0 and 1 there is a corresponding value of q. (You may want to use other quadrature functions, quadl or quadgk. Also you may want to specify error tolerances in them.)
>
> Then use this function as a handle into 'fzero'.
>
> T = fzero(@Haojiefun,[0,1]);
>
> It should return with the desired T root. It is a good practice to first use your (Haojiefun) function (in a for-loop) to make a plot of q versus t to see if there are multiple roots (or any at all) between 0 and 1.
>
> (Note: Earlier I asserted that your function (Haojiefun) would have to be able to accept vector inputs, but that is not true. The variable t sent to it by 'fzero' will just be a scalar. However, the functions called on by 'quad' do need to accept vectors, and hence the "x.^(2/7)" notation.)
>
> Roger Stafford

I really appreciate your help. It works perfectly. Thanks.

HJ

Tags for 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