Topic: Python scripting question

Hi there. Thank you for this software, I use it regularly as a maths tutor. I have started playing with scripting but I keep getting an error. I am running Python 3.2.3 and Graph 4.4.2.

From the console (F11):

>>> Graph.Selected
TStdFunc("f(x)=x^3+4x^2+x+3")
>>> Graph.Selected.Eval(1)
(1.0, 9.0)
>>> Graph.Selected.MakeDifFunc()
TStdFunc("f(x)=3*x^2+8x+1")
>>> dydx = Graph.Selected.MakeDifFunc()
>>> dydx.Eval(1)

This results in an error box displaying the message:

Access violation at address 00520E79 in module 'Graph.exe'. Read of address 00000008.

If I try to do the same thing from a script, I get an error box stating:

Invalid pointer operation.

Does anyone know if this is something that I am doing wrong, or a bug? I'm new to Python so I may be doing something stupid!

Thanks.

Re: Python scripting question

I tried asking the evaluation directly, without going through a dydx variable :

>>> Graph.Selected.MakeDifFunc().Eval(1)

and got that error as well :

Access violation at address 005248A5 in module 'Graph.exe'. Read of address 00000008.

As a workaround, add the derivative of the function to the list of functions in the grf file, and then evaluate the function you want :

>>> Graph.FunctionList.append(Graph.Selected.MakeDifFunc())
>>> Graph.FunctionList[len(Graph.FunctionList)-1].Eval(1)

"len(Graph.FunctionList)-1" is the list index of the last item in the list, since you just appended the derivative at the end of the list. You may want to choose something else. Instead of the last code line I gave you, you may choose to select the derivative and use "Graph.Selected.Eval(1)". Do it as you like.

As for the Access Violation Error, I leave the issue to Ivan.

Re: Python scripting question

I can see that there is a bug in the Eval() function so it assumes that the function always is in the function list and it crashes when it is not. I will try to get it fixed.

Re: Python scripting question

Thank you for the very fast responses. For now I will use the technique suggested by GraphUser3546 and thanks to Ivan for looking into this.