Problem with while loop
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
The goal of my code is to plot the function for a Tsai-Wu surface which is supposed to be a ellipsoide, the problem arrises with my while loop which does not seem to be doing anything. I've simplified the equation, but as you can see the value for my variable G can never excede 1. Any help or a pointer in the right direction would be really appreciated, thanks!
sig1c = -1.5; %always set compression as negative
sig1t = 1; %always set tension as positve
sig2c = -1.5;
sig2t = 1;
sig3c = -2;
sig3t = 0.5;
F1 = ((1/sig1t)-(1/sig1c));
F2 = ((1/sig2t)-(1/sig2c));
F3 = ((1/sig3t)-(1/sig3c));
F11 = (1/(sig1c*sig1t));
F22 = (1/(sig2c*sig2t));
F33 = (1/(sig3c*sig3t));
syms sig1 sig2 sig3 G
% sig1 = 0;
% sig2 = 0;
% sig3 = 0;
%[sig1,sig2,sig3] = meshgrid(linspace(-5,5,25));
%G = F1.*sig1 + F11.*sig1.^2 + F2*sig2 + F22.*sig2.^2 + F3.*sig3 + F33.*sig3.^2 - 1;
[sig1,sig2,sig3] = meshgrid(linspace(-5,5,25));
while G < 1
G = F1.*sig1 + F11.*sig1.^2 + F2*sig2 + F22.*sig2.^2 + F3.*sig3 + F33.*sig3.^2 - 1;
end
fv = isosurface(sig1,sig2,sig3,G,0);
fv = isosurface(G,0);
fvc = isosurface(G,'red');
p = patch(isosurface(sig1,sig2,sig3,G,0));
%isonormals(sig1,sig2,sig3,G,p)
%isonormals(sig1,sig2,sig3,G,p)
view(3);
댓글 수: 2
DGM
2021년 4월 13일
What is the intent of the loop? The value of G isn't different on subsequent passes. It will either loop once or it will loop infinitely.
채택된 답변
Chunru
2021년 4월 13일
Change
while G < 1
G = F1.*sig1 + F11.*sig1.^2 + F2*sig2 + F22.*sig2.^2 + F3.*sig3 + F33.*sig3.^2 - 1;
end
to:
G = F1.*sig1 + F11.*sig1.^2 + F2*sig2 + F22.*sig2.^2 + F3.*sig3 + F33.*sig3.^2 - 1;
댓글 수: 3
Chunru
2021년 4월 13일
Since you are ploting isosurface of G==0, it does not matter if some values of G is greater than 1 or not. Howver if you do really want to clip the G to be some value (say 1), then you can add this:
G(G>1) = 1;
추가 답변 (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!