0

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.

apfel
  • 3
  • 3

2 Answers2

0
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.

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • I have some formula of the form \sum_{k=0}^K\sum_{l=0}^L [A_k*B_l * (A_k > \alpha B_l)] and I'm trying to expand the sum by a CAS rather than doing it by hand for various \alpha and various L,K, A_k, B_l. The inequation should yield 1 if the statement is true and 0 otherwise. Of course it is obvious what to do for a given set of parameters, however because of that a machine can do it. This is the motivation behind this. Maybe you can help me with another approach. – apfel Jan 31 '14 at 21:56
  • The `* (A_k > \alpha B_l)` part is strictly speaking invalid, because a boolean expression is multiplied with a number. But it's obvious what is intended, I'll write a new answer. – Daniel Jan 31 '14 at 22:08
0

The question:

enter image description here

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)
Daniel
  • 36,610
  • 3
  • 36
  • 69
  • It seems a bit bulky but it actually works. Is there a way to shorten the input by maybe defining a procedure? I tried but it lacked the ability described in the next sentence. Your solution even distinguishes all possible cases if the logical expressions cannot be evaluated to true or false. – apfel Feb 01 '14 at 12:43