[Date Index]
[Thread Index]
[Author Index]
Re: More troubles coming from indexed variables
*To*: mathgroup at smc.vnet.net
*Subject*: [mg25048] Re: More troubles coming from indexed variables
*From*: leko at ix.netcom.com (J. Leko)
*Date*: Sun, 3 Sep 2000 22:11:06 -0400 (EDT)
*References*: <8onen5$okm@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Barbara,
I will attempt an answer to this question, but would prefer confirmation
from someone else with more experience.
As I see it, the problem with method one is that
Head[x[1]]
returns
x
as you have pointed out, and SetAttributes wants to operate on Symbols
which this is certainly not. However, if we performed the following trick:
Head[Head[x[1]]]
then the response is
Symbol
which is just what we need. This has the added benefit of allowing you to
set the attributes of the entire array in a single statement. For example,
I used:
SetAttributes[Head[datsimy[[1]]], Constant]
to set the list attributes, and
Evaluate[Head[datsimy[[1]]]]//Attributes
to display them. Note in these examples that it really doesn't matter what
index value you use, as long as it is a valid array index (i.e., remains
within the defined length of the array)!
I am not certain that this will work for your case, for example, if you
only wanted to set specific elements attributes to Constant. However, at
this point this is the best solution which I can devise.
Hopefully someone else will comment on this (PLEASE)!
Regards,
J. Leko
(Reply via e-mail to: leko*j at cspar.uah.edu and remove the "*" )
In article <8onen5$okm at smc.vnet.net>, Barbara DaVinci
<barbara_79_f at yahoo.it> wrote:
> Cari MathGrouppisti
>
> Some time ago a post of mine just concerned indexed
> variables.
> (I had replies, kind an learned, from many persons -
> Matthias Bode, David Keith, Steven M. Christensen,
> Otto Linsuain and Hartmut Wolf.
> I thank them all.)
>
> Now an even worse trouble is running.
> I'm writing an educational notebook
> on least-square fit and in a subsection I must show
> how the well-known
> formula is carried out.
>
> This provides a symbolic data set :
> datsimx = Table[x[k], {k, 1, 10}]
> datsimy = datsimx /. x -> y
>
> {x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9],
> x[10]}
> {y[1], y[2], y[3], y[4], y[5], y[6], y[7], y[8], y[9],
> y[10]}
>
> Now I must declare x[1] ... x[10] and y[1] ... y[10]
> to be costants
> (otherwise D[] and Dt[] ...) .
>
> I tried two ways, both ineffective.
>
>
> (I)
> -----------------------------------------------------
>
> SetAttributes[SetAttributes, Listable];
> SetAttributes[datsimx, Constant];
> SetAttributes[datsimy, Constant];
>
> but I get
>
> Attributes[datsimx]
> {Constant}
>
> Attributes[datsimx[[1]]]
> Attributes::ssle: Symbol, string, or
> HoldPattern[symbol]
> expected at position 1 in Attributes[datsimx[[1]]]
>
> I suppose that is because
>
> Head[datsimx[[1]]]
> x
>
>
> instead of
>
> Head[datsimx[[1]]]
> Symbol
>
> Therefore I'm not surprised seeing
>
>
> SetAttributes[#, Constant] & @ datsimx
>
> fails too.
>
> (II)
> -----------------------------------------------------
>
> I definded this function
>
> f[x_] := ToExpression[
> StringJoin[
> "Symbol[", ToString[x], "]"
> ]
> ]
> SetAttributes[f, Listable]
>
> whose aim is make x[i] "Symbol headed" ("so doing,
> maybe, SetAttributes stops shouting its warning
> messages", I deceived myself)
>
> But f[datsimx] make me howling with pain again:
>
>
> Symbol::string: String expected at position 1 in
> Symbol[x[1]].
> Symbol::string: String expected at position 1 in
> Symbol[x[2]].
> Symbol::string: String expected at position 1 in
> Symbol[x[3]].
> General::stop: Further output of Symbol::string will
> be suppressed during this calculation.
>
> (This message is rather unclear to me)
>
> -------------------------------------------
> Please, is there a way to get out alive ?
> -------------------------------------------
>
>
> Affettuosi saluti
> (The above is an Italian idiom meaning something like
> "yours sincerely")
>
> Barbara Da Vinci
>
>
> ______________________________________________________________________
> Do You Yahoo!?
> Il tuo indirizzo gratis e per sempre @yahoo.it su http://mail.yahoo.it
Prev by Date:
**Re: Email**
Next by Date:
**NotebookSave**
Previous by thread:
**Re: More troubles coming from indexed variables**
Next by thread:
**Re: More troubles coming from indexed variables**
| |