Reputation: 815
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?
As an example, the function I'm trying to integrate is given by:-
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?
Upvotes: 2
Views: 2164
Reputation: 8325
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
Upvotes: 1