http://www.mathworks.com/matlabcentral/newsreader/view_thread/294111
MATLAB Central Newsreader  I have a problem with Quad
Feed for thread: I have a problem with Quad
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Sun, 17 Oct 2010 23:13:04 +0000
I have a problem with Quad
http://www.mathworks.com/matlabcentral/newsreader/view_thread/294111#788503
Mostafa ElHosseini
in the documentation, quad(@f,a,b), and f shoud be a function of x. and x should be a vector.<br>
my case here that x is a matrix with 7 coulmns<br>
i.e what would be the case if x is matrix and i need the 1st coulmn, 2nd coulmn, ....<br>
<br>
below is my case<br>
<br>
function f =fitness(indiv)<br>
global u1 u2 u3<br>
[ro,co] = size(indiv);<br>
score = [];<br>
for i=1:ro<br>
eachrow = indiv(i,:);<br>
u1 = eachrow(:,1); % u1<br>
u2 = eachrow(:,2); % u2<br>
u3 = eachrow(:,3); % u3<br>
PI = quad(@fx,0,.2,1e1);<br>
if (u1 > 20  u2 > 6  u3 > 4)<br>
PI = PI/10; <br>
end<br>
score(i,:)=PI;<br>
end<br>
f = score;<br>
end<br>
===================<br>
<br>
function [ y] = fx( x )<br>
global u1 u2 u3 <br>
[t,x] = solveode(u1,u2,u3);<br>
q = 6.0 + u1 + u2;<br>
%[t,x] = solveode(u1,u2,u3);<br>
% write here the performance Index<br>
y = 5.8*(q*x(:,1)6)3.7*u14.1*u25*u3^2+q*(23*x(:,4)+11*x(:,5)...<br>
+28*x(:,6)+35*x(:,7))0.099;<br>
<br>
end

Sun, 17 Oct 2010 23:58:04 +0000
Re: I have a problem with Quad
http://www.mathworks.com/matlabcentral/newsreader/view_thread/294111#788506
Roger Stafford
"Mostafa ElHosseini" <melhosseini@yahoo.com> wrote in message <i9fvtv$lve$1@fred.mathworks.com>...<br>
> in the documentation, quad(@f,a,b), and f shoud be a function of x. and x should be a vector.<br>
> my case here that x is a matrix with 7 coulmns<br>
> i.e what would be the case if x is matrix and i need the 1st coulmn, 2nd coulmn, ....<br>
> <br>
> below is my case<br>
> <br>
> function f =fitness(indiv)<br>
> global u1 u2 u3<br>
> [ro,co] = size(indiv);<br>
> score = [];<br>
> for i=1:ro<br>
> eachrow = indiv(i,:);<br>
> u1 = eachrow(:,1); % u1<br>
> u2 = eachrow(:,2); % u2<br>
> u3 = eachrow(:,3); % u3<br>
> PI = quad(@fx,0,.2,1e1);<br>
> if (u1 > 20  u2 > 6  u3 > 4)<br>
> PI = PI/10; <br>
> end<br>
> score(i,:)=PI;<br>
> end<br>
> f = score;<br>
> end<br>
> ===================<br>
> <br>
> function [ y] = fx( x )<br>
> global u1 u2 u3 <br>
> [t,x] = solveode(u1,u2,u3);<br>
> q = 6.0 + u1 + u2;<br>
> %[t,x] = solveode(u1,u2,u3);<br>
> % write here the performance Index<br>
> y = 5.8*(q*x(:,1)6)3.7*u14.1*u25*u3^2+q*(23*x(:,4)+11*x(:,5)...<br>
> +28*x(:,6)+35*x(:,7))0.099;<br>
> <br>
> end<br>
        <br>
There seems to be some misunderstanding here about how matlab's 'quad' function works. It will send a number of vectors to its function argument according to its own convenience. These vectors can each have element values lying anywhere within the limits of integration and the vectors may have various lengths  whatever it decides is needed to obtain an accurate integral. It would never send a matrix to the function. The function is required to send back the integrand value for each of the points in the vector at each call.<br>
<br>
As far as I can make out, that is not at all in accordance with the 'fx' function you describe, which in fact appears to discard the x values it is sent and only makes use of the three global scalars u1, u2, and u3. Also to deepen the mystery, 'solveode' appears to be a mathematica function, not a matlab function.<br>
<br>
Could you please clarify your situation?<br>
<br>
Roger Stafford

Mon, 18 Oct 2010 00:22:04 +0000
Re: I have a problem with Quad
http://www.mathworks.com/matlabcentral/newsreader/view_thread/294111#788508
Mostafa ElHosseini
thank you<br>
solveode is my own function<br>
my case is optimization problem, i have a Continuous stirred tabk reactor CSTR with 7 states, the mathemtical model have differential equation like <br>
x1' = f(x1,x2,x3,x5,x6,x7,u1,u2,u3,q)<br>
and so on till<br>
x7' = f(x1,....................................)<br>
q = 6+u1+u2<br>
and the initial condition is given<br>
and i have a performance function that i want to maximize, <br>
PI = integrate from 0 to 0.2 (x1,x2,......q,u1,u2,u3)<br>
<br>
so i want to solve the differential equation of x1' to x7' assuming u1, u2 ,u3 = initila values using my function solveode which call ode45  there is no problem in this part<br>
<br>
then take this value to get the PI "using quad"<br>
<br>
<br>
There seems to be some misunderstanding here about how matlab's 'quad' function works. It will send a number of vectors to its function argument according to its own convenience. These vectors can each have element values lying anywhere within the limits of integration and the vectors may have various lengths  whatever it decides is needed to obtain an accurate integral. It would never send a matrix to the function. The function is required to send back the integrand value for each of the points in the vector at each call.<br>
> <br>
> As far as I can make out, that is not at all in accordance with the 'fx' function you describe, which in fact appears to discard the x values it is sent and only makes use of the three global scalars u1, u2, and u3. Also to deepen the mystery, 'solveode' appears to be a mathematica function, not a matlab function.<br>
> <br>
> Could you please clarify your situation?<br>
> <br>
> Roger Stafford