Numerical integration in Matlab

6 visualizaciones (últimos 30 días)
Moritz
Moritz el 23 de Ag. de 2013
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

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 23 de Ag. de 2013
Try:
f2_int = @(y)arrayfun(@(x)f_int(x),y);
out = integral(f2_int,a,b); % here a and b - double
  1 comentario
Mike Hosea
Mike Hosea el 24 de Ag. de 2013
Editada: Mike Hosea el 24 de Ag. de 2013
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);

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by