Main Page | Report this Page
 
   
Science Forum Index  »  Math - Symbolic Forum  »  Maxima simple problem...
Page 1 of 1    
Author Message
Vedran...
Posted: Mon Jul 14, 2008 2:56 am
Guest
Hello!

This is my Maxima program:

/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/

/* [wxMaxima: input start ] */
b(SNR, K) := (SNR-K)/3;
/* [wxMaxima: input end ] */

/* [wxMaxima: input start ] */
H:matrix([H11,H12,H13],[H21,H22,H23],[H31,H32,H33]);
/* [wxMaxima: input end ] */

/* [wxMaxima: input start ] */
P:transpose(matrix([P1,P2,P3]));
/* [wxMaxima: input end ] */

/* [wxMaxima: input start ] */
k:0.6;
/* [wxMaxima: input end ] */

/* [wxMaxima: input start ] */
FSAN(H,P,k,i):=(sum((H[j,i]*P[j])^(1/k),j,1,length(P))-(H[i,i]*P[i])^(1/k)
+AWGN^(1/k))^k;
/* [wxMaxima: input end ] */

/* [wxMaxima: input start ] */
SNR[i](H,P,k):=(P[i]*H[i,i])/FSAN(H,P,k,i);
/* [wxMaxima: input end ] */

/* [wxMaxima: input start ] */
SNR[1](H,P,k);
/* [wxMaxima: input end ] */

/* [wxMaxima: input start ] */
FSAN(H,P,k,2);
/* [wxMaxima: input end ] */

/* Maxima can't load/batch files which end with a comment! */
"Created with wxMaxima"$

The problem occurs when I write:
SNR[1](H,P,k);
`length' called on atomic symbol P
#0: FSAN(h=H,p=P,k=k,i=1)
#1: lambda([i],lambda([H,P,k],P[i]*H[i,i]/FSAN(H,P,k,i)))(i=1)
-- an error. To debug this try debugmode(true);

It can be noticed that
FSAN(H,P,k,2);

works ok.

I do not understand how FSAN works when I call it alone, and it doesn't
work when being called from the function SNR[i](...). I guess the error
is quite silly and I'm probably missing something obvious, but as I'm a
Maxima newbie, I'm quite stuck with this problem.

Thanks in advance!
Robert Dodier...
Posted: Mon Jul 14, 2008 5:40 pm
Guest
Vedran wrote:

Quote:
This is my Maxima program:

Kindly cut out the superfluous comments next time, thanks.

Quote:
b(SNR, K) := (SNR-K)/3;
H:matrix([H11,H12,H13],[H21,H22,H23],[H31,H32,H33]);
P:transpose(matrix([P1,P2,P3]));
k:0.6;
FSAN(H,P,k,i):=(sum((H[j,i]*P[j])^(1/k),j,1,length(P))-(H[i,i]*P[i])^(1/k)
+AWGN^(1/k))^k;
SNR[i](H,P,k):=(P[i]*H[i,i])/FSAN(H,P,k,i);
SNR[1](H,P,k);
FSAN(H,P,k,2);

The problem occurs when I write:
SNR[1](H,P,k);
`length' called on atomic symbol P

The problem originates from this: Maxima sees SNR[1] and tries to
construct a function of H, P, and k for the the given value of i
(namely 1). Maxima evaluates the right-hand side of SNR[i](...) := ...
without binding H, P, and k to anything (since arguments are not
yet available). However that leads to trouble because length(P)
triggers an error if P is just a symbol and not bound to a value.

I'm inclined to think that's a bug. I'll take it up with the Maxima
developers.

There are ways to work around it. Probably the most straightforward
is just to omit H and P from the argument list of SNR and FSAN,
so that they appear in those functions as global variables.

By the way, you probably want to write 2 subscripts for P even
though the second subscript is always 1.

HTH

Robert Dodier
 
Page 1 of 1       All times are GMT - 5 Hours
The time now is Sat Nov 22, 2008 12:15 am