New Reply

Double Sum Using Matlab

 
Share Thread Thread Tools
Feb21-12, 10:15 PM   #1
 

Double Sum Using Matlab


Hi,
I have this double summation expression to solve as part of matlab code I am writing. I have searched matlab no syntax that can do it. Please assist.

Q=ƩƩxixjaij i.e double sum of xi xj aij, i=1:n, j=1:n

Please assist me

Thanks
adeeyo
PhysOrg.com
PhysOrg
mathematics news on PhysOrg.com

>> Mathematicians analyze social divisions using cell phone data
>> Can math models of gaming strategies be used to detect terrorism networks?
>> Mathematician proves there are infinitely many pairs of prime numbers less than 70 million units apart
Feb22-12, 03:44 PM   #2
 
Recognitions:
Science Advisor Science Advisor
What do mean by solve? What you have written is simply an expression. To solve something you need to describe what is known and what you are trying to find.
Feb22-12, 05:12 PM   #3
 
Thanks Mathman,

What I mean is this. I wrote a matlab code for that expression and manual as seen below but got different answer. I don't know what is wrong either with matlab code or manual expression or both.

Q=∑∑xixjaij the first sigma has i=1:n, the second sigma j=1:n

for i=1:n
for j=1:n
Q=sum(sum(x(i).*x(j).*(a(i, j))));
end
end



Mannual

Q=x(1)*x(1)*(a(1)*a(1))+x(1)*x(2)*(a(1)*a(2))+x(1)*x(3)*a(1)*a(3)+x(2)* x(1)*a(2)*a(1))+x(2)*x(2)*a(2)*a(2))+x(2)*x(3)*a(2)*a(3)*+x(3)*x(1)*a(3 )*a(1))+x(3)*
x(2)*a(3)*a(2))+x(3)*x(3)*a(3)*a(3));

Thanks
Feb23-12, 03:45 PM   #4
 
Recognitions:
Science Advisor Science Advisor

Double Sum Using Matlab


From what I recall about coding: You need to set Q = 0.0 before starting. Then the operating instruction should be Q=Q+x(i)*x(j)*a(i, j). To save a little time you could multiply by x(i) outside the j loop.
Feb24-12, 04:57 PM   #5
 
if a is nxn and x is nx1 try Q = sum(sum(a.*repmat(x,[1 n]).*repmat(x',[n 1])))
Feb24-12, 05:03 PM   #6
 
Blog Entries: 1
Recognitions:
Homework Helper Homework Help
Q=sum(sum(x(i).*x(j).*(a(i, j))));
This line is what is wrong with your code. Let's consider what happens on each loop:
i=1, j=1:
sum(sum(x(1)*x(1)*a(1,1))) = x(1)*x(1)*a(1,1) so Q=x(1)*x(1)*a(1,1)

i=1,j=2:
sum(sum(x(1)*x(2)*a(1,2))) = x(1)*x(2)*a(1,2) so Q=x(1)*x(2)*a(1,2) NOT x(1)*x(1)*a(1,1)+x(1)*x(2)*a(1,2)

If you replace the line with
Q=Q+x(i)*x(j)*a(i,j)
you should get the right answer
New Reply
Thread Tools


Similar Threads for: Double Sum Using Matlab
Thread Forum Replies
Matlab Plotting of QM double-potential-barrier Math & Science Software 2
MATLAB: expressing a double index equation as a matrix Engineering, Comp Sci, & Technology Homework 6
calculating e, using matlab (how to get answer in double type) Engineering, Comp Sci, & Technology Homework 1
double integrals with matlab General Math 3
Matlab- input arguments of type 'double' ???? Math & Science Software 2