0
$\begingroup$

basically, I have a 4 dimensional matrix and I am looking to apply the following function:

results=Table[Mean[Total[Table[matrix[[a, b, c, d]]*Function[w,
        If[w < p[[m, 1, 1]], 0,
         If[
          p[[m, 1, 1]] <= w < p[[m, 1, 2]], (w - p[[m, 1, 1]])*
           p[[m, 2, 1]],

          If[p[[m, 1, 2]] <= w < 
            p[[m, 1, 3]], (p[[m, 1, 2]] - p[[m, 1, 1]])*
             p[[m, 2, 1]] + (w - p[[m, 1, 2]])*
             p[[m, 2, 2]], (p[[m, 1, 2]] - p[[m, 1, 1]])*
             p[[m, 2, 1]] + (p[[m, 1, 3]] - p[[m, 1, 2]])*
             p[[m, 2, 2]] + (w - p[[m, 1, 3]])*p[[m, 2, 3]]]]]]
       [matrix[[a, b, c, d]]], {a,1,2},{b, 1, 8}, {c, 1, 5}, {d, 1, 
     [Length[[d]]}], {2}]], {m, 1, 7}]

I would like the results to run through all iterations of a,b,c and the different lengths of d, depending on c. I keep getting error messages and dont really know how to iterate based on the lenght of d, which is different for every c and a.

Does this make sense?

Any help appreciated,

Thank you!

$\endgroup$
  • $\begingroup$ Your code has some basic syntax problems. For example: [matrix[[a, b, c, d]]] is not a legal construction, neither is [Length[[d]]} $\endgroup$ – bill s Apr 24 '18 at 13:03
  • $\begingroup$ Perhaps you could explain what you want to do to the matrix in words? Some syntax issues in your current code make it hard to follow. $\endgroup$ – MarcoB Apr 24 '18 at 13:54
  • $\begingroup$ if d is something with a length then you can not also use it as an iterator. $\endgroup$ – george2079 Apr 24 '18 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.