1

I want to integrate a given matrix elementwise using quadgk command, where the entries of my matrix are highly oscillatory functions. It seems the command integral got the option 'ArrayValued', whereas quadgk doesn't. Here I give a simplified example of what I'm aiming to do - the actual matrix I'm working on is way more complicated and has actually no explicit form, since it's the result of many prior intricate operations of inversions, truncations and multiplications. So here's what I'm doing.

First I define the function my_fun which generates my matrix in a separate file like this :

function f = my_fun(x)
f = [x x^2];

Next, in the main code I call it and try to integrate it elementwise from, say, 0 to 1 :

x = 0:.01:1;
g = @(x) my_fun(x);
Q = quadgk(g,0,1);

With the command integral I have no problem doing it, but with quadgk it doesn't work. Thanks !

Mokrane
  • 11
  • 1
  • Unfortunately, there is no reasonable way to get quadgk to work with a function handle corresponding to a vector/matrix output. However, you might get good results by reducing the error tolerance for `integral`. For instance, you could try `integral(f,0,1,'ArrayValued',true,'RelTol',1e-9)`. – Ben Grossmann Jan 13 '22 at 16:57
  • Do you think there'd be something similar on Python if I all switch to it ? – Mokrane Jan 13 '22 at 18:08
  • There definitely is something similar in python which works correctly with vector/matrix-valued functions – Ben Grossmann Jan 13 '22 at 18:55

0 Answers0