Hi,
I am trying to use ReplacePart in a function definition. The function
works using =, but not :=
newX= ReplacePart[x,{y[[1, 1]], y[[2, 1]]} -> x[[y[[1, 1]], y[[2,
1]]]] - y[[2, 2]]]
... works
update[x, y] := ReplacePart[
x,
{y[[1, 1]], y[[2, 1]]} -> x[[y[[1, 1]], y[[2, 1]]]] - y[[2, 2]]
]
... SetDelayed::write: Tag List in <snip> is Protected.
x and y are just integer lists. The problem seems to be Mathematica
trying to replace the head (List) of the rule in ReplacePart... even
though this is just correct syntax for replace part.
I tried using RuleDelayed but no change. Many functions use rules in
their syntax so this must be a general issue I haven't come across
yet.
cheers
B
|
|
0
|
|
|
|
Reply
|
niobe
|
11/7/2010 10:11:17 AM |
|
On Nov 7, 2:11 am, niobe <ben.carb...@gmail.com> wrote:
> Hi,
>
> I am trying to use ReplacePart in a function definition. The function
> works using =, but not :=
>
> newX= ReplacePart[x,{y[[1, 1]], y[[2, 1]]} -> x[[y[[1, 1]], y[[2,
> 1]]]] - y[[2, 2]]]
>
> .. works
>
> update[x, y] := ReplacePart[
> x,
> {y[[1, 1]], y[[2, 1]]} -> x[[y[[1, 1]], y[[2, 1]]]] - y[[2, 2]]
> ]
> .. SetDelayed::write: Tag List in <snip> is Protected.
>
> x and y are just integer lists. The problem seems to be Mathematica
> trying to replace the head (List) of the rule in ReplacePart... even
> though this is just correct syntax for replace part.
>
> I tried using RuleDelayed but no change. Many functions use rules in
> their syntax so this must be a general issue I haven't come across
> yet.
>
> cheers
>
> B
The two arguments in the definition of update are not patterns:
update[x, y] := ...
Try: update[x_, y_] := ...
|
|
0
|
|
|
|
Reply
|
Raffy
|
11/8/2010 8:37:46 AM
|
|
Apologies, that was just a typo when copying to email and my function
arguments are correct
update[x_, y_] := ReplacePart[
x,
{y[[1, 1]], y[[2, 1]]} -> x[[y[[1, 1]], y[[2, 1]]]] - y[[2, 2]]
]
... SetDelayed::write: Tag List in <snip> is Protected.
Has no-one else encountered this issue?
|
|
0
|
|
|
|
Reply
|
niobe
|
11/9/2010 8:54:09 AM
|
|
On Nov 9, 12:54 am, niobe <ben.carb...@gmail.com> wrote:
> Apologies, that was just a typo when copying to email and my function
> arguments are correct
>
> update[x_, y_] := ReplacePart[
> x,
> {y[[1, 1]], y[[2, 1]]} -> x[[y[[1, 1]], y[[2, 1]]]] - y[[2, 2]]
> ]
> .. SetDelayed::write: Tag List in <snip> is Protected.
>
> Has no-one else encountered this issue?
Could you provide a x, y pair that reproduce this error?
I would avoid using ReplacePart. If I understand your example
correctly...
y is a ragged array: {{row}, {col0, col1}}
And you're performing the following operation: x[[row, col0]] - x[[row, col1]]
update2[x_, {{row_}, {col0_, col1_}}] := Module[{temp = x},
temp[[row, col0]] -= temp[[row, col1]];
temp
];
|
|
0
|
|
|
|
Reply
|
Raffy
|
11/10/2010 11:27:45 AM
|
|
> Could you provide a x, y pair that reproduce this error?
x={{7, 9, 0, 0, 10}, {4, 0, 3, 10, 9}, {4, 9, 0, 5, 0}, {0, 2, 1, 8,
5}, {2, 5, 3, 4, 4}, {1, 0, 4, 0, 0}, {1, 10, 6, 8, 9}}
y={{4, 5}, {3, 1}, {2, 6}}
> I would avoid using ReplacePart. If I understand your example
> correctly...
>
> y is a ragged array: {{row}, {col0, col1}}
Think of x as a lists of quantities and y as rules for adjusting them.
So in this example of y, decrement x[[4,3]] by 2, increment x[[5,3]]
by 2, increment x[[4,1]] by 6, decrement x[[5,1]] by 6,
But the point is that the operation works when not delayed. It seems
like the way command is being parsed is the problem as Mathematica is
thinking that the ReplacePart syntax is actual an operation on one of
the arguments. I am hoping there is a way to force the correct
interpretation.
|
|
0
|
|
|
|
Reply
|
niobe
|
11/11/2010 11:11:39 AM
|
|
|
4 Replies
1142 Views
(page loaded in 0.063 seconds)
Similiar Articles: Tag List Protected error - comp.soft-sys.math.mathematica ...Hi, I am trying to use ReplacePart in a function definition. The function works using =, but not := newX= ReplacePart[x,{y[[1, 1]], y[[2, 1]]} ... emacs lisp tutorial: list & vectors - comp.emacsTag List Protected error - comp.soft-sys.math.mathematica ... However, I have no idea of Emacs Lisp. Hence, I could not ... I suppose one could add a specific tag to ... Why no std::back_insert_iterator::value_type? - comp.lang.c++ ...Tag List Protected error - comp.soft-sys.math.mathematica ... Why no std::back_insert_iterator::value_type? - comp.lang.c++ ... Tag List Protected error - comp.soft-sys ... Math operations on fields of different rows - comp.lang.awk ...Tag List Protected error - comp.soft-sys.math.mathematica ..... col1}} And you're performing the following operation: x[[row ... comp.soft-sys.math.mathematica 26853 ... Could anyone give me the spice-mode.el - comp.emacsHi, All I am new to *NIX and I am thinking of writing spice code under Emacs. However, I have no idea of Emacs Lisp. Hence, I could not write a packa... How to create a TIFF image from a binary raw data - comp.lang.java ...... Image.java:8: class, interface, or enum expected protected ... I used Eclipse and there is no compilation error. ... file. ... api.opengl TIF Image File Format TIFF - Tag ... [comp.publish.cdrom] CD-Recordable FAQ, Part 1/4 - comp.publish ...Archive-name: cdrom/cd-recordable/part1 Posting-Frequency: monthly Last-modified: 2008/10/09 Version: 2.71 Send corrections and updates to And... How best to detect duplicate values in a column? - comp.databases ...Like can I set an error-condition catcher around an ... primary purpose of censoring nominations is to protect ... millisecond investment that was really just a *tag ... C++: PTHREAD_CANCEL_ASYNCHRONOUS and random crash - comp ...The same error > happens regardless of whether there is ... Protect a semaphore of crash in the critical area - comp ... Category: Comedy Tags: fun funny crash outsch aua ... Windows Time with NTPv4 - comp.protocols.time.ntp... those at USNO and NIST, have specific means > to protect ... 44:34-05:00, stenn@whimsy.udel.edu ntp-4.1.1 TAG ... peer as one term in the estimation of their time error ... Tag List Protected error - comp.soft-sys.math.mathematica ...Hi, I am trying to use ReplacePart in a function definition. The function works using =, but not := newX= ReplacePart[x,{y[[1, 1]], y[[2, 1]]} ... Troubleshooting Protection Agent Installation IssuesThe following table provides troubleshooting guidance that supplements the specific error messages that you may encounter during protection agent installation. 7/23/2012 12:04:11 PM
|