Nothing "wrong" with what you're doing. But if the variable 'x' happens to
be defined as 2 or q when you write
f(x) -> x^5 + x^2 - 1;
you will be defining f(x)=2 or f(x)=q^5+q^2-1, which is probably not what
you had in mind.
And then when you define df(x) -> diff(f(x),x), if 'x' happens to be '2',
it will be an error, and if it happens to be 'q', it will be 0....
It would be nicer if Maxima understood lambda notation a bit better, so
that (e.g.) diff(lambda([x],x^3),1) i.e. with respect to the first argument
would return lambda([x],3*x^2). In fact, maybe I'll code that up. And it
would be nice, too, if the token 'lambda' were shorter and clearer to
non-Lisp non-logicians, e.g. func.... This is much cleaner than the
traditional mathematical notation f(x) = x^3.
But there are still the free-variable issues. For example, if you have
a: 2$
f : lambda([x],x^a)$
a: 3$
f(2)$
What is f(2)? Is it 4 (because a=2 when the function was defined) or 8
(because a=3 when the function is called)? And what about block([a:4],f(2))
-- is that 16 or 4/8 (this is the dynamic/lexical scope issue)?
See "Customization" in http://maxima.sourceforge.net/ui-tips.html for
initializations.
-s
On Sat, Nov 26, 2011 at 17:21, Daniel Carrera <dcarrera at gmail.com> wrote:
> On 11/26/2011 10:34 PM, Stavros Macrakis wrote:
>
>> If there was a way to write "nr(2.0)" to mean "nr,x=2.0" I would be happy.
>>>
>>
>> The syntax "nr,x=2.0" is another feature (the "ev" function) that I would
>> discourage you from using. The simple cases work fine, but they don't
>> generalize nicely when you start programming.
>>
>
> :-(
>
>
> That's one way of looking at it. Another way is to realize that every
>> tool
>> has idiosyncracies and you may want to learn to use the tool effectively,
>> which means that you don't necessarily do things in ways that come
>> naturally to you at first.
>>
>> I'm not saying that all these idiosyncracies are intellectually
>> defensible,
>> just that that is what they are for now. But many idiosyncracies respond
>> to concerns that you may not be aware of or interested in.
>>
>
> Ok. Fair enough.
>
>
>
> For example,
>> you seem to want to use Maxima as a desk calculator. But many users of
>> Maxima like to use it as programming language, where the functions they
>> define are not functions mapping numbers to numbers (as in your examples),
>> but functions over *expressions* (mapping expressions to expressions or
>> mapping expressions to numbers).
>>
>
>
> Yes, I basically want a desk calculator to do calculus and algebraic work
> that would take too long to do with a pencil.
>
> My work is done in Fortran 2008. I am interested in astrophysical
> simulations. Last week I wanted to make a polynomial approximation for a
> stellar model and I needed it to have certain smoothness properties. My
> first couple of tries were with a pencil, but I realized I could explore
> more ideas if I used a CAS like Maxima.
>
> I probably won't use a CAS very often, but this week proved to me that I
> should know how to use at least one.
>
> I modified your idea in your previous post. You'll probably consider this
> an abomination, but I kind of like the syntax:
>
>
> infix("->", 20, 20);
> "->"(a,b) := define( ev(a), b );
>
> f(x) -> x^5 + x^2 - 1;
> df(x) -> diff(f(x),x);
> nr(x) -> 1 - f(x)/df(x);
>
>
> Is it possible to add the first two lines to a startup script or something
> so I always have this? Btw, can explain to me why what I'm doing is wrong?
> At first sight it looks innocent enough.
>
> Cheers,
>
> Daniel.
> --
> I'm not overweight, I'm undertall.
>