Numerical integration in Matlab

조회 수: 10 (최근 30일)
Moritz
Moritz 2013년 8월 23일
Hi I want to numerically integrate some function in Matlab using "integral". Say f_int(x). However, f_int can not handle vector inputs. This seems to cause "integral" troubles? Any ideas how to quickly fix this, w/o having to rewrite f_int(x)? Thanks a lot. M

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 8월 23일
Try:
f2_int = @(y)arrayfun(@(x)f_int(x),y);
out = integral(f2_int,a,b); % here a and b - double
  댓글 수: 1
Mike Hosea
Mike Hosea 2013년 8월 24일
편집: Mike Hosea 2013년 8월 24일
Andrei's answer is the way I prefer to do it. However, in a pinch you can leverage the 'Arrayfun',true option to treat the problem as a vector-valued integral (just one that happens to return a vector of only one element)
out = integral(f_int,a,b,'ArrayValued',true);

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by