# Issue with numerical integration of two variable function

조회 수: 3(최근 30일)
Bathala Teja 2021년 9월 20일
댓글: Bathala Teja 2021년 9월 22일
I want to do integration of two variable function w.r.t one variable.
A = @(x, y)cos(x)+sin(y)
A = function_handle with value:
@(x,y)cos(x)+sin(y)
B = @(x, y)(A-integral(@(x)A, 0 , 2*pi))
B = function_handle with value:
@(x,y)(A-integral(@(x)A,0,2*pi))
How to see the output here??

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

### 채택된 답변

Walter Roberson 2021년 9월 20일
A = @(x, y) cos(x)+sin(y)
A = function_handle with value:
@(x,y)cos(x)+sin(y)
B = @(x, y) A(x,y)-integral(@(X)A(X,y), 0 , 2*pi, 'ArrayValued', true)
B = function_handle with value:
@(x,y)A(x,y)-integral(@(X)A(X,y),0,2*pi,'ArrayValued',true)
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.1e-07. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.1e-07. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
fsurf(B, [-pi pi -pi pi])
##### 댓글 수: 4표시숨기기 이전 댓글 수: 3
Bathala Teja 2021년 9월 22일
ok got it
thank you

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

### 추가 답변(2개)

Sargondjani 2021년 9월 20일
편집: Sargondjani 2021년 9월 20일
You created only function handles. So f(x,y) = .....
To compute the numerical value you need to assign numerical values to x and y. So for example:
y=0;
x=1;
B_value = B(x,y);
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

Steven Lord 2021년 9월 20일
A = @(x, y)cos(x)+sin(y);
B = @(x, y)(A-integral(@(x)A, 0 , 2*pi));
Your expression for B won't work for two reasons. The integral function requires the function handle you pass into it as the first input to return a numeric array, but yours returns a function handle. Even if that worked, you would then try to subtract that result from a function handle and arithmetic on function handles is not supported.
From your description it sounds like you want B to be a function of one variable, but you need to pass two inputs into your A function handle. Assuming you want to fix the value of x and make B just a function of y, evaluate A inside your expression for B:
A = @(x, y)cos(x)+sin(y);
fixedX = 0.5;
B = @(y) A(fixedX, y)-integral(@(z)A(fixedX, z), 0 , 2*pi)
B = function_handle with value:
@(y)A(fixedX,y)-integral(@(z)A(fixedX,z),0,2*pi)
B(0.25)
ans = -4.3890
##### 댓글 수: 1표시숨기기 없음
Bathala Teja 2021년 9월 21일
My intension is to get B as a function of x and y not interms of value

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

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by