Help on double integral

I wrote a simple code for evaluating a double integral of a function of the following but it does n't work;
R = 0.0067; D = 1.1111;
f = inline('exp(-R*(y-x))*((((y+D)/(x+D)))^(R*(K+D)+1))*(1/((y+D)*y)))','x','y');
dblquad(f,0,100,100,inf)
Any with a solution? Thanks for your time

댓글 수: 1

Walter Roberson
Walter Roberson 2012년 3월 5일
You have an extra ) at the end of the integral expression.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 3월 5일

0 개 추천

The above cannot be integrated, as it involves the undefined variable K .

댓글 수: 4

Natnael Hamda
Natnael Hamda 2012년 3월 5일
sorry to mention it; K = 100;
Walter Roberson
Walter Roberson 2012년 3월 5일
R = 0.0067; D = 1.1111; K = 100;
f = inline(sprintf('exp(-%.16g*(y-x))*((((y+%.16g)/(x+%.16g)))^(%.16g*(%.16g+%.16g)+1))*(1/((y+%.16g)*y))', R, D, D, R, K, D, D),'x','y');
Yes, the implication *is* that inline() never reads values of variables from the workspace: any variable whose value you do not pass as a parameter will cause an error.
I would suggest to you that using anonymous functions would be considerably cleaner than using inline(), if your MATLAB version supports anonymous functions.
R = 0.0067; D = 1.1111; K = 100;
dblquad( @(x,y) exp(-R*(y-x))*((((y+D)/(x+D)))^(R*(K+D)+1))*(1/((y+D)*y)), 0, 100, 100, inf)
Natnael Hamda
Natnael Hamda 2012년 3월 6일
Thanks a lot; The anonymous functions creates the function in better way. But still there is an error when i try to evaluate the double integral. I included the error message:
??? Error using ==> mldivide
Matrix dimensions must agree.
Error in ==> @(x,y)exp(-R*(y-x))*((((y+D)/(x+D)))^(R*(K+D)+1))*(1/((y+D)*y))
Error in ==> quad at 77
y = f(x, varargin{:});
Error in ==> dblquad>innerintegral at 78
Q(i) = quadf(intfcn, xmin, xmax, tol, trace, y(i), varargin{:});
Error in ==> quad at 77
y = f(x, varargin{:});
Error in ==> dblquad at 54
Q = quadf(@innerintegral, ymin, ymax, tol, trace, intfcn, ...
Mike Hosea
Mike Hosea 2012년 3월 8일
Your integral function must be able to accept arrays and return arrays. Don't use *, as this is matrix multiply. Instead use .*, elementwise multiplication. Similarly, don't use ^, rather .^. Don't use /, rather ./ . Basically, your integrand isn't working because it is being passed arrays, and it's trying to do matrix multiplications, matrix powers, and linear system solves when what you really just want is simple arithmetic, elementy-by-element.

이 질문은 마감되었습니다.

질문:

2012년 3월 5일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by