Mathematica Asked by Dinesh Shankar on May 18, 2021
The square of a sum reads
$$left(sum_ia_iright)^2=sum_ia^2_i+2sum_{i<j}a_ia_j$$.
In Mathematica code for i=1 to 5 we get:
T = Expand[(Sum[a[i], {i, 5}])^2]
a[1]^2 + 2 a[1] a[2] + a[2]^2 + 2 a[1] a[3] + 2 a[2] a[3] + a[3]^2 + 2 a[1] a[4] + 2 a[2] a[4] + 2 a[3] a[4] + a[4]^2 + 2 a[1] a[5] + 2 a[2] a[5] + 2 a[3] a[5] + 2 a[4] a[5] + a[5]^2
P = Expand[Sum[a[i]^2, {i, 5}] + 2 Sum[a[i]*a[j], {i, 4}, {j, 5}]]
3 a[1]^2 + 4 a[1] a[2] + 3 a[2]^2 + 4 a[1] a[3] + 4 a[2] a[3] +
3 a[3]^2 + 4 a[1] a[4] + 4 a[2] a[4] + 4 a[3] a[4] + 3 a[4]^2 +
2 a[1] a[5] + 2 a[2] a[5] + 2 a[3] a[5] + 2 a[4] a[5] + a[5]^2
$T-P$ should be zero, but:
T - P
2 a[1]^2 - 2 a[1] a[2] - 2 a[2]^2 - 2 a[1] a[3] - 2 a[2] a[3] -
2 a[3]^2 - 2 a[1] a[4] - 2 a[2] a[4] - 2 a[3] a[4] - 2 a[4]^2
What is the proble here?
use
P = Expand[Sum[a[i]^2, {i, 1, 5}] + 2 Sum[a[i]*a[j], {j, 5}, {i, j - 1}]]
Correct answer by Andreas on May 18, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP