Skip to main content
Fixed error in code
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Not very efficient, but this brute force approach has the advantage of being very easy to code.

data = {{a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}, {a4, b4, c4}, {a5, b5, c5}};
{aa, bb, cc} = Transpose @ data;
as = Most @ Accumulate[aa];
bs = Most @ Sqrt @ Accumulate[bb];Accumulate[bb^2];
cs = 
  Table[
    Module[{as = aa[[;; i]], cs = cc[[;; i]]}, cc[[i + 1]] Total[as]/(as.cs)], 
    {i, Length@ccLength @ cc - 1}]
result = Transpose @ {as, bs, cs}
{{a1, Sqrt[b1]Sqrt[b1^2], c2/c1}, 
 {a1 + a2, Sqrt[b1Sqrt[b1^2 + b2]b2^2], ((a1 + a2)*c3)/(a1*c1 + a2*c2)}, 
 {a1 + a2 + a3, Sqrt[b1Sqrt[b1^2 + b2b2^2 + b3]b3^2], 
    ((a1 + a2 + a3)*c4)/(a1*c1 + a2*c2 + a3*c3)}, 
 {a1 + a2 + a3 + a4, Sqrt[b1Sqrt[b1^2 + b2b2^2 + b3b3^2 + b4]b4^2], 
    ((a1 + a2 + a3 + a4)*c5)/(a1*c1 + a2*c2 + a3*c3 + a4*c4)}}

Not very efficient, but this brute force approach has the advantage of being very easy to code.

data = {{a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}, {a4, b4, c4}, {a5, b5, c5}};
{aa, bb, cc} = Transpose @ data;
as = Most @ Accumulate[aa];
bs = Most @ Sqrt @ Accumulate[bb];
cs = 
  Table[
    Module[{as = aa[[;; i]], cs = cc[[;; i]]}, cc[[i + 1]] Total[as]/(as.cs)], 
    {i, Length@cc - 1}]
result = Transpose @ {as, bs, cs}
{{a1, Sqrt[b1], c2/c1}, 
 {a1 + a2, Sqrt[b1 + b2], ((a1 + a2)*c3)/(a1*c1 + a2*c2)}, 
 {a1 + a2 + a3, Sqrt[b1 + b2 + b3], ((a1 + a2 + a3)*c4)/(a1*c1 + a2*c2 + a3*c3)}, 
 {a1 + a2 + a3 + a4, Sqrt[b1 + b2 + b3 + b4], 
    ((a1 + a2 + a3 + a4)*c5)/(a1*c1 + a2*c2 + a3*c3 + a4*c4)}}

Not very efficient, but this brute force approach has the advantage of being very easy to code.

data = {{a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}, {a4, b4, c4}, {a5, b5, c5}};
{aa, bb, cc} = Transpose @ data;
as = Most @ Accumulate[aa];
bs = Most @ Sqrt @ Accumulate[bb^2];
cs = 
  Table[
    Module[{as = aa[[;; i]], cs = cc[[;; i]]}, cc[[i + 1]] Total[as]/(as.cs)], 
    {i, Length @ cc - 1}]
result = Transpose @ {as, bs, cs}
{{a1, Sqrt[b1^2], c2/c1}, 
 {a1 + a2, Sqrt[b1^2 + b2^2], ((a1 + a2)*c3)/(a1*c1 + a2*c2)}, 
 {a1 + a2 + a3, Sqrt[b1^2 + b2^2 + b3^2], 
    ((a1 + a2 + a3)*c4)/(a1*c1 + a2*c2 + a3*c3)}, 
 {a1 + a2 + a3 + a4, Sqrt[b1^2 + b2^2 + b3^2 + b4^2], 
    ((a1 + a2 + a3 + a4)*c5)/(a1*c1 + a2*c2 + a3*c3 + a4*c4)}}
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Not very efficient, but this brute force approach has the advantage of being very easy to code.

data = {{a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}, {a4, b4, c4}, {a5, b5, c5}};
{aa, bb, cc} = Transpose @ data;
as = Most @ Accumulate[aa];
bs = Most @ Sqrt @ Accumulate[bb];
cs = 
  Table[
    Module[{as = aa[[;; i]], cs = cc[[;; i]]}, cc[[i + 1]] Total[as]/(as.cs)], 
    {i, Length@cc - 1}]
result = Transpose @ {as, bs, cs}
{{a1, Sqrt[b1], c2/c1}, 
 {a1 + a2, Sqrt[b1 + b2], ((a1 + a2)*c3)/(a1*c1 + a2*c2)}, 
 {a1 + a2 + a3, Sqrt[b1 + b2 + b3], ((a1 + a2 + a3)*c4)/(a1*c1 + a2*c2 + a3*c3)}, 
 {a1 + a2 + a3 + a4, Sqrt[b1 + b2 + b3 + b4], 
    ((a1 + a2 + a3 + a4)*c5)/(a1*c1 + a2*c2 + a3*c3 + a4*c4)}}