From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Integrate this function
Date: Wed, 20 Oct 2010 00:46:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 38
Message-ID: <i9le4c$anl$>
References: <i9h44p$2pr$> <i9i488$a64$> <i9igi0$ski$> <i9j1ur$1vq$> <i9l7kb$i24$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1287535564 10997 (20 Oct 2010 00:46:04 GMT)
NNTP-Posting-Date: Wed, 20 Oct 2010 00:46:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:679712

"Mostafa El-Hosseini" <> wrote in message <i9l7kb$i24$>...
> Dear Roger, 
> thank you again for your patience. Ok. I gree with you now that quad does not fit.
> regarding incorporating the eighth equation into the solver, how can i make that especially i knew that ode45 solve differential equation not integral one.
> really i have no idea about that, can you pls. help
> i can even send you the .m file if you wish, 
> anyway i so grateful for your contribution 
> -- mostafa
- - - - - - - - -
  You stated in your second article of this thread that you have a system of seven differential equations which you solved using 'ode45'.  These would be of the form:

 dx1/dt = f1(x1,x2,x3,x4,x5,x6,x7)
 dx2/dt = f2(x1,x2,x3,x4,x5,x6,x7)
 dx7/dt = f7(x1,x2,x3,x4,x5,x6,x7)

with appropriate initial conditions.  Since you are attempting to integrate y from t = 0 to t = 0.2, it can be assumed that this was also the t interval (tspan) of these differential equations.

  My proposal is that you extend this set of differential equations by adding one more equation which would be:

 dI/dt = y = 5.8*(q*x(:,1)-6)-3.7*u1-4.1*u2-5*u3^2+... etc.

and add the initial condition that 'I' be equal to 0 at the start.  This would be an eighth differential equation.  When 'ode45' has completed its task, besides having discrete values for the seven x's from t = 0 to t = 0.2, you will also have corresponding discrete values for I for these various values of t.  Each of these values will be the integral of y from t = 0 up to the corresponding discrete value of t.  The final value of I at t = 0.2 will give you the integral you wish to find.  (The other values of I are a kind of gratuitous cumulative integral in case you are interested.)

  As you can perhaps see from this discussion, integration is one of the tasks that solving differential equations can accomplish.  For example, suppose you want to find the integral of sin(x) from x = 0 to x = pi/2 (which we all know is 1.)  If you define the variable y as

 y = int(sin(t),'t',0,x); %<--  integral of sin(t) w.r. to t, from t = 0 to t = x

then it is a fundamental theorem of calculus that dy/dx = sin(x).  To find the value of y at x = pi/2 you could set up that single differential equation in 'ode45' starting with y = 0 at x = 0 and set your tspan to [0,pi/2].  The final value of y when 'ode45' finishes will be the desired integral, allowing of course for computation errors.  You should try this experiment to see how close you come to 1.

  That reminds me.  You should take care to set acceptable error tolerances with 'RelTol' and 'AbsTol' settings using 'odeset' when using 'ode45'.  Its default settings may not be as accurate as you would like.

Roger Stafford