[sage-support] Re: Fwd: sagemath question re: implicit differentiation
Michael, I appreciate your very thoughtful reply. On Jan 20, 10:45 pm, Michael Orlitzky wrote: > > -- Forwarded message -- > > From: storne...@mathisasport.com > > > That's fine, but now I want to solve for dy/dx, so I try: > > > sage: solve(equation2.diff(),diff(f(x),x,1)) > > /home/stornetta/sage-4.7.2/local/lib/python2.6/site-packages/IPython/iplib. > > py:2260: > > DeprecationWarning: Substitution using function-call syntax and > > unnamed arguments is deprecated and will be removed from a future > > release of Sage; you can use named arguments instead, like EXPR(x=..., > > y=...) > > exec code_obj in self.user_global_ns, self.user_ns > > [D[0](f)(x) == -f(x)/(x + 4*f(x))] > > > as you can see, I do get an answer, but the interpreter indicates my > > approach is deprecated, and I'm not clear on how one would use named > > arguments in this situation to achieve the same result. > > f here is a symbolic function taking one argument (forget for a second > that the argument is called 'x'). f(x) means f evaluated at x, which of > course is... f(x), whatever that is. What I'm trying to get at here is > that f(x) isn't the function, f is. > > You can try: > > f = function('f',x) > sage: y = var('y') > sage: f(y) > f(y) > > the call f(y) just substitutes 'y' for 'x' in the definition of f, even > though we don't really have one, we just refer to it by name, f. It's > the same as f(x = y). > > Thus, your call to f(x) up there makes an unnecessary substitution -- > it's equivalent to f(x = x). In fact, to avoid the warning, f(x = x) is > what you would do. Of course, it's better to just pass in f and not > evaluate it: > > sage: f = function('f',x) > sage: equation2 = x*f + 2*f^2 == 1 > sage: solve(equation2.diff(),diff(f,x,1)) > [D[0](f)(x) == -f(x)/(x + 4*f(x))] -- 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 URL: http://www.sagemath.org
[sage-support] Re: Issues with bessel function.
> > error: > > - > > *** SyntaxError: can't assign to function call (, line 1) > > > the code I used was: > > - > > r,p,z,g,k,ro,gro = var('r,p,z,g,k,ro,gro') > > g = 1; k = 1; ro = 1; gro = 1 > > Psi(r,z) = lambda r,z: ((r*bessel_J(1, g*r))/ > > (ro*bessel_J(1,gro)))*(cos(k*z)) > > > The psi function is the line of code that has the issue. > > Do not use 'Psi(r,z) = ...', just use 'Psi = ...'. Such as: > > r,p,z,g,k,ro,gro = var('r,p,z,g,k,ro,gro') > g = 1; k = 1; ro = 1; gro = 1 > Psi = lambda r,z: ((r*bessel_J(1, g*r))/ (ro*bessel_J(1,gro)))*(cos(k*z)) > Great point, Renan. The basic reason is that `Psi(r,z)` creates a symbolic "callable" function, so all of its components need to be symbolic Sage functions. But lambda is (by definition) a Python non-symbolic "regular" function, so you can't combine those notations. -- 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 URL: http://www.sagemath.org
[sage-support] issue with sage -t (sage 4.8)
I have this file 'myclass.py' that contains the following class MyClass(object): @staticmethod def myt(l): """ sage: from myclass import MyClass sage: MyClass.myt([1,2]) [1, 2] """ return l when run sage -t myclass.py , it gives errors about no module named myclass. (details below) My previous code use this format (e.g. from filename import ClassName ... ClassName.foo for testing) and they worked before on Sage version <= 4.72 and now they all report similar error (no module named filename) so something has changed in 4.8 that causes this problem ? Another problem I observed after install Sage 4.8 is also with sage -t , I change a name of a function and update the appropriate test in the comment section , run sage -t on the file -- it keeps reporting the error in the "old" function -- in other words it does not see the new code. Is it being cached somewhere ? I have closed all Sage session and even del my ~/.sage and restart the machine but doesn't seem to help. All of the above problems occur on both of my Linux and Mac OS. Basically now all my tests are broken. sage -t "myclass.py" ** File "/Users/tnguyen/Dropbox/code/invgen/ig120123/myclass.py", line 7: sage: from myclass import MyClass Exception raised: Traceback (most recent call last): File "/Users/tnguyen/Src/Devel/SAGE/sage/local/bin/ncadoctest.py", line 1231, in run_one_test self.run_one_example(test, example, filename, compileflags) File "/Users/tnguyen/Src/Devel/SAGE/sage/local/bin/sagedoctest.py", line 38, in run_one_example OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags) File "/Users/tnguyen/Src/Devel/SAGE/sage/local/bin/ncadoctest.py", line 1172, in run_one_example compileflags, 1) in test.globs File "", line 1, in from myclass import MyClass###line 7: sage: from myclass import MyClass ImportError: No module named myclass ** File "/Users/tnguyen/Dropbox/code/invgen/ig120123/myclass.py", line 9: sage: MyClass.myt([1,2]) Exception raised: Traceback (most recent call last): File "/Users/tnguyen/Src/Devel/SAGE/sage/local/bin/ncadoctest.py", line 1231, in run_one_test self.run_one_example(test, example, filename, compileflags) File "/Users/tnguyen/Src/Devel/SAGE/sage/local/bin/sagedoctest.py", line 38, in run_one_example OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags) File "/Users/tnguyen/Src/Devel/SAGE/sage/local/bin/ncadoctest.py", line 1172, in run_one_example compileflags, 1) in test.globs File "", line 1, in MyClass.myt([Integer(1),Integer(2)])###line 9: sage: MyClass.myt([1,2]) NameError: name 'MyClass' is not defined ** 1 items had failures: 2 of 5 in __main__.example_0 ***Test Failed*** 2 failures. For whitespace errors, see the file /Users/tnguyen/.sage//tmp/myclass_2814.py [3.3 s] -- 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 URL: http://www.sagemath.org