Use of 3D array. Find inverse of individual page

2 views (last 30 days)
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

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 8 Jun 2011
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 Comments
Andrei Bobrov
Andrei Bobrov on 8 Jun 2011
small corrected in row: J = permute ...
Saurav Agarwal
Saurav Agarwal on 9 Jun 2011
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

Sign in to comment.

More Answers (1)

James Tursa
James Tursa on 9 Jun 2011

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!