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
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.
Kevin Hanekom
Kevin Hanekom 2021-4-13
Im new to programing so alot of this is blury to me but the goal is to use different values of sig1, sig2, and sig3, up to a point where g is <=1, and then plot those points forming a ellipsoid

请先登录,再进行评论。

采纳的回答

Chunru
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
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;
Kevin Hanekom
Kevin Hanekom 2021-4-13
Great thank you for helping me! You guys are what make this community so great.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by