cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Matrix multplication with mid-range indices yields zero values outside the range

TG_8255675
6-Contributor

Matrix multplication with mid-range indices yields zero values outside the range

I have imported excel data and made column vectors from data. When I try to multiply elements with an index beginning somewhere in the range I get this.

TG_8255675_0-1688056063749.png

Why do I get zero values and how might I eliminate this behavior?

Any help would be greatly appreciated.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:TG_8255675)

By default vector indices start with  number 0 and if you assign the vector element 5 a value, you are actually creating a 6-element vector. Elements #0 to 4 are set to 0.

Werner_E_0-1688060422011.png

 

So you might use index i-5 instead of i on the left hand side when you assign the multiplication result.

Other solutions like the usage of the "submatrix" function or the "trim" function are possible, too.

 

Furthermore you should move the return of the result from inside the loop to after the loop - it works the way you did, but its not good programming habit.

 

For future question you should consider attaching your worksheet and stating, which version of Prime you are using.

View solution in original post

3 REPLIES 3
Werner_E
25-Diamond I
(To:TG_8255675)

By default vector indices start with  number 0 and if you assign the vector element 5 a value, you are actually creating a 6-element vector. Elements #0 to 4 are set to 0.

Werner_E_0-1688060422011.png

 

So you might use index i-5 instead of i on the left hand side when you assign the multiplication result.

Other solutions like the usage of the "submatrix" function or the "trim" function are possible, too.

 

Furthermore you should move the return of the result from inside the loop to after the loop - it works the way you did, but its not good programming habit.

 

For future question you should consider attaching your worksheet and stating, which version of Prime you are using.

LucMeekes
23-Emerald III
(To:TG_8255675)

You could also  change the index starting value, it is controlled by the built-in constant ORIGIN:

LucMeekes_0-1688061107328.png

But you probably shouldn't...

 

Success!
Luc

Werner_E
25-Diamond I
(To:LucMeekes)


@LucMeekes wrote:

You could also  change the index starting value, it is controlled by the built-in constant ORIGIN:

 


If he does so, he would multiply the wrong values! He would have to use index i+5 instead of i twice on the right hand side of the assignment!

So I sure would vote against changing ORIGIN to 5 😉

 

A better option may be to trim off the first five entries in the "Row" and "Center" vectors right ahead and then use a vectorized multiplication of the two. But without seeing the sheet and knowing the reason why the first five values in the vectors should not be used, we can't say for sure if that really is the better approach.

Announcements

Top Tags