How can I put an integral inside a for loop when the bounds depend on the loop's variable?

조회 수: 1 (최근 30일)
Hi, I would like to do this integration where the j of cj is the loop variable.
I tried this but when I calculate Phi_ij1(1,1) for example, Matlab says "unrecognized function or variable 'y' ". Can you help me?
for j=1:13
x_max1 = @(y,j) (-sqrt(3)/3).*y + c(j);
y_min1 = @(j) (sqrt(3)/2)*c(j);
y_max1 = @(j) c(j)*sqrt(3);
Phi_ij1 = @(i,j) integral2(B_zi(i,x,y), 0, x_max1(y,j),0,y_max1(j)) - integral2(B_zi(i,x,y),0, x_max1(y,j),y_min1(j),y_max1(j)) ;
end
  댓글 수: 5
darova
darova 2020년 4월 1일
Try to specify variables integral depends on
Phi_ij1 = @(i,j) integral2(@(x,y)B_zi(i,x,y), 0, @(y)x_max1(y,j),0,y_max1(j)) - ...
integral2(@(x,y)B_zi(i,x,y), 0, @(y)x_max1(y,j),y_min1(j),y_max1(j)) ;
sawdiia_too
sawdiia_too 2020년 4월 1일
I tried it and it says XMAX must be a floationg point scalar.

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

채택된 답변

darova
darova 2020년 4월 1일
Here is an example for integral3
According to this integration is done from z to x
You have only y. Looks like x=x(y) in your case
So you have to integrate by x first
Try to replace limits of integration
Phi_ij1 = @(i,j) integral2(@(x,y)B_zi(i,x,y), 0, y_max1(j)), 0, @(y)x_max1(y,j) - ...
integral2(@(x,y)B_zi(i,x,y), y_min1(j),y_max1(j), 0, @(y)x_max1(y,j)) ;
  댓글 수: 2
sawdiia_too
sawdiia_too 2020년 4월 2일
In the example, the integration of x is from a scalar to a scalar while on mine the integrations are from functions to functions (one depending on y like you said x(y) and the other depending on j y(j))

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

추가 답변 (1개)

Torsten
Torsten 2020년 4월 2일
Phi_ij1 =@(i,j) integral2(@(y,x) B_zi(i,x,y),0,y_min1(j),0,@(y)x_max1(y,j));
  댓글 수: 7
Torsten
Torsten 2020년 4월 2일
integral 0 -> ymax1 - integral ymin1 -> ymax1 = integral 0 -> ymin1 (outer integral)

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by