Integral function, input parameter and output as vectors?

조회 수: 1 (최근 30일)
Robin Hellmers
Robin Hellmers 2015년 11월 27일
답변: Star Strider 2015년 11월 27일
Hi!
I know that if I want several different integral values into a vector, I could use this loop:
int = [];
for i = 1:5
A = integral(@(y) func(y), 0, i);
int = [int, A];
end
But is it in any way possible to put in a vector instead of making this loop? Something like:
B = 1:5;
A = integral(@(y) func(y), 0, B);
isvector(A) %I want this to be true then.
And thereby get a vector A?

답변 (1개)

Star Strider
Star Strider 2015년 11월 27일
Trying your code with the exp function:
B = 1:5;
A = integral(@exp, 0, B);
it throws the error ‘A and B must be floating-point scalars.’. So the short answer is: No!
However, not knowing what ‘func(y)’ actually is and not being clear on what you want to do, it is possible to integrate array-valued functions if you set the name-value pair 'ArrayValued in integral to true or 1.
For example, you might change your integral call to:
B = 1:5;
A = integral(@(y) exp(B.*y), 0, 1, 'ArrayValued',1);
That syntax works.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by