Integration using a vector as function parameter
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm a recent joinee to the MATLAB community and have what I think is fairly simple question but can't seem to find the answer so maybe its less simple than I think.
I have a vector containing a string of data and want to use that data to provide a single parameter in a function for definite integration.
Ultimately I want to write a function that will return a vector that contains the definite integrals of this function using the previous vector as a parameter of the function.
i.e.
N=[1:4];
Crush = @(x,n) x.^n;
M = quad(crush(x,N),0,2);
I know that this doesn't work at least in this form because quad will not accept a function with argument, but hopefully my intention is clear. I was wondering if there is a way to do this without resorting to a complex for/while loop. I suspect that it can be done by nesting functions and I'm just missing something very simple. I'm using x^n as an example for the function.
Thanks for any help,
Paul
0 comentarios
Respuesta aceptada
Mike Hosea
el 16 de Mayo de 2012
Not sure of your intention. This is how I interpreted what you wrote:
>> N = 1:4;
>> Crush = @(x,n) x.^n;
>> integral(@(x)Crush(x,N),0,2,'ArrayValued',true)
ans =
2 2.6667 4 6.4
>> quadv(@(x)Crush(x,N),0,2)
ans =
2 2.6667 4 6.4
Use INTEGRAL for 12a and later, QUADV for 11b and earlier releases of MATLAB. -- Mike
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!