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?

 Réponse acceptée

Walter Roberson
Walter Roberson le 23 Mai 2012

0 votes

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 commentaires

Cyberz
Cyberz le 23 Mai 2012
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 le 23 Mai 2012
Yay
Vectorize works perfectly fine! ;)
dblquad(vectorize(f(k)),0,1,0,1);
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Function Creation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by