필터 지우기
필터 지우기

How to solve an equation from 2 different matrix..?

조회 수: 1 (최근 30일)
Noru
Noru 2013년 2월 7일
I have a problem when i want to vectorize an equation, and the elements of the equation contain 2 different matrix with 2 different size. for example :
P Q R S T
A = [ 1 3 21 5 20
2 1 15 1 25
3 5 7 3 21
4 2 6 6 28
5 4 5 7 16
6 2 8 10 18
7 3 12 9 12
8 1 7 4 23];
P P W
(i) (j)
B = [ 1 2 0.5
1 8 0.8
2 1 0.6
3 4 0.22
3 7 0.13
4 5 0.16
4 6 0.58
5 6 0.21
6 7 0.20
7 8 0.66];
and the equation is :
I've already try with this :
n = length(A(:,1));
for i = 1:n
for j = 1:i
x = sum((w*(Q(i)-R(j))*(Q(j)-R(i)))/S(i)-T(j));
end
end
but the result is "Index exceeds matrix dimensions." Does anyone have the solution...??
thanks..
  댓글 수: 1
Jan
Jan 2013년 2월 7일
편집: Jan 2013년 2월 7일
Well formatted text and code, very nice formula, shown what has been tried already - this is simply a good question. +1
Does the value of B matter anywhere in the equation?

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

채택된 답변

Jan
Jan 2013년 2월 7일
The code for the posted equation:
x = 0;
n = size(A, 1);
for i = 1:n
for j = 1:n
x = x + sum((w*(Q(i)-R(j))*(Q(j)-R(i)))/S(i)-T(j));
end
end
But this does not change anything for the "Index exceeds matrix dimensions" problem. Please post the complete error message and finc out which of the array fails:
dbstop if error
% Then run the program until the error occurres
disp(i)
disp(j)
disp(size(Q))
disp(size(R))
disp(size(S))
disp(size(T))
  댓글 수: 1
Noru
Noru 2013년 2월 8일
I already fix my vector.
I think i found where is my mistake, I didn't use
x = 0;
n = size(A, 1);
and in the equation i didn't use "x +..." before sum((...
if i may ask, why i have to add "x +..." before sum((... ?? that thing is really new for me..
thank you for your solution..

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by