Integrate function that calls a function
Mostrar comentarios más antiguos
I'm having trouble integrating a function that contains another function. To give an example:
value = X*func(y)
prob = lognpdf(y, muy, stdy)
int_func = @(y)(value(y)*prob(y))
i.e. I have a function value that depends on a variable y, which is log-normally distributed. The problem is that the multiplication in the first line does not work when done inside the integral function:
>> integral(int_func, 0, 5)
Error using _*_: Innder matrix dimensions must agree
As func(y) creates a matrix, the size of which does not line up with the size of X when it is not passed a scalar as input. It appears that integral() internally passes vectors to the function that is being integrated, which then causes the error. Is there any way around this?
Respuesta aceptada
Más respuestas (1)
Honglei Chen
el 12 de Ag. de 2014
Editada: Honglei Chen
el 12 de Ag. de 2014
1 voto
What is the dimensions of value and prob? What are the operation you want to do?
If the function is vector valued, integral can deal with it by setting 'ArrayValued' to true
1 comentario
Nils
el 13 de Ag. de 2014
Categorías
Más información sobre Numerical Integration and Differentiation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!