MathGroup Archive 2013

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

Search the Archive

Re: IntegerPart


The problem is not with IntegerPart, it is with the default setting for
PlotPoints in Plot. You are undersampling since the default value is too
low for your function.


Clear["Global`*"]
nSize = 100;

prefstate = Table[0, {nSize}];


Do[{prefstate[[i]] =
    If[EvenQ[i], 0.8, 0.4]},
  {i, nSize}];


Plot[
 prefstate[[IntegerPart[x]]],
 {x, 1, nSize + 1},
 AxesOrigin -> {0, 0},
 TicksStyle -> 18,
 PlotStyle -> Black,
 PlotPoints -> 125]


Alternatively, use SquareWave instead of prefstate


Plot[
 SquareWave[{0.4, 0.8}, x/2],
 {x, 1, nSize + 1},
 AxesOrigin -> {0, 0},
 TicksStyle -> 18,
 PlotStyle -> Black,
 PlotPoints -> 125,
 ExclusionsStyle -> Black]



Bob Hanlon


On Mon, Apr 1, 2013 at 12:58 AM, <dougwangsaif at gmail.com> wrote:

> can anyone help with this. There seems to be something wrong with the
> IntegerPart function. Please help!
>
> Clear["Global`*"]
> nSize = 100;
>
> prefstate = Table[0, {i, 1, nSize}];
> Do[
>   {prefstate[[i]] = If[EvenQ[i], 0.8, 0.4]},
>   {i, 1, nSize}
>   ];
>
> Plot[{prefstate[[IntegerPart[x]]]}, {x, 1, nSize + 1},
>  AxesOrigin -> {0, 0}, TicksStyle -> Directive[18],
>  PlotStyle -> {Black}]
>
>


  • Prev by Date: Re: ImageTaker[img, {{x1,y1},{x2,y2}} ] useful toolfunction
  • Next by Date: Re: Quit is grayed out in Mathematica 8.0.4
  • Previous by thread: Re: IntegerPart
  • Next by thread: smp: does Mathematica use Lisp ?