From: Vedhas | sahdeV on
a = {1 2 3 4 5 6}
The goal is to plot a piecewise function corresponding to each of "a"
values, with manipulate where control variable is p, and the function
for plot y versus x is:
y=x-p for x-p<a, and (x-p)^2 for (x-p)>=a i.e. 6 plots getting
manipulated simultaneously.

I am new to Mathematica and this might be a naive question, but I
couldn't find a solution through help documentation. I will appreciate
if you can help!

Thanks,

Vedhas

From: Patrick Scheibe on
Hi,

I hope I got your explanation right. You could define your plot-function
for one pair of params {a,p} and map it over your list a. So you get a
list of 6 plots which you can show:

a = {1, 2, 3, 4, 5, 6};
plotfunc[a_, p_] := Plot[
Piecewise[{{x - p, x - p < a}}, (x - p)^2], {x, 0, 20},
PlotRange -> {Automatic, {0, 100}},
PlotLabel -> ("Value for a is " <> ToString[a])];
Manipulate[
Grid[
Partition[Map[plotfunc[#, p] &, a], 3]]
, {p, 0, 20}]


my preferred solution would be to use /@ for map and make an anonymous
function for your plot

Manipulate[
Grid[
Partition[Plot[
Piecewise[{{x - p, x - p <= #}}, (x - p)^2], {x, 0, 20},
PlotRange -> {Automatic, {0, 50}},
PlotLabel -> ("Value for a is " <> ToString[#])] & /@ Range[6],
3]]
, {p, 0, 20}]

Cheers
Patrick

On Sun, 2010-02-21 at 04:24 -0500, Vedhas | sahdeV wrote:
> a = {1 2 3 4 5 6}
> The goal is to plot a piecewise function corresponding to each of "a"
> values, with manipulate where control variable is p, and the function
> for plot y versus x is:
> y=x-p for x-p<a, and (x-p)^2 for (x-p)>=a i.e. 6 plots getting
> manipulated simultaneously.
>
> I am new to Mathematica and this might be a naive question, but I
> couldn't find a solution through help documentation. I will appreciate
> if you can help!
>
> Thanks,
>
> Vedhas
>


From: Bob Hanlon on

If you plot all of the curves on a single plot they will overlap and make it difficult to see what is happening.
Recommend an array of plots.

Manipulate[
Grid[
Partition[
Table[
Plot[
Piecewise[{
{x - p, x < a + p},
{(x - p)^2, x >= a + p}}],
{x, -8, 5},
Frame -> True,
Axes -> False,
PlotRange -> {-10, 50},
ImageSize -> 250,
Epilog ->
{Style[
Text[
"a = " <> ToString[a],
{-6, 40}],
Blue, 16],
Style[
Text[
"step = " <> ToString[a (a - 1)],
{-6, 30}],
Blue, 16]}],
{a, 6}],
2]],
{p, -6, -2, Appearance -> "Labeled"}]


Bob Hanlon

---- Vedhas | sahdeV <vedhas(a)gmail.com> wrote:

=============
a = {1 2 3 4 5 6}
The goal is to plot a piecewise function corresponding to each of "a"
values, with manipulate where control variable is p, and the function
for plot y versus x is:
y=x-p for x-p<a, and (x-p)^2 for (x-p)>=a i.e. 6 plots getting
manipulated simultaneously.

I am new to Mathematica and this might be a naive question, but I
couldn't find a solution through help documentation. I will appreciate
if you can help!

Thanks,

Vedhas


From: Nasser M. Abbasi on

"Vedhas | sahdeV" <vedhas(a)gmail.com> wrote in message
news:hlqu4a$gog$1(a)smc.vnet.net...
>a = {1 2 3 4 5 6}
> The goal is to plot a piecewise function corresponding to each of "a"
> values, with manipulate where control variable is p, and the function
> for plot y versus x is:
> y=x-p for x-p<a, and (x-p)^2 for (x-p)>=a i.e. 6 plots getting
> manipulated simultaneously.
>
> I am new to Mathematica and this might be a naive question, but I
> couldn't find a solution through help documentation. I will appreciate
> if you can help!
>
> Thanks,
>
> Vedhas
>

Not sure if this is what you meant

Manipulate[process[a, p, max], {{a, 1, "a"}, 1, 6, 1,
Appearance -> "Labeled"}, {{p, 1, "p"}, 1, 100, 0.1,
Appearance -> "Labeled"}, {{max, 10, "max range"}, 1, 100, 1,
Appearance -> "Labeled"}, FrameMargins -> 0, ImageMargins -> 0,
ContinuousAction -> False, SynchronousUpdating -> False,
Initialization :> {process[a_, p_, max_] :=
Module[{y}, y[x_] := Piecewise[{{x - p, x - p < a},
{(x - p)^2, x - p >= a}}]; Plot[y[x], {x, -max, max},
ImagePadding -> {{5, 1}, {20, 4}}, ImageMargins -> 5,
ImageSize -> 400, AspectRatio -> 0.5]]}]

--Nasser



From: Patrick Scheibe on
Hi,

> for plot y versus x is:
> y=x-p-q for x-p-q<a, and (x-p-q)^2 for (x-p-q)>=a i.e. 6 plots getting
> manipulated simultaneously.

this makes absolutely no sense, because you will have no additional
information. Set k=p+q and you can do the same with only one parameter.
But your original question is easy:

Manipulate[
Plot[Evaluate[
Piecewise[{{x - p - q, x - p - q <= #}}, (x - p - q)^2] & /@
Range[6]], {x, 0, 20}, PlotRange -> {Automatic, {0, 50}}], {p, 0,
20}, {q, 0, 20}]

If you give Plot a list of functions you'll have them all in the same
plot. But I'm pretty sure you expected something different from this
plot.

Cheers
Patrick


> Again, Thanks for your help and I hope you will again respond to the
> query quickly!
>
> Best regards,
>
> Vedhas
>
> On Sun, Feb 21, 2010 at 8:33 AM, Bob Hanlon <hanlonr(a)cox.net> wrote:
>
> If you plot all of the curves on a single plot they will
> overlap and make it difficult to see what is happening.
> Recommend an array of plots.
>
> Manipulate[
> Grid[
> Partition[
> Table[
> Plot[
> Piecewise[{
> {x - p, x < a + p},
> {(x - p)^2, x >= a + p}}],
> {x, -8, 5},
> Frame -> True,
> Axes -> False,
> PlotRange -> {-10, 50},
> ImageSize -> 250,
> Epilog ->
> {Style[
> Text[
> "a = " <> ToString[a],
> {-6, 40}],
> Blue, 16],
> Style[
> Text[
> "step = " <> ToString[a (a - 1)],
> {-6, 30}],
> Blue, 16]}],
> {a, 6}],
> 2]],
> {p, -6, -2, Appearance -> "Labeled"}]
>
>
> Bob Hanlon
>
>
> ---- Vedhas | sahdeV <vedhas(a)gmail.com> wrote:
>
> =============
> a = {1 2 3 4 5 6}
> The goal is to plot a piecewise function corresponding to each
> of "a"
> values, with manipulate where control variable is p, and the
> function
> for plot y versus x is:
> y=x-p for x-p<a, and (x-p)^2 for (x-p)>=a i.e. 6 plots getting
> manipulated simultaneously.
>
> I am new to Mathematica and this might be a naive question,
> but I
> couldn't find a solution through help documentation. I will
> appreciate
> if you can help!
>
> Thanks,
>
> Vedhas
>
>
>