How to Convert the negative Zero into Positive Zero in my code?
古いコメントを表示
% Find the A B and D matrix of the given elastic constant and the given
% sequence
clc,clear all
% Input the data
E1=input(' The elastic modulus in the fiber direction in GPa : ');
E2=input(' The elastic modulus in the transverse direction in GPa : ');
G12=input(' The rigidity of the material in GPa : ');
nu12=input(' The poisson ratio of the materal : ');
n=input(' The number of the orientation have : ');
% Calculating the transformation coeffficient
nu21=(E2/E1)*nu12;
x=1-(nu12*nu21);
Q11=E1/x;
Q22=E2/x;
Q12=(nu12*E2)/x;
Q66=G12;
% Representing the transformed coefficient in the matrix form
Q=[Q11,Q12,0;Q12,Q22,0;0,0,Q66];
% Calculating the transformed reduce matrix for different orientation
for i=1:n
theta=input(' Enter the angle in degrees : ');
% forming the transformation matrix
m=cos(theta*0.0174533);
n=sin(theta*0.0174533);
T1=[m^2,n^2,2*m*n;n^2,m^2,-2*m*n;-m*n,m*n,m^2-n^2];
T=inv(T1)
T2=[m^2,n^2,m*n;n^2,m^2,-m*n;-2*m*n,2*m*n,m^2-n^2];
% Calculating the tranformed reduces matrix
disp(' The reduced transformation matrix for this orientation : ')
Qbar=T*Q*T2;
disp(Qbar)
end
3 件のコメント
Adam Danz
2021 年 5 月 7 日
Welcome to the forum @MD SAJJAD ALAM
I formatted your code but in the future, when supplying code please format it using the code/text toggle.
What "negative zero" and "positive zero" ? We have your code but we don't know your inputs and we don't know where to look for these signed zeros.
MD SAJJAD ALAM
2021 年 5 月 7 日
MD SAJJAD ALAM
2021 年 5 月 7 日
採用された回答
その他の回答 (1 件)
Adam Danz
2021 年 5 月 7 日
Any time you see a negative 0 you can bet that the number contains a very small decimal value that is negative.
For example, set your display format to "long" and you'll see more decimal places.
This is your T matrix with short and long display formats.
format short
T =
0.0000 1.0000 0.0000
1.0000 0.0000 -0.0000
-0.0000 0.0000 -1.0000
format long
T =
0.000000000000453 0.999999999999547 0.000001346410207
0.999999999999547 0.000000000000453 -0.000001346410207
-0.000000673205104 0.000000673205104 -0.999999999999094
If you want to round to +/-1 and 0,
format long
round(T)
ans =
0 1 0
1 0 0
0 0 -1
2 件のコメント
MD SAJJAD ALAM
2021 年 5 月 8 日
Good point. But I don't understand what your motivation is. Are you expecting to only receive 1, -1 and 0? Did you understand the difference between the display formats that I shared with you?
To be clear, in that matrix of 1s -1s 0s and -0, there's not a single number that is equal to any of those values. That's just what you are seeing in the simplified display of the variable.
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

