Thanks a lot, that should work. I will have to do the symbolic derivations first and then convert the results into python functions before doing numerical computations.
Cheers Stan On Jun 5, 1:23 pm, Marshall Hampton <[EMAIL PROTECTED]> wrote: > Here is a somewhat different solution that you might like more: > > sage: var('x,a,b') > sage: def f(x): > return 2*x^a + b > > sage: f(x) > 2*x^a + b > > sage: a = 2; f(x) > 2*x^2 + b > > sage: b = 1; f(x) > 2*x^2 + 1 > > The fact that f is a python function instead of a SymbolicArithmetic > object has both advantages and disadvantages. I prefer it because I > have a better understanding of the basic python objects. > > Cheers, > Marshall Hampton > > On Jun 5, 5:36 am, Stan <[EMAIL PROTECTED]> wrote: > > > Dear Robert, > > > Thanks a lot for the quick solution. That's a whole new support > > experience! > > > I was hoping I could define > > z=y.subs(locals()) > > so that z would automatically adapt if the local variables change, but > > it does not. Every time I change the local variables, I have to > > redefine z=y.subs(locals()) > > to update it. Whereas this is better than writing y(a=3,b=4), it would > > be even more convenient if I could define a function that > > automatically takes the actual local variables. > > Almost there... > > > Thanks again, > > Stan > > > On Jun 5, 11:47 am, Robert Bradshaw <[EMAIL PROTECTED]> > > wrote: > > > > On Jun 5, 2008, at 2:34 AM, Stan wrote: > > > > > Dear all, > > > > > I would like to use Sage as an alternative to Mathematica and I am > > > > quite amazed about the demonstrated functionality of Sage. I just have > > > > a very basic problem with the way I am used to do calculations. Often, > > > > I define a set of equations with different variables in them, then I > > > > solve the equations for example for y, set some of the variables to > > > > prescribed values and plot y as a function of the free variable. In > > > > Sage, a symbolic function does not replace the variables by numbers if > > > > the variables have values assigned to them. > > > > > Example: > > > > > sage: var ('x a b') > > > > (x, a, b) > > > > sage: y=2*x^a+b > > > > sage: a=3;b=4 > > > > sage: y > > > > 2*x^a + b > > > > sage: y(a=3,b=4) > > > > 2*x^3 + 4 > > > > > In the above example, y only uses the values of a and b if they are > > > > explicitly included in the call. This would become very tedious for a > > > > system of equations if I want to plot several of them with the same > > > > parameter values. > > > > > Is there a way of formulating equations that will automatically > > > > evaluate if their variables have values assigned to them? > > > > I would try something like > > > > sage: var ('x a b') > > > (x, a, b) > > > sage: y=2*x^a+b > > > sage: a=3;b=4 > > > sage: y > > > 2*x^a + b > > > sage: y.subs(locals()) > > > 2*x^3 + 4 > > > > This will take all the local variables (with their names) and plug > > > their values in. > > > > > Same example in Mathematica: > > > > > In[282]:= > > > > y=2*x^a+b > > > > > Out[282]= > > > > b + 2 x^a > > > > > In[283]:= > > > > a=3;b=4; > > > > y > > > > > Out[284]= > > > > 4 + 2 x^3 > > > > > Thanks for your help! > > > > > Stan --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---