Integration using a vector as function parameter
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Mike Hosea
2012년 5월 16일
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!