Problem with while loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Kevin Hanekom
el 13 de Abr. de 2021
Comentada: Kevin Hanekom
el 13 de Abr. de 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 comentarios
DGM
el 13 de Abr. de 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.
Respuesta aceptada
Chunru
el 13 de Abr. de 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 comentarios
Chunru
el 13 de Abr. de 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;
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!