# Matrix manipulations, anyone?

0 Favourites
• 7 posts
• I am in the process of trying to build a DC circuit simulator similar to the excellent one available at phet.colorado.edu. In order to make it work, I will need to do some matrix manipulations, specifically, computing the inverse of a matrix of size n x n and matrix multiplication.

Has anyone attempted to do this in Construct 2?

Methinks an extension to the Array plugin would be really cool...

• This sounds like much more than an array plugin extension. You can probably achieve this easily enough with an existing javascript matrix library though, or even build a plugin around an existing library.

• So I've tried the following so far to recursively compute an array determinant:

1. I've created an object called "array" in the layout. On start of layout I set all of the values for each XY.

2. Each time I call the "computedeterminant" function, I create a new, smaller array of (n-1) x (n-1) for the next step in the recursion.

3. My plan was to pick a value from the smaller array, set it to a temporary variable, then plug that value into the bigger array.

It looks like my smaller arrays aren't getting filled properly because I can't pick the original by UID.

• I smell a job for the hound

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Picking problem is solved with the "System -> Pick All" condition. Thank you Yann for the excellent picking video!

On to other troubleshooting...

• [attachment=0:3vh4bsl5][/attachment:3vh4bsl5]

So here is my most recent attempt. It looks like the value of the local variable "determinant" is being reset inappropriately in a recursion loop. Maybe a javascript variable scope issue?

• The determinant is now computed correctly. The problem appears to be that loopindex("x") is in the global scope. In other words, if you recursively call a function with for() loops in it, it will always reference the first time you called a loop of that name. The solution was to uniquely identify the loop with a different name in each iteration.

In this case, instead of calling a for() loop with the tag "i", I called the for loop with the tag "i"&n, where n is the current size of the matrix I am working with. This is unique for each level of the recursion.

See the attached image for the solution.

Ashley, is recursion supposed to work this way? Or am I missing something?

[attachment=0:1ayng80n][/attachment:1ayng80n]: