필터 지우기
필터 지우기

definite double integration-dblquad-int

조회 수: 2 (최근 30일)
Victor
Victor 2011년 5월 21일
Dear all,
I have a long equation that I would like to have its definite double integration.
Let’s suppose this integration:
(2*sin(x)+cos(x))^2
Please pay attention that I did not expand the equation and I did not use “ .^ ” in it.
Since symbols are expensive I prefer not to use symbols like this:
syms x y;
integrand = @(x,y) (2*sin(x)+cos(x))^2;
doubleintegration=double(int(int(integrand(x,y),0,pi),0,2*pi))
Also, if I want to use “dblquad” it does not expand the equation. I should expand it then use following equation
doubleintegration= dblquad(@(x,y) (cos(x).^2 + 4.*cos(x).*sin(x) + 4.*sin(x).^2) ,0, pi, 0, 2*pi)
Is there any way that I do not use symbols (not expensive computation) in normal integration or not expand my long equation and then use “dblquad”?
Any idea is appreciated. Thanks in advance

채택된 답변

Andrew Newell
Andrew Newell 2011년 5월 21일
I think you may be confusing vectorizing with expansion. You would need to vectorize your integrand to use dblquad, but you don't need to expand it. Your equation could look like this:
doubleintegration= dblquad(@(x,y) (2*sin(x)+cos(x)).^2 ,0, pi, 0, 2*pi);
It shouldn't be hard to do this. Just use search and replace to substitute .* for *, .^ for ^ and ./ for /.
EDIT: The comments below may help or may add to the confusion. Think of it this way:
B = (2*sin(x)+cos(x)).^2;
is equivalent to
A = 2*sin(x)+cos(x);
B = A.^2;
so, for example, inserting these values for x
x = [0 pi/2];
gives
B = (2*sin(x)+cos(x)).^2
ans =
1 4
This is equivalent to the expansion
B = cos(x).^2 + 4.*cos(x).*sin(x) + 4.*sin(x).^2
ans =
1 4
Now try
B = (2*sin(x)+cos(x))^2
??? Error using ==> mpower
Inputs must be a scalar and a square matrix.
It's the same error you would get if you tried
[1 2]^2
Thanks for the tip about vectorize. It's amazing how many MATLAB tricks I still don't know!
  댓글 수: 4
Matt Fig
Matt Fig 2011년 5월 21일
In this case: (2*sin(x)+cos(x)).^2
The .^ just means raise every element of the array in parenthesis to the power 2.
In this case: (2*sin(x)+cos(x))^2
This means to multiply the array in parenthesis by itself, so the array in parenthesis must be a square array according to the rules of matrix algebra.
You are still confusing vectorizing with expanding. They just are NOT the same thing. Look:
A = magic(2);
B = A^2
C = A*A % Notice that isequal(B,C)==1
D = A.^2
But now look:
A = [3 ,5]; % A vector!!
D = A.^2
B = A^2 % An error, because a 1-by-2 cannot multiply a 1-by-2!
C = A*A % Same error as above.
Therefore if you have an array you wish to multiply or divide by itself or another array and you use: *, or /, or ^, the arrays must be the correct size to satisfy the requirements of matrix algebra. If, on the other hand, you use: .*, ./, or .^, then there is no such size requirement other than that all arrays must be the same size or scalar.
Matt Fig
Matt Fig 2011년 5월 21일
@Oleg, I am afraid you have been infected by the confusion!
x = 0:.1:1;
(2*sin(x)+cos(x)).^2 % Your first equation
4*sin(x).^2 + cos(x).^2 % Your distribution of square is illegal!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by