Search code examples
matlabcell

Quad in a cell of handle functions


I have two lists of functions, for instance: log(n*x), n=1:2017 and cos(m*x), m=1:6. I want/need to construct the matrix product of these vectors and then integrating each element of the matrix between 10 and 20.

I have read this post: Matrix of symbolic functions but I think that it is not useful for this problem. I'm trying to do this by using a loop but I can not get it.

Thanks in advance for reading it.


Solution

  • You can solve this problem by assigning the appropriate vectors to n and m as follows:

    n = (1:2017)'; % column vector
    m = 1:6; % row vector
    
    syms x;
    l = log(n*x); % column vector of logs
    c = cos(m*x); % row vector of cos
    
    product = l*c; % matrix product
    i = int(product, x, 10, 20); % integral from 10 to 20
    iDouble = double(i); % convert the result to double