[scilab-Users] Integration of a piecewise function

Michaël Baudin michael.baudin at scilab.org
Mon Nov 8 10:54:39 CET 2010


  Hi,

I tested your script and found that reducing the absolute tolerance 
allows me to get a result:

-->integrate('TranchantNum(x,x1,Vnum)','x',0,15,0.02)
  ans  =
   - 3204.7066

With 0.02 of absolute tolerance for an integral of -3204.7066 means that 
you get more than 5 significant digits.
Notice also that you may use the "find" function instead of using a for 
loop: this should perform way faster.

Best regards,

Michaël Baudin

Le 16/10/2010 14:43, xavier roguiez a écrit :
> Hello,
>
> I've got the following problem, i need to perform successively two
> integrations along the x axis of a beam.
> It's consumming large time and memory. And the calculation doesn't
> converge at the end...
>
> I've tried to cut my problem in two parts. I've performed (quite
> rapidely) the first integration and store the result in a vector Vnum.
>
> And i've (naively) try to build a function which is giving the value of
> V at the x position (in order to avoid the last integration).
>
> function [V]=TranchantNum(u,x,Vnum)
> for i=1:size(x,1),
>     if (u<=x(i)) then
>       V=Vnum(i);
>       break,
>     end
>   end
> endfunction
>
> where Vnum is the result of the last integration, x is a vector which
> contains the position (0:0.1:50)', and u is the position along the x
> axis where I need the information.
>
> Then
> x1=x
> for i=1:size(x,1),
>    M(i)=integrate('TranchantNum(x,x1,Vnum)','x',0,x(i))
> end
> The loop is ok for first value, because Vnum is quite continuous, but
> for further values, discontinuities appears in Vnum.
>
> And I've got the following messages :
> -->integrate('TranchantNum(x,x1,Vnum)','x',0,15)
>   !--error 24
> Problème de convergence ...
>
> at line      70 of function integrate called by :
> integrate('TranchantNum(x,x1,Vnum)','x',0,15)
>
> Does anybody has an idea to solve or reformulate my problem ?
>
> Thanks in advance for any information
> xavier
>
> PS : I join the data of x and Vnum, in order to test my code, i'm
> executing the following code
> temp=read('donnees.txt',548,2);
> x=temp(:,1);
> Vnum=temp(:,2);
>
> PS : i've tried another formulation of TranchantNum
> function [y]=TranchantNum2(u,x,Vnum)
>    pas=0.1
>   y=sum(bool2s((x>=u-pas/2)&(x<=u+pas/2)).*Vnum)
> endfunction
> which is more compact, but the result is the same.
>


-- 
Michaël Baudin
Ingénieur de développement
michael.baudin at scilab.org
-------------------------
Consortium Scilab - Digiteo
Domaine de Voluceau - Rocquencourt
B.P. 105 - 78153 Le Chesnay Cedex
Tel. : 01 39 63 56 87 - Fax : 01 39 63 55 94





More information about the users mailing list