Implement following matrix using for loop

조회 수: 1 (최근 30일)
Tipu Sultan
Tipu Sultan 2019년 5월 15일
편집: Bob Thompson 2019년 5월 15일
I want implement the following matrix and expression:
%Big_lambda
where theta,r,t are 1*3 matrix and a,b,p,q are 1*1 matrix.
My approach:
theta = [ 45 46 48] ;
t= [ 1 2 3 ];
r= [200 210 220];
for i=1:3
dif_x = [(-cos(theta(i))) (r(i).*sin(theta(i))) (2*a.*t(i)+b);...
(-sin(theta(i))) (-r(i).*cos(theta(i))) (2*p.*t(i)+q)]
W = dif_x(i)*Big_lambda(i)*dif_x(i)'
end
Is the approach correct or if it is wrong what should be done!
Thanks in advance.
  댓글 수: 7
Tipu Sultan
Tipu Sultan 2019년 5월 15일
편집: Tipu Sultan 2019년 5월 15일
I want to implement the following expression:
the expression contains partial derivative and big lambda which are basically the following expression:
where big lamda in the above can be taken as a identity matrix of 3*3.
W having index means it it will be inside a loop,I have implemented as follows:
theta = [ 45 46 48] ;
t= [ 1 2 3 ];
r= [200 210 220];
x = [ r; theta ; t];
Big_lambda = eye(2);
dif_x = zeros(2, 3, 3); % Pre-allocation
for i=1:3
dif_x(:, :, i) = [-cos(theta(i)), r(i).*sin(theta(i)), 2*a.*t(i)+b;...
-sin(theta(i)), -r(i).*cos(theta(i)), 2*p.*t(i)+q];
W = dif_x(:,:,i)*Big_lambda(i)*dif_x(:,:,i)'
end
I want to know I am going in the correct direction or I need to change some thing.
Bob Thompson
Bob Thompson 2019년 5월 15일
편집: Bob Thompson 2019년 5월 15일
As far as I can tell you are going in the correct direction. I am not a SME on your specific problem, but for the code aspect it seems to be functional.
I noticed you adjusted your indexing on dif_x. Don't forget to index W as well if you want to retain the results from each loop, instead of just the final loop.
W(i) = dif_x(:,:,i)*Big_lambda(i)*dif_x(:,:,i)'

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by