Hi,
*** I attached a Mathcad sheet exemplifying the issue***
I have a variable j defined below:
This variable can take values like [1], [2], etc. except when type is 12, in which case j=[0,1,2,...,11]
My idea is that the user can select an individual type or select type=12, which includes all types from 0 to 11..
When I multiply two vectors using j to access their elements, it works as intended:
The problem occurs when I want to store this result in a variable.
I want to get rid of those zeros and mimic the C_j * M1_j results shown above. I tried to create a another variable i but for some reason it gives an error:
I wonder if there is a cleaner/easier way of doing this?
Regards,
Solved! Go to Solution.
I see no need for any variable "j" - neither as a range, nor as a vector.
You may use the if-function:
Note that you need to apply vectorization when calculating C*M1.
If you need the variable T to be a vector/matrix even though it consists of just one value, you can do it that way:
and of course you don't have to use the if-function, you can also use the programmed if-statement
Prime 9 worksheet attached
With the statement:
you are simply multiplying two array elements (which are scalars in your case) for every value of j.
If j is a single value, you get a single value as result. If j is a range, you get a range of results:
one result for each product of C[j and M1[j.
With the assignment:
you are creating array elements for each value in the range of j. If j is a single value, say 3, the array T gets created with 4 elements, one with index 0, the second with index 1, third with index 2 and fourth with index 3 (because j=3). The first three are created by default, and set to 0. (You have ORIGIN=0, so indexing starts at 0, another common setting for ORIGIN is 1, so indexing starts at 1 and with the same value j=3 you would get for T a 3-element vector, the first 2 being 0 and the third containing the product C[3*M1[3.
Hope this sheds some light.
You could solve it by:
Success!
Luc
I see no need for any variable "j" - neither as a range, nor as a vector.
You may use the if-function:
Note that you need to apply vectorization when calculating C*M1.
If you need the variable T to be a vector/matrix even though it consists of just one value, you can do it that way:
and of course you don't have to use the if-function, you can also use the programmed if-statement
Prime 9 worksheet attached