Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Trouble Reassigning element in a set' topicStudent Support Forum > General > "Trouble Reassigning element in a set"

Next Comment >Help | Reply To Topic
Author Comment/Response
Amanda
05/15/12 7:14pm

Hi, I don't use mathematica much, so maybe I am doing something really silly. I am trying to reassign the last element of a set with another element. Here is the relevant portion of my code:

nelder[Set_, f_, tau_, kmax_, n_, mu_, x_] :=
Module[{S = SortBy[Set, f], fflag, gflag, fcount, xbar, xmax, varr,
fr, vare, fe, varoc, foc, varic, fic, i},
.
.
.
While[f[S[[n + 1]]] - f[S[[1]]] > tau && fcount < kmax,
xbar := Total[S]/n;
xmax := S[[n + 1]];
varr := x[mu[[1]], xmax, xbar];
Print[S];
fr := f[varr];
fcount++;

If[ fcount == kmax, Break];

If[f[S[[1]]] <= fr && fr < f[S[[n + 1]]],
Print["varr ", varr];
S[[n + 1]] = varr; (* THIS ASSIGNMENT IS NOT WORKING! *)

Print["Sn+1 ", S[[n + 1]]];
gflag := 1 ];
.
.
.

AND it prints out

{{1,1},{1,2},{-1,-1},{3,4}}

varr {-(1/3),0}

Sn+1 {3,4}


Could someone please help explain to me why this re-assignment is not working as I want it to? Thanks!

URL: ,

Subject (listing for 'Trouble Reassigning element in a set')
Author Date Posted
Trouble Reassigning element in a set Amanda 05/15/12 7:14pm
Re: Trouble Reassigning element in a set Bill Simpson 05/15/12 10:31pm
Re: Trouble Reassigning element in a set Peter Pein 05/16/12 03:54am
Next Comment >Help | Reply To Topic