2 views (last 30 days)

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

darova
on 1 Apr 2020

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)) ;

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

Start Hunting!
## 5 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/514539-how-can-i-put-an-integral-inside-a-for-loop-when-the-bounds-depend-on-the-loop-s-variable#comment_819226

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/514539-how-can-i-put-an-integral-inside-a-for-loop-when-the-bounds-depend-on-the-loop-s-variable#comment_819226

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/514539-how-can-i-put-an-integral-inside-a-for-loop-when-the-bounds-depend-on-the-loop-s-variable#comment_819246

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/514539-how-can-i-put-an-integral-inside-a-for-loop-when-the-bounds-depend-on-the-loop-s-variable#comment_819246

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/514539-how-can-i-put-an-integral-inside-a-for-loop-when-the-bounds-depend-on-the-loop-s-variable#comment_819252

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/514539-how-can-i-put-an-integral-inside-a-for-loop-when-the-bounds-depend-on-the-loop-s-variable#comment_819252

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/514539-how-can-i-put-an-integral-inside-a-for-loop-when-the-bounds-depend-on-the-loop-s-variable#comment_819288

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/514539-how-can-i-put-an-integral-inside-a-for-loop-when-the-bounds-depend-on-the-loop-s-variable#comment_819288

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/514539-how-can-i-put-an-integral-inside-a-for-loop-when-the-bounds-depend-on-the-loop-s-variable#comment_819303

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/514539-how-can-i-put-an-integral-inside-a-for-loop-when-the-bounds-depend-on-the-loop-s-variable#comment_819303

Sign in to comment.