I am trying to implement loop on integral "Ufluid equation".but i am not able to successful make a proper loop. this big problem how to use limits as the range is differ in every step.

Any body help me in making loop for these calculation.

``U=3.888889H=0.25r = linspace(-0.125, -0.0416);Ufluid1= 1.5*U*(1.0 - (2.0*r/H).^2);A1=sum(Ufluid1,2)/((-0.125)-(-0.0416))r = linspace(-0.0416, 0.0416 );Ufluid2= 1.5*U*(1.0 - (2.0*r/H).^2);A2 =sum(Ufluid2,2)/((-0.0416)-(0.0416))r = linspace(0.0416, 0125 );Ufluid3= 1.5*U*(1.0 - (2.0*r/H).^2);A3=sum(Ufluid3,2)/((0.0416)-(0125))``

You can use a cell if you want it as a loop. However, the equation does not look like an integral, you must take the width of the integration elements into account. Also, linspace needs to be adjusted I think. But regarding the loop, try:

``````U=3.888889
H=0.25
A = 0;

r{1} = linspace(-0.125, -0.0416);
r{2} = linspace(-0.0416, 0.0416);
r{3} = linspace(0.0416, 0.125);

for k = 1:length(r)
Ufluid = 1.5*U*(1.0 - (2.0*r/H).^2);
A=A + sum(Ufluid,2)/((-0.125)-(-0.0416));
end
``````

Or if you want to save the different parts separately:

``````U=3.888889
H=0.25

r{1} = linspace(-0.125, -0.0416);
r{2} = linspace(-0.0416, 0.0416);
r{3} = linspace(0.0416, 0.125);

for k = 1:length(r)
Ufluid = 1.5*U*(1.0 - (2.0*r/H).^2);
A{k}=sum(Ufluid,2)/((-0.125)-(-0.0416));
end
``````

I sort out the problem solution

``````j=1
for i = -0.125:0.083333:0.083333;
r = linspace(i, i+0.083333);
Ufluid= 1.5*U*(1.0 - (2.0*r/H).^2);
Ufluid_A(j)=sum(Ufluid,2)/0.083333;
j = j+1;
end
``````

Top