Use of 3D array. Find inverse of individual page

조회 수: 2 (최근 30일)
Saurav Agarwal
Saurav Agarwal 2011년 6월 8일
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

채택된 답변

Andrei Bobrov
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
Andrei Bobrov
Andrei Bobrov 2011년 6월 8일
small corrected in row: J = permute ...
Saurav Agarwal
Saurav Agarwal 2011년 6월 9일
Sir Andrei,
Could you please explain the last line Td=cell2mat(arrayfun.....
the code is working fine but i couldnt understand the last line well although i went through my handbook. Please Help.
Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

James Tursa
James Tursa 2011년 6월 9일

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by