On 02/03/2012 08:48 PM, Pier wrote:
> (%i6) a:1;
> (%i7) b:1;
> (%i8) c:1;
> (%i9) e:1;
> (%i10) f:0.5;
> (%i11) g:1;
> (%i12) r:a*x+b*y+c;
> (%i13) s:e*x+f*y+g;
> (%i14) P:linsolve([r,s],[x,y]); centre point of the star
> (%i15) ex:r+K*s;
> (%i16) solve(ex,y); copy and paste the rhs of the output as rhs of %i17
> (%i17) Z(x,K):=-((2*x+2)*K+2*x+2)/(K+2);
> (%i18) F:makelist(Z(x,K),K,0,10);
> (%i19) plot2d(F,[x,-5,5]);
>
> One thing I haven't been able to do is to avoiding copying-pasting the rhs
> output of %i16
>
> y=-((2*x+2)*K+2*x+2)/(K+2)
>
> as the rhs in %i17. I tried with:
>
> Z(ex,K):=solve(ex,y);
>
> but that didn't work.
I guess you meant "Z(x,K) := solve(ex,y)", but that will fail by two
reasons. The first reason,
already pointed out by Ray, is that solve will give you a list of
equations, even if there is
only one solution. You want just the right hand side of the first
equation in the list returned
by solve: rhs(first(solve(ex, y)))
(or use [1] instead of first).
The second reason is that := will not evaluate its arguments. That means
that in the
command "Z(x,K) := rhs (first (solve (ex, y)))" ex will not be solved to
find y, but
that step will be delayed until you try to evaluate Z(x,k) at some later
time; that might
work but it might also give you unintended results; for instance:
(%i15) Z(x,K) := rhs ( first(solve(ex,y)));
(%o15) Z(x, K) := rhs(first(solve(ex, y)))
(%i16) y:3;
(%o16) 3
(%i17) Z(2,4);
solve: all variables must not be numbers.
#0: Z(x=2,k=4)
-- an error. To debug this try: debugmode(true)
by the time Z tried to use solve, y was no longer an undefined variable
so it failed.
As I pointed out in my previous message you should better use expressions:
Z: rhs ( first(solve(ex,y)));
but if you insist on using functions, then use define() instead of :=
define (Z(x,K), rhs ( first(solve(ex,y))));
the difference between f(x):=exp and define(f(x),exp) is that define
will first evaluate its arguments
before defining the function. In the case above, solve, first and rhs
will be executed before Z(x,K) is defined.
I also use Maxima extensively in my Physics lectures; I'm interested to
know what courses
you are teaching.
Cheers,
Jaime