Problem with while loop

1 回表示 (過去 30 日間)
Kevin Hanekom
Kevin Hanekom 2021 年 4 月 13 日
コメント済み: Kevin Hanekom 2021 年 4 月 13 日
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 Center および File ExchangeLoops 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