For loop in matlab
조회 수: 1 (최근 30일)
이전 댓글 표시
I write a code about a fission process and i want to repeat this 10^6 times i can use for loop right? But i get an error like this: Conversion to logical from sym is not possible.
What is the problem? Can you help me?
Error in Untitled58 (line 34)
if d1<ds
n=10^6;
for i=1:n
R=0.30; %in mm
l=0.1; %in mm
d=0.05; %in mm
x1=rand;
x2=rand;
x3=rand;
x4=rand;
x5=rand;
ksi1=x1;
ksi2=x2;
ksi3=x3;
ksi4=x4;
ksi5=x5;
r=(x1)^1/3* R;
mu=2*x2-1;
fi=2*pi*x3;
ds1=-r*mu+((r^2*mu^2)+(R^2-r^2))^1/2;
ds2=-r*mu-(r^2*mu^2+R^2-r^2)^1/2;
if ds1>0
ds=ds1;
else
ds=ds2;
end
syms s;
syms d1;
s=d1; %d*=d1
if x4<0.3
d=d1;
elseif x4>0.3
d1=(-l*log(exp(x5)));
end
if d1<ds
disp('fission product is not reached to surface of sphere');
else
disp('fission product is reached to surface of sphere');
end
end
댓글 수: 0
채택된 답변
David Hill
2021년 10월 28일
Not sure what you are trying to do. You don't use several variables. Why use symbolic?
n=10^6;
R=0.30;
l=0.1;
d=0.05;
for i=1:n
x=rand(1,5);
r=x(1)^1/3*R;
mu=2*x(2)-1;
fi=2*pi*x(3);
a=(r^2*mu^2+R^2-r^2)^1/2;
ds1=-r*mu+a;
ds2=-r*mu-a;
if ds1>0
ds=ds1;
else
ds=ds2;
end
if x(4)<0.3
d1=d;
else
d1=(-l*log(exp(x(5))));
end
end
if d1<ds
disp('fission product is not reached to surface of sphere');
else
disp('fission product is reached to surface of sphere');
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!