How can I use for loop twice

1 回表示 (過去 30 日間)
omkar bichkar
omkar bichkar 2015 年 6 月 13 日
編集済み: Azzi Abdelmalek 2015 年 6 月 13 日
error: for | Error: Expression or statement is incomplete or incorrect.
syms x
Fun = (sqrt(7.447.*(200-x).*(2.0720.*x-200.*sqrt(9.01)+sqrt(9.01.*200^2- 7.9810*200.*x))))/8;
h=1;
zi = 1:360;
x=0:h:200;
Fun1 = matlabFunction(Fun);
for i=1:(length(x)-1)
for
j=1:360
end
y1 = Fun1(x(i));
z1 = Fun1(x(i));
x2 = x(i)+h;
y2 = Fun1(x(i+1));
z2 = Fun1(x(i+1));
x3 = x(i)+h;
y3 = y2*cos((pi/180)*zi(j));
z3 = z2*sin((pi/180)*zi(j));
T1 = [0, y3-y2, z3-z2];
T2 = [x(i)-x(i+1), y1-y2, z1-z2];
Vec = cross(T1,T2);
deltal = sqrt((y2-y1)^2+h^2);
deltazi = sqrt(z3^2+(y2-y3)^2);
dA11 = deltal.*deltazi;
end
please help me

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 13 日
編集済み: Azzi Abdelmalek 2015 年 6 月 13 日
Look at this part of your code
for
j=1:360
end
It's not correct, and even it's corrected
for j=1:360
end
This doesn't mean anything, maybe what you want is this:
syms x
Fun = (sqrt(7.447.*(200-x).*(2.0720.*x-200.*sqrt(9.01)+sqrt(9.01.*200^2- 7.9810*200.*x))))/8;
h=1;
zi = 1:360;
x=0:h:200;
Fun1 = matlabFunction(Fun);
for i=1:(length(x)-1)
y1 = Fun1(x(i));
z1 = Fun1(x(i));
x2 = x(i)+h;
y2 = Fun1(x(i+1));
z2 = Fun1(x(i+1));
x3 = x(i)+h;
for j=1:360
y3 = y2*cos((pi/180)*zi(j));
z3 = z2*sin((pi/180)*zi(j));
T1 = [0, y3-y2, z3-z2];
T2 = [x(i)-x(i+1), y1-y2, z1-z2];
Vec = cross(T1,T2);
deltal = sqrt((y2-y1)^2+h^2);
deltazi = sqrt(z3^2+(y2-y3)^2);
dA11 = deltal.*deltazi;
end
end

その他の回答 (1 件)

Mischa Kim
Mischa Kim 2015 年 6 月 13 日
Hi Omkar, looks like the second end is misplaced. Als, I recommend using ii instead of i (and same for j) because it is also used as the imaginary unit.
Fun1 = matlabFunction(Fun);
for i = 1:(length(x)-1) %%replace i by ii
for j = 1:360 %%replace j by jj
y1 = Fun1(x(i));
z1 = Fun1(x(i));
x2 = x(i)+h;
y2 = Fun1(x(i+1));
z2 = Fun1(x(i+1));
x3 = x(i)+h;
y3 = y2*cos((pi/180)*zi(j));
z3 = z2*sin((pi/180)*zi(j));
T1 = [0, y3-y2, z3-z2];
T2 = [x(i)-x(i+1), y1-y2, z1-z2];
Vec = cross(T1,T2);
deltal = sqrt((y2-y1)^2+h^2);
deltazi = sqrt(z3^2+(y2-y3)^2);
dA11 = deltal.*deltazi;
end
end

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by