|
[Date Index]
[Thread Index]
[Author Index]
Re: How to change the argument of a function?
Vilis Nams wrote:
>
> I want to define a function that in the course of doing something, also
> changes the value of its argument, for example: f[x_]:=Module[{},
> x=2*x;
> x
> ]
> When I run the function, I get the error: "Set::setraw : Cannot assign
> to raw object ...." Can this be done in some way?
>
Vilis:
Could you explain more fully what you wish to do please? I'm not sure
what "changes the value of its argument" means. The trouble with
In[1]:=
f[x_]:=Module[{},
x=2*x;
x
]
In[2]:=
f[2]
>From In[2]:=
Set::setraw: Cannot assign to raw object 2.
Out[2]=
2
is that every x on the right is replaced by 2, so that Mathematica is
asked to evaluate Module[{}, 2 = 2 2, 2], and can't assign to 2.
But,
f[x_] := 2 x
does what you seem to have been aiming.
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642
Prev by Date:
Error Bars
Next by Date:
Re: Solve, Plot and limits
Prev by thread:
Re: How to change the argument of a function?
Next by thread:
RE: How to change the argument of a function?
|