Use of 3D array. Find inverse of individual page
조회 수: 2 (최근 30일)
이전 댓글 표시
My program contains a 3x3x100 matrix. I need to find A=J\B where J is each page of the 3x3x100 matrix ( i.e. 100 numbers of 3x3 matrix) and B is a 3x1 matrix. Which would result in matrix A to be of dimension 3x100
How do i solve this. One of the ways might be to generate a loop 100 times. But i was looking for more efficient way. May by using the matrix directly. Please help.
I have attached the codes incase it helps.
function[J]=Jacobian(t1,t2,t3)
global l1 l2 l3;
%t1 t2 and t3 would be 1x100 matrices each.
J{1,1}=-(l1+l2.*cos(t2)+l3.*cos(t2+t3)).*sin(t1);
J{1,2}=-(l2.*sin(t2)+l3.*sin(t2+t3)).*cos(t1);
J{1,3}=-l3.*sin(t2+t3).*cos(t1);
J{2,1}=(l1+l2.*cos(t2)+l3.*cos(t2+t3)).*cos(t1);
J{2,2}=-(l2.*sin(t2)+l3.*sin(t2+t3)).*sin(t1);
J{2,3}=-l3.*sin(t2+t3).*sin(t1);
J{3,1}=0;
J{3,2}=l2.*cos(t2)+l3.*cos(t2+t3);
J{3,3}=l3.*cos(t2+t3);
function[]=Support(A,B)
%.....
J=Jacobian(M1(1,:),M1(2,:),M1(3,:))
vx=(B(1)-A(1))/2.5
vy=0;
vz=0;
V=[vx;vy;vz];
Td=J\V
This is the error i get
??? Undefined function or method 'mldivide' for input arguments of type 'cell'.
Error in ==> Support at 11 Td=J\V
댓글 수: 0
채택된 답변
Andrei Bobrov
2011년 6월 8일
function J =Jacobian1(t)
global l1 l2 l3;
j1 = [-(l1+l2.*cos(t(2,:))+l3.*cos(t(2,:)+t(3,:))).*sin(t(1,:));
-(l2.*sin(t(2,:))+l3.*sin(t(2,:)+t(3,:))).*cos(t(1,:));
-l3.*sin(t(2,:)+t(3,:)).*cos(t(1,:));
(l1+l2.*cos(t(2,:))+l3.*cos(t(2,:)+t(3,:))).*cos(t(1,:));
-(l2.*sin(t(2,:))+l3.*sin(t(2,:)+t(3,:))).*sin(t(1,:));
-l3.*sin(t(2,:)+t(3,:)).*sin(t(1,:));
zeros(1,size(t,2));
l2.*cos(t(2,:))+l3.*cos(t(2,:)+t(3,:));
l3.*cos(t(2,:)+t(3,:))];
J = permute(reshape(j1,3,3,[]),[2 1 3]);
end
J=Jacobian1(M1);
vx=(B(1)-A(1))/2.5;
vy=0;
vz=0;
V=[vx;vy;vz];
Td=cell2mat(arrayfun(@(jj)J(:,:,jj)\V,1:size(J,3),'un',0));
댓글 수: 2
추가 답변 (1개)
James Tursa
2011년 6월 9일
See this small size linear solver by Bruno Luong:
and you might be interested in this one as well:
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!