Effacer les filtres
Effacer les filtres

Extracting elements from matrix to do summation

2 vues (au cours des 30 derniers jours)
lo le 13 Mar 2014
Now I have 3 matrixes
Oi is a 3x1 matrix
Dj is a 1x3 matrix
cij is a 3x3 matrix
And then I have 2 equations to solve:
Ai and Bj are unknowns and Ai should be a 3x1 matrix and Bj should be a 1x3 matrix
and it is actually only a 6 equations 6 unknown question.
But I found difficulties typing the equations in matlab.
Because I can't simply type something like
syms= i j
Because things like A(i) is not gonna work
So how should I type the equations correctly?
I can't do it manually as I have equation like
where n equal to like 25

Réponses (2)

Image Analyst
Image Analyst le 13 Mar 2014
What about
j = 1 : 25; % Define indexes over which to sum
% Now do the multiplication. i is some number that's predefined.
A25 = B(j) .* D(j) .* c(i,j); % Array of 25 terms.
% Now sum all the terms.
A(i) = sum(A25);

Roger Stafford
Roger Stafford le 13 Mar 2014
Matlab can indeed save you some writing. Let these arrays already be defined:
c = [c11,c12,...,c1n;
O = [O1;O2;...;On] (Column vector)
D = [D1,D2,...,Dn] (Row vector)
Now do the following in matlab:
M = [eye(n),-bsxfun(@times,c,D);
[U,S,V] = svd(M);
Because your equations are homogeneous, you will either have as the only solution that all A's and B's are zero, or there will be infinitely many solutions. You can determine the nature of these solutions from the singular values in the diagonal of array S. If all singular values there are non-zero, then the only solution is for all A's and B's to be zero. If all but the rightmost singular value are non-zero and that is zero, then all multiples of V(:,2*n) are solutions with A's first and then the B's next. That is, A = t*V(1:n,2*n), B =t*V(n+1:2*n).' for any scalar t. If the rightmost two singular values are zero, then any linear combination of V(:,n) and V(:,n-1) are also solutions. If the rightmost k of the singular values are zero, then any linear combination of V(:,n), V(:,n-1),...,V(:,n-k+1) is a solution. That is the nature of homogeneous linear equations.


Community Treasure Hunt

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

Start Hunting!

Translated by