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 个评论

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.
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