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.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2017년 3월 3일
편집: Andrei Bobrov 2017년 3월 3일
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

User-Mia
User-Mia 2017년 3월 3일
편집: User-Mia 2017년 3월 3일
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 2017년 3월 3일
편집: Torsten 2017년 3월 3일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

질문:

2017년 3월 3일

댓글:

2017년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by