Oh right, sorry.  I always do that and then remember after the syntax
error...

On Aug 14, 6:35 pm, William Stein <wst...@gmail.com> wrote:
> On Fri, Aug 14, 2009 at 4:32 PM, Marshall Hampton<hampto...@gmail.com> wrote:
>
> > You probably have to pass in the "dx" as a local variable, i.e. do
> > something like
>
> > sage_stuff = sage_eval(expr, locals = {'dx' = 'dx'})
>
> It's {'dx':'dx'} or something like that.  Definitely not 'dx' = 'dx'.
>
>
>
>
>
> > where expr is your mathematica expression.
>
> > -Marshall Hampton
>
> > On Aug 14, 1:49 pm, Viny <hje...@hotmail.com> wrote:
> >> Thanks for your help Felix, with your ideas i made progresses. But the
> >> problem isn't fixe yet. Since i have some symbolic variable such 'dx'
> >> in my expressions, the
> >> code's line --> 500  return eval(string, {'I': numpy.complex(0,1)})
> >> generate this folowing error
> >> NameError: name 'dx' is not defined
> >> Even when i put in the begining of my function var ("dx"), the problem
> >> stay.
>
> >> Thanks again
>
> >> On 14 août, 04:04, thelamecamel <thelameca...@gmail.com> wrote:
>
> >> > Hi Viny,
>
> >> > Sage's mathematica support at present seems to be geared towards
> >> > sending data to mathematica and printing the results to the screen,
> >> > rather than getting mathematica's results back into sage for data
> >> > manipulation.  So the going may be a little rough.
>
> >> > Sage can convert its own arrays into mathematica's notation, e.g.
> >> > Jason's example
> >> > sage: b=mathematica([1,2,3])
> >> > will create a mathematica variable representing the array {1,2,3},
> >> > accessible from sage.  I'm not sure whether you can send mathematica
> >> > more complicated things such as functions in this fashion.
>
> >> > Once you've got your variables into mathematica, you perform
> >> > mathematica functions on them like so:
> >> > sage: x = mathematica(1)
> >> > sage: mathematica.eval('myfunc[x_,y_]:=x+y')
> >> > sage: x.myfunc(2)
> >> > 3
>
> >> > It's hard to get your mathematica results back into sage for use.  As
> >> > Jason noted below, mathematica arrays with {} don't get converted back
> >> > into sage arrays with []. There is a ticket related to the array
> >> > problem <http://trac.sagemath.org/sage_trac/ticket/4948>, but there
> >> > seems to be no progress on it.
>
> >> > I gave up and rolled my own mathematica list to numpy array conversion
> >> > - you might find it useful.  I believe that using eval() is frowned
> >> > upon for security reasons.  If you want sage arrays rather than numpy
> >> > arrays, then use sage_eval() (which is considerably slower for large
> >> > arrays) and strip out the numpy stuff.  Comments on the below code are
> >> > welcome.
>
> >> > import numpy
> >> > import re
> >> > def mma_to_numpy(mma_arr):
> >> >     """Convert mathematica array to numpy array."""
> >> >     # Convert the mathematica object to a string
> >> >     string = repr(mma_arr)
> >> >     # Convert mathematica-style {} to python style []
> >> >     string = string.replace('{','[').replace('}',']')
> >> >     # Replace mathematica's crazy exponent notation with the standard
> >> > one
> >> >     string = string.replace('*^', 'e')
> >> >     # Delete new lines (both \n and \r\n appear sporadically)
> >> >     string = string.replace('\n', ' ').replace('\r', ' ')
> >> >     # Detect characters that should not be in an array
> >> >     if re.findall(r'[a-df-zA-HJ-Z]+', string) != []:
> >> >         raise TypeError, "Mathematica returns non-array: %s" % string
> >> >     # Read the string into numpy, interpreting I as j
> >> >     return eval(string, {'I': numpy.complex(0,1)})
>
> >> > You use it as such:
> >> > sage: b = mathematica([1.5,2.+3.j,3])
> >> > sage: b
> >> > {1.5, 2. + 3.*I, 3}
> >> > sage: numpy.array(mma_to_numpy(b), dtype='D')
> >> > array([ 1.5+0.j,  2.0+3.j,  3.0+0.j])
>
> >> > Hope that this helps - there isn't much documentation on this stuff.
>
> >> > Cheers,
> >> > Felix
>
> >> > On Aug 13, 8:26 pm, Viny <hje...@hotmail.com> wrote:
>
> >> > > On 13 août, 10:47, Viny <hje...@hotmail.com> wrote:
>
> >> > > > Hi,
>
> >> > > > I have a problem of memory into maxima when it performs a symbolic
> >> > > > expression of an hessian matrix. This symbolic expression of the
> >> > > > hessian seems to be too big. My sage program is written using python.
> >> > > > And i want to compute the hessian matrix with mathematica 6.0 in my
> >> > > > sage file.
> >> > > > I need to compute symbolic expresstion of the gradient and the 
> >> > > > hessian
> >> > > > with mathematica and after compute the mathématica LinearSolve
> >> > > > function to solve hessian^-1*grad.
> >> > > > How to make this interface in my .sage?
> >> > > > Please help me!!!
>
> >> > > > I have mathematica 6.0 and sage4.0.2 in my linux 64bit system.
>
> >> > > This is an example of the function to compute the gradient in
> >> > > my .sage, but it doesn't work.
> >> > > def grad(f,v):
> >> > >           return mathematica ( f ).D( [ ' v ',1] )
> >> > > The result is {0,0} . I have another problem of format, i don't know
> >> > > the command to change { } in () in the mathematica result {0,0}
>
> --
> William Stein
> Associate Professor of Mathematics
> University of Washingtonhttp://wstein.org
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to