Problem with while loop

1 view (last 30 days)
Kevin Hanekom
Kevin Hanekom on 13 Apr 2021
Commented: Kevin Hanekom on 13 Apr 2021
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 Comments
DGM
DGM on 13 Apr 2021
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 on 13 Apr 2021
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

Sign in to comment.

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!