Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: apply rule to Partition
Replies: 6   Last Post: Sep 21, 2013 4:34 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Tomas Garza Hernandez

Posts: 264
Registered: 4/15/05
Re: apply rule to Partition
Posted: Sep 21, 2013 4:21 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


The error message doesn't prevent the evaluation from taking place. In this case it acts more as a warning. You may eliminate this warning using Quiet:
In[1]:= Partition[Range[10],m]/.m->3//QuietOut[2]= {{1,2,3},{4,5,6},{7,8,9}}
Alternatively you can write the ReplaceAll inside the brackets:
In[3]:= Partition[Range[10],m/.m->3]Out[3]= {{1,2,3},{4,5,6},{7,8,9}}
or you can use With:
In[5]:= With[{m=3},Partition[Range[10],m]]Out[5]= {{1,2,3},{4,5,6},{7,8,9}}
In all cases, m has to be a positive integer; otherwise the error actually prevents the evaluation. The definition of Partition doesn't make this explicit but I guess it goes without saying.
-Tomas

> From: jougraw@gmail.com
> Subject: apply rule to Partition
> To: mathgroup@smc.vnet.net
> Date: Fri, 20 Sep 2013 07:06:57 -0400
>
>
> I want to use rule to simplify my code. A piece of my code use Partition
> and I tried something like:
>
> Partition[Range[10], m] /. m -> 2
>
> It give me error message. My real code is in fact more complicated and this
> way failed to give me an output. How could I make it work?
> Thanks.
>
>






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.