Function for Compliance Matrix

I want to know what I am doing wrong with these codes
function y = Sbar(S,theta)
%Sbar This function returns the transformed reduced
% compliance matrix "Sbar" given the reduced
% compliance matrix S and the orientation
% angle "theta".
% There are two arguments representing S and "theta"
% The size of the matrix is 3 x 3.
% The angle "theta" must be given in degrees.
m = cosd(theta);
n = sind(theta);
T = [m*m, n*n, 2*m*n; n*n, m*m, -2*m*n; -m*n, m*n, m*m-n*n];
Tinv = [m*m, n*n, -2*m*n; n*n, m*m, 2*m*n; m*n, -m*n, m*m-n*n];
y = Tinv*S*T;
S = ReducedCompliance(155, 12.10, 0.248, 4.40)
theta = -90:10:90
for i = 1:length(theta)
S(:,:,i) = Sbar(S, theta(i))
end
%The output is
S =
0.0826 -0.0016 0
-0.0016 0.0065 0
0 0 0.2273
S(:,:,1) =
0.0826 -0.0016 0
-0.0016 0.0065 0
0 0 0.2273
S(:,:,2) =
0.0193 -0.0122 -0.0712
-0.0122 0.0909 0.0452
-0.0356 0.0226 0.2061
Error using *
Inputs must be 2-D, or at least one input must be scalar.
To compute elementwise TIMES, use TIMES (.*) instead.
Error in Sbar (line 13)
y = Tinv*S*T;

Réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 4 Sep 2019
Modifié(e) : KALYAN ACHARJYA le 4 Sep 2019

1 vote

May be, one way?
y=Tinv*T.*S;
Example:
>> Tinv
Tinv =
0.1361 0.5499 0.6221
0.8693 0.1450 0.3510
0.5797 0.8530 0.5132
>> T
T =
0.2417 0.1320 0.5752
0.4039 0.9421 0.0598
0.0965 0.9561 0.2348
>> whos S
Name Size Bytes Class Attributes
S 3x3x2 144 double
>> S(:,:,1)
ans =
0.4018 0.1233 0.4173
0.0760 0.1839 0.0497
0.2399 0.2400 0.9027
>> S(:,:,2)
ans =
0.9448 0.3377 0.1112
0.4909 0.9001 0.7803
0.4893 0.3692 0.3897
>> y
y(:,:,1) =
0.1266 0.1394 0.1073
0.0230 0.1079 0.0294
0.1282 0.3289 0.4558
y(:,:,2) =
0.2976 0.3819 0.0286
0.1485 0.5282 0.4612
0.2613 0.5062 0.1968
>>

13 commentaires

Jide Williams
Jide Williams le 4 Sep 2019
Modifié(e) : Jide Williams le 4 Sep 2019
Thanks Kalyan I will verify once I get on MATLAB but it looks great to me! Thanks....I did verify but it wasnt working for me, I thank you anyways. Also remember that the whole thing is wraped in a funtion which makes it difficult to write it the way you did.
I just want the function to iterate along the theta array, giving S matrices as outcomes
Jide Williams
Jide Williams le 4 Sep 2019
I checked but it appears its still not working for me.
KALYAN ACHARJYA
KALYAN ACHARJYA le 4 Sep 2019
Modifié(e) : KALYAN ACHARJYA le 4 Sep 2019
Can you share following three things? Run the code and type the following one by one in command window as follows, and requested you to share the details
>>whos Tinv
>>whos Tinv
>>whos S
Jide Williams
Jide Williams le 4 Sep 2019
Ok lemme do that now
KALYAN ACHARJYA
KALYAN ACHARJYA le 4 Sep 2019
Because I considered the same sizes random data, its works in my case. I showed the example also
Jide Williams
Jide Williams le 4 Sep 2019
so it returns 3*3*2, thats not what I want, I want it to return 3*3*19, i.e length of Z = -90:10:90.
Thanks
Jide Williams
Jide Williams le 4 Sep 2019
Modifié(e) : Jide Williams le 4 Sep 2019
Thanks, but lemme see the code....it is still not working. When you run the function
S1 = Sbar(S, -90), %You will get a 3*3 matrix
%Now I want to run from:
theta = -90:10:90 %degree
S1-S19 = Sbar(S, theta[-90:10:90]); %S is constant
%I should get 19 3*3 matrices
KALYAN ACHARJYA
KALYAN ACHARJYA le 4 Sep 2019
Modifié(e) : KALYAN ACHARJYA le 4 Sep 2019
Have you mentioned this "I want it to return 3*3*19" in the original question?
I sepcifically asked for share the followings
>>whos Tinv
>>whos Tinv
>>whos S
Run the code and Type whos Tinv on commnad window, then enter, show the details here
.....do the same for others
In your case
Tinv is 3x3
T is 3x3
S is 3x3x2
Can you show, how you can get 3*3*19 after doing multiplication from those matrices?
I am asking basic Maths, not Matlab?
Jide Williams
Jide Williams le 4 Sep 2019
Ok hang on I think I am seeing where the mistake is....gimme a second
I HAVE SEEN MY ERROR and I have been able to solve it. Thanks anyways. see code below
function y = Sbar(S,theta)
for iter = 1:length(theta)
%Sbar This function returns the transformed reduced
% compliance matrix "Sbar" given the reduced
% compliance matrix S and the orientation
% angle "theta".
% There are two arguments representing S and "theta"
% The size of the matrix is 3 x 3.
% The angle "theta" must be given in degrees.
m = cosd(theta(iter));
n = sind(theta(iter));
T = [m.*m, n.*n, 2.*m.*n; n.*n, m.*m, -2.*m.*n; -m.*n, m.*n, m.*m-n.*n];
Tinv = [m.*m, n.*n, -2.*m.*n; n.*n, m.*m, 2.*m.*n; m.*n, -m.*n, m.*m-n.*n];
%y = Tinv*S*T;
y(:,:,iter) = Tinv*S*T;
end
KALYAN ACHARJYA
KALYAN ACHARJYA le 4 Sep 2019
Happy to know that the problem has been resolved
Good Wishes!
Jide Williams
Jide Williams le 4 Sep 2019
Thanks alot I appreciate your guidiance sir!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Special Functions dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by