Sanaa
Posts:
154
Registered:
3/20/12


Re: Integration with variable limits
Posted:
Aug 15, 2013 9:46 AM


"Torsten" wrote in message <kuih1o$c4g$1@newscl01ah.mathworks.com>... > "Sanaa" wrote in message <kuig3n$9d$1@newscl01ah.mathworks.com>... > > "Steven_Lord" <slord@mathworks.com> wrote in message <ktb57u$el8$1@newscl01ah.mathworks.com>... > > > > > > > > > "Torsten " <Torsten.Hennig@umsicht.fraunhofer.de> wrote in message > > > news:ktad6k$gtn$1@newscl01ah.mathworks.com... > > > > "Torsten" wrote in message <ktacg3$fkj$1@newscl01ah.mathworks.com>... > > > >> "Sanaa" wrote in message <kt9bf4$56h$1@newscl01ah.mathworks.com>... > > > >> > "Torsten" wrote in message <kst5mn$h75$1@newscl01ah.mathworks.com>... > > > >> > > "Sanaa" wrote in message <kss3h5$50n$1@newscl01ah.mathworks.com>... > > > >> > > > "Torsten" wrote in message > > > >> > > > <ksrcel$2k$1@newscl01ah.mathworks.com>... > > > >> > > > > "Sanaa" wrote in message > > > >> > > > > <ksrbia$r0l$1@newscl01ah.mathworks.com>... > > > >> > > > > > Hi all, > > > >> > > > > > How to integrate a function within a loop and the limits of > > > >> > > > > > integration are variables? > > > >> > > > > > For instance, y(i)*(1y(i)) is the function I wish to integrate > > > >> > > > > > from 0.25*i to t where t \in (0.25*i, 0.25*(i+1)). > > > >> > > > > > Any help is really appreciated. > > > >> > > > > > Sanaa Moussa > > > >> > > > > > > > >> > > > > I think y(i)*(1y(i)) is just a real number, not a function, > > > >> > > > > isn't it ? > > > >> > > > > > > > >> > > > > Best wishes > > > >> > > > > Torsten. > > > >> > > > > > > >> > > > Thanks for replying. You are right, but I mean the function is > > > >> > > > y*(1y) which I want to put it into a loop > > > >> > > > My code is > > > >> > > > itermax=300;min=itermax9;% That is we plot from 291:300 i.e. 10 > > > >> > > > values of x only. > > > >> > > > r=0.25; > > > >> > > > for rho=0:0.001:4 > > > >> > > > %x0=0.1; > > > >> > > > x(1)=0.1; > > > >> > > > for i=1:itermax1 > > > >> > > > %t=linspace(i*r,(i+1)*r,itermax) > > > >> > > > y(i+1)=x(i); > > > >> > > > x(i+1)=x(i)+ rho*int(y(i)*(1y(i)),i*r,(i+1)*r); > > > >> > > > end > > > >> > > > %fix(y) > > > >> > > > plot(rho*ones(10),x(min:itermax),'b.','linewidth',0.1) > > > >> > > > hold on > > > >> > > > end > > > >> > > > fsize=15; > > > >> > > > xlabel('\rho','FontSize',fsize) > > > >> > > > ylabel('\itx','FontSize',fsize) > > > >> > > > %title('r=0.25, \alpha=1','FontSize',fsize) > > > >> > > > hold off > > > >> > > > % print(gcf, 'djpeg', 'zbuffer', 'bif.png'); > > > >> > > > > > > >> > > > I get the error > > > >> > > > Function 'int' is not defined for values of class 'double'. > > > >> > > > what does this mean and how to fix it please? > > > >> > > > Many thanks in advance. > > > >> > > > > > >> > > It means what I said before: > > > >> > > y(i)*(1y(i)) is a scalar value and not a function. > > > >> > > So "int" does not know how to handle this because it expects a > > > >> > > function, not a scalar as its first input argument. > > > >> > > > > > >> > > Best wishes > > > >> > > Torsten. > > > >> > > > > >> > Sorry for not posing my question correctly. The function I want to > > > >> > integrate is > > > >> > y(s)*(1y(s)) ds from (n*0.25) to t, and t/in(n*0.25, (n+1)*0.25). > > > >> > Do you have any idea on how to format my code above to solve my > > > >> > problem? > > > >> > Thanks a lot in advance > > > >> > > > >> int_{n*0.25}^{t} (y(s)*(1y(s)) ds = (1/2*t^2  1/3*t^3)  > > > >> (1/2*(n*0.25)^2  1/3*(n*0.25)^3) > > > >> for t/in(n*0.25, (n+1)*0.25). > > > >> Is it that what you asked for ? > > > >> > > > >> Best wishes > > > >> Torsten. > > > > > > > > No sorry, this is wrong  I integrated s*(1s). > > > > For integration, you will have to know the explicit form of y as a > > > > function of s, > > > > e.g. y(s)=sin(s) or something like that. > > > > > > If Y is only known as data, you will need to do one of two things: > > > > > > 1) Use TRAPZ or CUMTRAPZ. > > > 2) Interpolate the Y data to obtain the value of the "function" at > > > intermediate points. This can be dangerous if your data does not > > > sufficiently represent your actual function: > > > > > > x = 0:10 > > > y = sin(x*pi).^2 > > > answer1 = integral(@(t) interp1(x, y, t), 0, 10) > > > syms z > > > answer2 = int(sin(z*pi)^2, 0, 10) > > > > > > Your numeric data makes your function "look like" the constant function y = > > > 0 and so answer1 is very close to 0. The symbolic integration gives an > > > answer2 of 5, which is correct. Evaluating y at more points (x = 0:0.1:10 > > > for example) would show the true form of the curve and gives an answer very > > > close to 5. > > > > > >  > > > Steve Lord > > > slord@mathworks.com > > > To contact Technical Support use the Contact Us link on > > > http://www.mathworks.com > > > > Thank you very much for your discussion and sorry for getting back to you very late. > > Actually, I don't know how to interpolate the data that's why I intended to use cumptrapz. However, there is no posibility to put the bounds of my integration in that function!!! I want to integrate from i*0.25 to t, and t from i*0.25 to (i+1)*0.25!! > > Just for clarification: > How is your function given you want to integrate ? > 1. By data points (x1,y1),(x2,y2),...,(xn,yn) you already calculated beforehand, > 2. By a functional equation, e.g. f(x)=x^2, > 3. By a differential equation dy/dx=y(x)*(1y(x)), > 4. ?? > > Best wishes > Torsten. Tanks a lot for replying. before I make a discretization process, I have the system: y(t) = x(tr), dx/dt = f(y(t)), where f = rho*y(1y). After discretization and integration I have the system y_(n+1)=x_n; x_(n+1)= x_n + integration (f(y_(n+1)(s))) ds.

