Mqwp= [1,0,0,0;...
0, cos(2*t).^2+(sin(2*t).^2*cos(d)), sin(2*t)*cos(2*t)*(1-cos(d)), -sin(2*t)*sin(d);...
0, sin(2*t)*cos(2*t)*(1-cos(d)), sin(t).^2+cos(2*t).^2*cos(d), cos(2*t)*sin(d);....
0, sin(2*t)*sin(d), -cos(2*t)*sin(d), cos(d);]
is there anz problem in 4*4 matrix please tell me i am bignner for this software

4 commentaires

Steven Lord
Steven Lord le 9 Déc 2020
What is the size of t and d when you try to execute that command?
Sanjeev Sharma
Sanjeev Sharma le 9 Déc 2020
O to 2 pi both t and d
John D'Errico
John D'Errico le 9 Déc 2020
Modifié(e) : John D'Errico le 9 Déc 2020
No. Steven was asking if t and d are scalar, or are they vectors or arrays? This seems to be pertinent, because you use .^ to rise things to a power. So if you know how and perhaps why you need to do that, but you don't use .* to multiply. And they would also be an issue.
Regardless, if t and/or d are vectors or arrays, then it make little sense to try to create a 4x4 array, if t and d are also more than scalars. So why do you think there is a problem in this line (beyond the extra dot in the continuation ... )? So all of this means you need to explain what you are doing with this, and what are t and d. Are they scalar variables? What error did you get when you tried to use this code?
Sanjeev Sharma
Sanjeev Sharma le 9 Déc 2020
Yes both t & d are vector and this is also vector like muller matrix if you know Error comes out- arguments not assign

Connectez-vous pour commenter.

Réponses (2)

Since t and d are vectors I would create a 3-D array instead of a wide matrix. First turn t and d into 3-D arrays.
t = reshape(1:5, 1, 1, []);
d = reshape(6:10, 1, 1, []);
Now for convenience I'll define two helper variables:
One = ones(size(t));
Zero = zeros(size(t));
Now define the array. I've changed all your multiplications except the 2*t ones from matrix operations (the * operator) to element-wise operations (the .* operator.)
Mqwp= [One, Zero, Zero, Zero;...
Zero, cos(2*t).^2+(sin(2*t).^2.*cos(d)), sin(2*t).*cos(2*t).*(1-cos(d)), -sin(2*t).*sin(d);...
Zero, sin(2*t).*cos(2*t).*(1-cos(d)), sin(t).^2+cos(2*t).^2.*cos(d), cos(2*t).*sin(d);....
Zero, sin(2*t).*sin(d), -cos(2*t).*sin(d), cos(d)];
Now you have two main options. You can use a for loop over the third dimension of Mqwp or if you're using release R2020b or later you could use pagemtimes.
b = (11:14).';
for k = 1:size(Mqwp, 3)
result1a(:, :, k) = Mqwp(:, :, k)*b;
end
result1 = result1a(:, :, 3)
result1 = 4×1
11.0000 10.8018 8.1265 -17.7037
result2a = pagemtimes(Mqwp, b);
result2 = result2a(:, :, 3)
result2 = 4×1
11.0000 10.8018 8.1265 -17.7037

Catégories

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by