Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8256
| From | Chris <kristophs.post@web.de> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | large lists with variable and if condition (vrs. 8.0.4) |
| Date | 2012-01-31 10:42 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jg8gi2$13i$1@smc.vnet.net> (permalink) |
Hi
I would like to construct a large list or large table with some data
and one unknown variable which I need for optimization purposes in say
a for loop. Constructing the whole list at each iteration is time
consuming and slows the optimization down.
First, I present some code that works just fine in order to get the
idea:
(*inputs)
leg = 100;
data = RandomReal[{}, leg];
(*constructing the list with the data in which g is a non-specfied
variable*)
Clear[list, list2, tab];
list = Table[(data[[i]] - data[[leg - i + 1]])/g, {i, 1, leg}];
(*specifying the function and the result*)
tab[k_] := list /. g -> k;
tab[1]
Now the following code does not work and I don't know why.
list2=
Table[If[Abs[(data[[j]]-data[[i]])/x]<1.,.75 (1.-((data[[j]]-
data[[i]])/x)^2),0.],{i,1,leg},{j,1,leg}];
mat[bw_Real]:=list/.x->bw
It seems to me, when looking at list2, that Mathematica is not
evaluating the when-part of the if-function when the if-part depends
on the unknown variable. Hence, an error message.
Constructing the list as:
mat[bw_Real]:=Table[If[Abs[(data[[j]]-data[[i]])/bw]<1.,.75 (1.-
((data[[j]]-data[[i]])/bw)^2),0.],{i,1,leg},{j,1,leg}];
is not an option because it slows things down.
Thanks for answer.
Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread
large lists with variable and if condition (vrs. 8.0.4) Chris <kristophs.post@web.de> - 2012-01-31 10:42 +0000 Re: large lists with variable and if condition (vrs. 8.0.4) "Oleksandr Rasputinov" <oleksandr_rasputinov@ymail.com> - 2012-02-01 08:51 +0000
csiph-web