필터 지우기
필터 지우기

Generate code for randomly oriented short fiber RVE?

조회 수: 10 (최근 30일)
RAJESH
RAJESH 2023년 1월 11일
댓글: RAJESH 2023년 1월 12일
Kindly look into the below code, i am not able to run it, if there is any issue.
function Fiber=Generate_Fiber(x,y,z,L,N)
%input
%x=[x1 x2]: x boundaries of the box
%y=[y1 y2]: y boundaries of the box
%z=[z1 z2]: z boundaries of the box
%L: Length of fibers
%N: Number of fibers
%output
%Fiber: (N,6) matrix of fiber coordinates with (:,1), (:,2) and (:,3) are x,y, and z coordinates of one end
%and (:,4),(:,5) and (:,6) are x,y, and z coordinates of the other end.
for i=1:1:N
while 1
x1=min(x)+(max(x)-min(x))*rand(1);
y1=min(y)+(max(y)-min(y))*rand(1);
z1=min(z)+(max(z)-min(z))*rand(1);
theta=2*pi*rand(1);
v=2*rand(1)-1;
x2=x1+L*sqrt(1-v^2)*cos(theta);
y2=y1+L*sqrt(1-v^2)*sin(theta);
z2=z1+L*v;
if x2<=x(2) && x2>=x(1) && y2<=y(2) && y2>=y(1) && z2<=z(2) && z2>=z(1)
break;
end
end
Fiber(i,1)=x1;
Fiber(i,2)=y1;
Fiber(i,3)=z1;
Fiber(i,4)=x2;
Fiber(i,5)=y2;
Fiber(i,6)=z2;
end

채택된 답변

Constantino Carlos Reyes-Aldasoro
You are not running your loops correctly. If you ident your code (control-i) you can see better:
for i=1:1:N
while 1
x1=min(x)+(max(x)-min(x))*rand(1);
y1=min(y)+(max(y)-min(y))*rand(1);
z1=min(z)+(max(z)-min(z))*rand(1);
theta=2*pi*rand(1);
v=2*rand(1)-1;
x2=x1+L*sqrt(1-v^2)*cos(theta);
y2=y1+L*sqrt(1-v^2)*sin(theta);
z2=z1+L*v;
if x2<=x(2) && x2>=x(1) && y2<=y(2) && y2>=y(1) && z2<=z(2) && z2>=z(1)
break;
end
end
Fiber(i,1)=x1;
Fiber(i,2)=y1;
Fiber(i,3)=z1;
Fiber(i,4)=x2;
Fiber(i,5)=y2;
Fiber(i,6)=z2;
end
You have a for loop, pressumably to run N times (no need to do 1:1:N, with 1:N will work), then "while 1" does not have a condition to check, it will always enter (https://uk.mathworks.com/help/matlab/ref/while.html) and then an if in which you do not do anything. Finally, I do not think that you need a loop here, you are only adding random numbers to x1,y1,z1, most probably you could do what you want without the for loop.
  댓글 수: 2
RAJESH
RAJESH 2023년 1월 12일
In commnad window it is showing that:
function Fiber=Generate_Fiber(x,y,z,L,N)
Error: Function definition not supported in this context. Create functions in code file.
RAJESH
RAJESH 2023년 1월 12일
Can you help to generate the code for randon short fiber postioning for beam elements
I am sending the LT Harper's paper for information:

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by