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:
I have a problem with Quad

Subject: I have a problem with Quad

From: Mostafa El-Hosseini

Date: 17 Oct, 2010 23:13:04

Message: 1 of 3

in the documentation, quad(@f,a,b), and f shoud be a function of x. and x should be a vector.
my case here that x is a matrix with 7 coulmns
i.e what would be the case if x is matrix and i need the 1st coulmn, 2nd coulmn, ....

below is my case

function f =fitness(indiv)
global u1 u2 u3
[ro,co] = size(indiv);
score = [];
for i=1:ro
    eachrow = indiv(i,:);
    u1 = eachrow(:,1); % u1
    u2 = eachrow(:,2); % u2
    u3 = eachrow(:,3); % u3
    PI = quad(@fx,0,.2,1e-1);
    if (u1 > 20 || u2 > 6 || u3 > 4)
        PI = PI/10;
    end
    score(i,:)=PI;
end
f = score;
end
===================

function [ y] = fx( x )
global u1 u2 u3
[t,x] = solveode(u1,u2,u3);
q = 6.0 + u1 + u2;
%[t,x] = solveode(u1,u2,u3);
% write here the performance Index
y = 5.8*(q*x(:,1)-6)-3.7*u1-4.1*u2-5*u3^2+q*(23*x(:,4)+11*x(:,5)...
    +28*x(:,6)+35*x(:,7))-0.099;

end

Subject: I have a problem with Quad

From: Roger Stafford

Date: 17 Oct, 2010 23:58:04

Message: 2 of 3

"Mostafa El-Hosseini" <melhosseini@yahoo.com> wrote in message <i9fvtv$lve$1@fred.mathworks.com>...
> in the documentation, quad(@f,a,b), and f shoud be a function of x. and x should be a vector.
> my case here that x is a matrix with 7 coulmns
> i.e what would be the case if x is matrix and i need the 1st coulmn, 2nd coulmn, ....
>
> below is my case
>
> function f =fitness(indiv)
> global u1 u2 u3
> [ro,co] = size(indiv);
> score = [];
> for i=1:ro
> eachrow = indiv(i,:);
> u1 = eachrow(:,1); % u1
> u2 = eachrow(:,2); % u2
> u3 = eachrow(:,3); % u3
> PI = quad(@fx,0,.2,1e-1);
> if (u1 > 20 || u2 > 6 || u3 > 4)
> PI = PI/10;
> end
> score(i,:)=PI;
> end
> f = score;
> end
> ===================
>
> function [ y] = fx( x )
> global u1 u2 u3
> [t,x] = solveode(u1,u2,u3);
> q = 6.0 + u1 + u2;
> %[t,x] = solveode(u1,u2,u3);
> % write here the performance Index
> y = 5.8*(q*x(:,1)-6)-3.7*u1-4.1*u2-5*u3^2+q*(23*x(:,4)+11*x(:,5)...
> +28*x(:,6)+35*x(:,7))-0.099;
>
> end
- - - - - - - - -
  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.

  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.

  Could you please clarify your situation?

Roger Stafford

Subject: I have a problem with Quad

From: Mostafa El-Hosseini

Date: 18 Oct, 2010 00:22:04

Message: 3 of 3

thank you
solveode is my own function
my case is optimization problem, i have a Continuous stirred tabk reactor CSTR with 7 states, the mathemtical model have differential equation like
x1' = f(x1,x2,x3,x5,x6,x7,u1,u2,u3,q)
and so on till
x7' = f(x1,....................................)
q = 6+u1+u2
and the initial condition is given
and i have a performance function that i want to maximize,
PI = integrate from 0 to 0.2 (x1,x2,......q,u1,u2,u3)

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

then take this value to get the PI "using quad"


  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.
>
> 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.
>
> Could you please clarify your situation?
>
> Roger Stafford

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