From: Vedhas Pandit on
That helped so far as syntax is concerned!

Please note that I need to use elements of array a, a is an array is
predefined with some random numbers, say a={0 7 2 1 4}. (I cannot use range,
I need to use the "data" I have with me).

a = {0 7 2 1 4};
Manipulate[
Plot[Evaluate[
Piecewise[{{x - p - q, x - p - q <= a}}, (x - p - q)^2]], {x, 0,
20}, PlotRange -> {Automatic, {0, 50}}], {p, 0, 20}, {q, 0, 20}]
didn't work

Thanks,

Vedhas


On Tue, Feb 23, 2010 at 3:54 PM, Patrick Scheibe <
pscheibe(a)trm.uni-leipzig.de> wrote:

> 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
> >
> >
> >
>
>
From: Patrick Scheibe on
Hi,

I thought it was clear that Range[blub] is a list which you have to
substitute by whatever you want:

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

See where your "a" goes? You have to try to follow every step to
understand and to get better! So try to understande the core which is

Piecewise[{{x - p - q, x - p - q <= #}}, (x - p - q)^2] & /@ a

What is the # and the &? What is /@? Why and how does it work?
You only have to read the examples in the documentation and maybe the
doc itself.

Cheers
Patrick



On Tue, 2010-02-23 at 16:53 -0700, Vedhas Pandit wrote:
> That helped so far as syntax is concerned!
>
> Please note that I need to use elements of array a, a is an array is
> predefined with some random numbers, say a={0 7 2 1 4}. (I cannot use
> range, I need to use the "data" I have with me).
>
> a = {0 7 2 1 4};
> Manipulate[
> Plot[Evaluate[
> Piecewise[{{x - p - q, x - p - q <= a}}, (x - p - q)^2]], {x, 0,
> 20}, PlotRange -> {Automatic, {0, 50}}], {p, 0, 20}, {q, 0, 20}]
> didn't work
>
> Thanks,
>
> Vedhas
>
>
> On Tue, Feb 23, 2010 at 3:54 PM, Patrick Scheibe
> <pscheibe(a)trm.uni-leipzig.de> wrote:
> 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
> >
> >
> >
>
>
>


From: Bob Hanlon on

You can interconnect the controls to avoid cases where everything is off the graph.

Also the Exclusions option can be used if you want the vertical lines to show.

a = {0, 7, 2, 1, 4};
Manipulate[
Plot[
Evaluate[
Piecewise[
{{x - p - q, x - p - q <= #}},
(x - p - q)^2] & /@ a],
{x, 0, 20},
PlotRange -> {Automatic, {-1, 51}},
Exclusions -> p + q],
{p, 0, 20 - q, 0.1, Appearance -> "Labeled"},
{q, 0, 20 - p, 0.1, Appearance -> "Labeled"}]


Bob Hanlon

---- Patrick Scheibe <pscheibe(a)trm.uni-leipzig.de> wrote:

=============
Hi,

I thought it was clear that Range[blub] is a list which you have to
substitute by whatever you want:

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

See where your "a" goes? You have to try to follow every step to
understand and to get better! So try to understande the core which is

Piecewise[{{x - p - q, x - p - q <= #}}, (x - p - q)^2] & /@ a

What is the # and the &? What is /@? Why and how does it work?
You only have to read the examples in the documentation and maybe the
doc itself.

Cheers
Patrick



On Tue, 2010-02-23 at 16:53 -0700, Vedhas Pandit wrote:
> That helped so far as syntax is concerned!
>
> Please note that I need to use elements of array a, a is an array is
> predefined with some random numbers, say a={0 7 2 1 4}. (I cannot use
> range, I need to use the "data" I have with me).
>
> a = {0 7 2 1 4};
> Manipulate[
> Plot[Evaluate[
> Piecewise[{{x - p - q, x - p - q <= a}}, (x - p - q)^2]], {x, 0,
> 20}, PlotRange -> {Automatic, {0, 50}}], {p, 0, 20}, {q, 0, 20}]
> didn't work
>
> Thanks,
>
> Vedhas
>
>
> On Tue, Feb 23, 2010 at 3:54 PM, Patrick Scheibe
> <pscheibe(a)trm.uni-leipzig.de> wrote:
> 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



From: Vedhas Pandit on
Thanks Bob and Patrick!

I agree with you using array of plots, but I "need" to put all the 6 curves
in the same plot window. Can you help me do that?

(Analyzing the curves might then be tricky, but piecewise (x-p) and (x-p)^2
is only an example function, actual piecewise function that I am trying to
plot is different, having many control variables to manipulate. I only need
to know the syntax so the query (adding one more control variable q if that
changes anything): )

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,q , and the function
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.

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
>
>