problem in matlab for sin and cos
Mostrar comentarios más antiguos
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 comentarios
Steven Lord
el 9 de Dic. de 2020
What is the size of t and d when you try to execute that command?
Sanjeev Sharma
el 9 de Dic. de 2020
John D'Errico
el 9 de Dic. de 2020
Editada: John D'Errico
el 9 de Dic. de 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
el 9 de Dic. de 2020
Respuestas (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)
result2a = pagemtimes(Mqwp, b);
result2 = result2a(:, :, 3)
Matt J
el 9 de Dic. de 2020
0 votos
Nope.
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!