Mupad cast boolean to integer

I give a simple example of what I want to do in Matlabs MuPad

S := matrix([[0,S_1,S_2]]);
sum(S[k]*(k < 2)* S[k] * (TRUE), k=1..3)

should be: "S_1^2 + S_2" however I get: Error: The first argument must be of type 'Type::Arithmetical'. [sum]

I understand the error, I just don't know how to succeed. Advice appreciated. I'm looking for some kind of indicator function.

Answers


The question:

Start with the inner term. To have a valid number 0 or 1, I used the following expression:

piecewise([A[k]>a*B[l],1],[Otherwise,0])

The rest is straight forward:

sum(sum(A[k]*B[l]*piecewise([A[k]>a*B[l],1],[Otherwise,0]), l=1..L), k=1..K)

S := matrix([[0,S_1,S_2]]);

sum(S[k]^(4-k), k=1..3)

I'm to really sure what you are trying to do.


Need Your Help

make a div block share a line?

html css

-edit- example: http://jsfiddle.net/AXCap/