Trying to do a quad on the positions in a vector

I try to do it like this:
syms x
RR = [x.^2 x.^3 x];
q = quad(@(x)RR(1),0,2);
disp(q)
But when I run it it gives me this error:
??? Undefined function or method 'isfinite' for input arguments of type 'sym'.
Error in ==> quad at 81
if ~isfinite(y(1))
Error in ==> Untitled at 5
q = quad(@(x)RR(1),0,2);
If I try it like this:
syms x
RR = x.^2;
q = quad(@(x)RR,0,2);
disp(q)
It gives me the same error:
??? Undefined function or method 'isfinite' for input arguments of type 'sym'.
Error in ==> quad at 81
if ~isfinite(y(1))
Error in ==> Untitled at 5
q = quad(@(x)RR,0,2);
But if I do it like this:
syms x
RR = @(x)x.^2;
q = quad(RR,0,2);
disp(q)
It works. So my problem is that I got a vector with functions in it on which I would like to use quad on each of the functions, one at a time. Is this possible?

 채택된 답변

Andrew Newell
Andrew Newell 2011년 5월 2일

2 개 추천

quad is not defined for symbolic variables. Do this instead:
syms x
RR = [x.^2 x.^3 x];
q = int(RR,0,2)
EDIT: The reason your last example works is that the variable x in the anonymous function definition is a dummy variable and has no relation to the symbolic variable x in the line above. So what you get is a function of a double precision variable. This approach can be extended as follows:
RR = @(x)[x.^2 x.^3 x];
q = quadv(RR,0,2)

추가 답변 (1개)

maia
maia 2013년 1월 26일

0 개 추천

if i write RR = x.^2; RR = @(x)RR q = quadv(RR,0,2)
it give me error why?
??? Undefined function or method 'isfinite' for input arguments of type 'sym'.
Error in ==> quadv at 62 if any(~isfinite(y{1}(:)))
Error in ==> testcode2 at 4 q = quadv(RR,0,2);

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

Jon
2011년 5월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by