dblquad function handle help

Hello. I'm facing the following problem:
dblquad('power(x,3)*power(y,3)',0,1,0,1)
Works perfectly fine! But...
dblquad('x^3*y^3',0,1,0,1)
Gives the following error...
Error using inlineeval (line 15)
Error in inline expression ==> x^3*y^3
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
Error in inline/subsref (line 24)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);
Error in quad (line 72)
y = f(x, varargin{:});
Error in dblquad>innerintegral (line 82)
Q(i) = quadf(intfcn, xmin, xmax, tol, trace, y(i), varargin{:});
Error in quad (line 72)
y = f(x, varargin{:});
Error in dblquad (line 58)
Q = quadf(@innerintegral, ymin, ymax, tol, trace, intfcn, ...
So, what I've tried is:
dblquad('x.^3*y.^3',0,1,0,1)
And it works perfectly well. The real problem is that I must define a vector with functions:
k=1;
syms x y
for i=1:n;
for j=1:n;
f(k)=power(x,1+i)*power(y,1+j);
k=k+1;
end
end
And then I must deliver the following code to dblquad:
dblquad(char(f(k)),0,1,0,1);
And char(f(k)) gives me 'x^(1+i)*y^(j+1)' form, which dblquad can't handle. (Noting that "i" and "j" are now real numbers, arbitrary.)
Any ideas?

 채택된 답변

Walter Roberson
Walter Roberson 2012년 5월 23일

0 개 추천

char() isn't going to give you that unless you are using the symbolic toolbox. If you are, see matlabFunction()
Also see vectorize()
Passing strings in instead of function handles is no longer recommended.

댓글 수: 2

Cyberz
Cyberz 2012년 5월 23일
Is there a way in which I could write my functions as a real function handles?
The functions I need to define are the same as in the question.
Cyberz
Cyberz 2012년 5월 23일
Yay
Vectorize works perfectly fine! ;)
dblquad(vectorize(f(k)),0,1,0,1);
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by