quad con límite de vector

I want to use quad for a list of limits without a for loop. As a basic example

T=[1 2 3];
f=@(x)x.^2
quad(0,T(1),f)

Calculate what I need, but I want to save quad(0,T(1),f) quad(0,T(2),f) quad(0,T(3),f) as a vector. Probably, it is a basic thing but I couldn't find any solution. I'm thankful for any help,

preguntado el 09 de marzo de 12 a las 15:03

2 Respuestas

Utilizan arrayfun:

T=[1 2 3];
f=@(x)x.^2
Q = arrayfun(@(x) quad(f,0,x), T);

*Note that your post has the arguments to quad in an incorrect order.

respondido 09 mar '12, 16:03

Me gusta arrayfun, and use it a lot - but remember that in cases like this (where the function is complicated) that really all you're doing is hiding the for loop. - Edric

This is only here for variety. You could try this Matlab Central entry. As stated on the posting, it's the only vectorized numerical method like this I've seen.

respondido 09 mar '12, 16:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.