MathGroup Archive 1993

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

Search the Archive

Plotting without asyptotes.

  • To: mathgroup <mathgroup at yoda.physics.unc.edu>
  • Subject: Plotting without asyptotes.
  • From: HAY at leicester.ac.uk
  • Date: Mon, 13 SEP 93 14:43:54 BST

Here is a lazy man)s way of plotting without asymptotes - you don)t 

need to know where they are.

The third entry is roughly the slope beyond which the line elements

are to be removed.

The function Split may be of independent interest.

The treatment can be varied by, for example, adding an option to

Plot instead of defining a new object, and the deletion process

can be refined, particularly for dealing with multiple plots.



Allan Hayes

hay at leicester.ac.uk









PlotNA[f_,{x_,min_, max_},n:(_?NumberQ):25, opts___?OptionQ] :=

	Module[ {graph,graphNA,pairs,slope,posns},

		graph = Plot[f, {x,min,max}, DisplayFunction->Identity,opts];

		graphNA = 

		 	graph/.Line[lst_] :>

		(

		pairs = Partition[lst, 2, 1];

		slope = 

			Abs[

				(Max[Last/@lst] -Min[Last/@lst])/

				(Max[First/@lst] -Min[First/@lst])

			];

		posns = 

			Position[

				pairs, {

				a_List,b_List}/; 

					Less@@(Abs/@((a-b){n slope,1}))

			]//Flatten;

		Line/@Split[lst,posns]

		);

		Show[graphNA, DisplayFunction -> $DisplayFunction]

	]

	

	



Split[list_List, {breaks___Integer}]/;

	Less[0,breaks,Length[list]]:=

	With[

		{takes =

			Partition[

				Flatten[{1,{#,#+1}&/@{breaks},Length[list]}],

				{2}

			]

		},

		Take[list,#]&/@takes

	];

	

	



Examples:





f[x_] := 

	Which[

		x<2, x^2,

		x<6, Cos[x],

		True, Sin[x]

	]



PlotNA[Tan[x], {x,0,2Pi}, 100, PlotRange ->{-2,2},AspectRatio->1]

PlotNA[{f[x],Tan[x]},{x,0,9}, 

	PlotStyle->{RGBColor[1,0,0], RGBColor[0,0,1]},

	PlotRange -> {-3,3}

]





  • Prev by Date: MatchQ, RepeatedNull
  • Next by Date: Nuclear constants sought
  • Previous by thread: MatchQ, RepeatedNull
  • Next by thread: Nuclear constants sought