2

Let's say I have a function which takes a real number x and returns a matrix M(x). How do I evaluate the following?

enter image description here

As an example, the function I'm trying to integrate is given by:-

enter image description here

Here, k is a constant and A is a matrix.

I tried using the int function, but it seems to work only for scalar functions. I'm new to Matlab. Could someone help me out?

Train Heartnet
  • 785
  • 1
  • 12
  • 24
  • please, provide an example of M(x) – brainkz Dec 27 '15 at 09:01
  • you do it numericaly, e.g http://www.mathworks.com/help/matlab/ref/integral.html – Nikos M. Dec 27 '15 at 09:02
  • 3
    if you have a matrix then you integrate each matrix element itself, using previous link – Nikos M. Dec 27 '15 at 09:18
  • @brainkz: I've edited the question for an example. – Train Heartnet Dec 27 '15 at 09:21
  • @NikosM. Thank you! I'll get back to you if I encounter difficulties. – Train Heartnet Dec 27 '15 at 09:22
  • @AntonSchigur, sure, if this solves your issue i can add an answer as well – Nikos M. Dec 27 '15 at 09:32
  • @AntonSchigur you might find this [post](http://www.mathworks.com/matlabcentral/answers/38572-integration-using-a-vector-as-function-parameter) on how to vectorize integration helpful (ii.e integrate matrix without loops per element as one command) – Nikos M. Dec 27 '15 at 09:44
  • 1
    a similar [question on scicomp](http://scicomp.stackexchange.com/questions/8198/integration-of-matrix-valued-function-using-matlab) which points to same direction – Nikos M. Dec 27 '15 at 09:48
  • @NikosM.: Thank you so much for taking the time to help me! The link to scicomp had exactly what I was looking for! Please post it as an answer so that I may accept it. :) – Train Heartnet Dec 27 '15 at 14:51

1 Answers1

1

Matlab (latest, 2015) provides the integral function to numericaly compute integrals of functions

For functions that have a multi-dimensional domain (e.g matrix-valued functions) you can use the 'ArrayValued',true option

Vector-Valued Function

Create the vector-valued function

f(x) = [sin x, sin 2x, sin 3x, sin 4x, sin 5x]

and integrate from x=0 to x=1. Specify 'ArrayValued',true to evaluate the integral of an array-valued or vector-valued function.

fun = @(x)sin((1:5)*x);
q = integral(fun,0,1,'ArrayValued',true)

q =

0.4597    0.7081    0.6633    0.4134    0.1433

Alternatively, you can integrate the matrix-valued function element-wise, i.e per-element using loops, plus, one can also try to vectorize the operation to one without-loops (for example see here)

related question on scicomp.se

Community
  • 1
  • 1
Nikos M.
  • 8,033
  • 4
  • 36
  • 43