Grasshopper

algorithmic modeling for Rhino

I am just stumbling through this, trying to stuff a Gaussian Elimination linear equation solver into the Python script component of GH (using WIP Rhino for Mac).  I get the error shown in picture (and copied at bottom).  The Gaussian Elimination script (included below the pict) works fine in Rhino-Python.

Any thoughts?

"""Provides a scripting component.
Inputs:
x: The x script variable
y: The y script variable
Output:
a: The a output variable"""

import rhinoscriptsyntax as rs

# Copyright (c) Isaac Evans 2011
# All rights reserved.

def myGauss(m):
# eliminate columns
for col in range(len(m[0])):
for row in range(col+1, len(m)):
r = [(rowValue * (-(m[row][col] / m[col][col]))) for rowValue in m[col]]
m[row] = [sum(pair) for pair in zip(m[row], r)]
# now backsolve by substitution
ans = []
m.reverse() # makes it easier to backsolve
for sol in range(len(m)):
if sol == 0:
ans.append(m[sol][-1] / m[sol][-2])
else:
inner = 0
# substitute in all known coefficients
for x in range(sol):
inner += (ans[x]*m[sol][-2-x])
# the equation is now reduced to ax + b = c form
# solve with (c - b) / a
ans.append((m[sol][-1]-inner)/m[sol][-sol-2])
ans.reverse()
return ans

##########################################################################
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.

if( __name__ == "__main__" ):
#Call the function
a = myGauss(x)

ERROR MESSAGE:

{0;0}
0. Runtime error (ArgumentTypeException): __getitem__() takes exactly 2 arguments (1 given)

Traceback:
line 15, in myGauss, "<string>"
line 43, in script

Views: 581

Attachments:

Replies to This Discussion

I got a script to work finally after learning a little about GH data trees and their manipulation, etc.  Still not clear on what flavor of Python is being executed by the GH script component (on Mac with Rhino WIP).  Are negative indices only legal in regular Python v2.7, etc.?

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service