How can I effectively integrate a function in Matlab?

Hello everyone! I have a function in Matlab that is a product of 3 other complicated functions, like this: I(A,x)=V(x)*R(x)*F(A,x). I need to integrate the function I(A,x) with respect to the variable x in some interval (ex. x=0..x=5), but for each value of the parameter E in some interval (ex. A=0.1.. A=100).
Can anybody help with how to do this in Matlab?
I think I will need a for-loop that iterates over the parameter A in the specified interval, and then integrate over x, but the problem is that matlab won't evaluate the integral. I have for example tried defining the function as a symfun and then integrate it, but the result is something like: int(....) after a very long period of being "busy".
I have considered using "trapz" but I need one value of the integral over I for every value of A, is that possible?
How do I get Matlab to actually evaluate the integral and how can I make it do it reasonable fast?
Thank you in advance.

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 3 Mär. 2017
Bearbeitet: Andrei Bobrov am 3 Mär. 2017
Small example for using:
V = @(x) 2*x+2;
R = @(x) x.^2;
F = @(A,x) x./A-3;
I = @(A,x) V(x)*R(x)*F(A,x);
A = [.1 10 20;40 50 70 ; 80 90 100];
out = integral(@(x)I(A,x),0,5,'ArrayValued',1)

3 Kommentare

User-Mia
User-Mia am 3 Mär. 2017
Bearbeitet: User-Mia am 3 Mär. 2017
Does ArrayValued mean that it evaluate the integral for every specified value of A?
And also, does it work for symbolic functions too?
Torsten
Torsten am 3 Mär. 2017
Bearbeitet: Torsten am 3 Mär. 2017
Small correction:
I = @(A,x) V(x).*R(x).*F(A,x);
"out" will be a 3x3 matrix with
out(i,j)=integral_{0}^{5} V(x)*R(x)*F(A(i,j),x) dx
Best wishes
Torsten.
Thank you both so much.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 3 Mär. 2017

Kommentiert:

am 3 Mär. 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by