MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: SetDelayed::write ... [x_] is protected

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97954] Re: SetDelayed::write ... [x_] is protected
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Thu, 26 Mar 2009 05:23:54 -0500 (EST)

On 3/25/09 at 5:42 AM, Serych at panska.cz (Serych Jakub) wrote:

>Thanks for the Flatten, now it seem that it works (without any error
>messages), but in fact it doesn't work.

>sol = {{i1 -> 220/x}, {i2 -> 100 + x}};
>myfun[x_] := 50*i1 + 2*i2 /. Flatten[sol]
>(no errors here) but:

>In: myfun[1]

>Out: 11000/x + 2 (100 + x)

>and not 11202 which would be result for argument 1.

>So it cannot recognize (or connect together with the pattern x_) the
>= variable x in the result from sol.

What you have done is use SetDelayed. That means by design
evaluation of the

50*i1 + 2*i2 /. Flatten[sol]

part on the right hand side isn't done until myfun is called.
Consequently, nothing matches the pattern x_ and you get the
result you posted. What you need for this application is to
replace SetDelayed with Set which causes evaluation of the right
hand side to occur immediately. That is:

In[1]:= sol = {{i1 -> 220/x}, {i2 -> 100 + x}};
myfun[x_] = 50*i1 + 2*i2 /. Flatten[sol];

In[3]:= myfun[1]

Out[3]= 11202

Does what you want



  • Prev by Date: Re: Re: SetDelayed::write ... [x_] is protected
  • Next by Date: Re: Bug in D (or Derivative) ( Was: Re: DSolve bug)
  • Previous by thread: Re: Re: SetDelayed::write ... [x_] is protected
  • Next by thread: Re: Re: SetDelayed::write ... [x_] is protected