3
$\begingroup$

I have the following two expressions:

v1[z]=(39 z^2)/160 - (23 z^3)/480

and

v2[z]=47/240 - (131 z)/480 + (17 z^3)/480 + z^4/24

I would like to calculate both for z that goes from 0 to 1, but I would like to plot both consecutively, i.e., v1[z] from 0 to 1 and v2[z] from 1 to 2 but evaluated from 0 to 1. How can I do this? Thanks

$\endgroup$
3
$\begingroup$

One way is to join the two functions together into a single Piecewise function:

v1[z_] := (39 z^2)/160 - (23 z^3)/480;
v2[z_] := 47/240 - (131 z)/480 + (17 z^3)/480 + z^4/24;
v[z_] := Piecewise[{{v1[z], 0 <= z <= 1}, {v2[z - 1], 1 <= z <= 2}}]
Plot[v[z], {z, 0, 2}]

enter image description here

Alternatively, you could use UnitBoxes to join the two functions:

v[z_] := v1[z] UnitBox[z - 1/2] + v2[z - 1] UnitBox[z - 3/2];
|improve this answer|||||
$\endgroup$
3
$\begingroup$

You can also wrap v1 and v2 with ConditionalExpression:

v1[z_] := (39 z^2)/160 - (23 z^3)/480
v2[z_] := 47/240 - (131 z)/480 + (17 z^3)/480 + z^4/24

Plot[{ConditionalExpression[v1[z], 0 <= z <= 1], 
  ConditionalExpression[v2[z - 1], 1 <= z <= 2]}, {z, 0, 2}, 
 PlotLegends -> "Expressions"]

enter image description here

You can also Translate the primitives of the second plot and combine the two plots using Show:

{plot1, plot2} = Plot[#[z], {z, 0, 1}] & /@ {v1, v2};
Show[plot1, Graphics@Translate[First@plot2, {1, 0}], PlotRange -> All]

enter image description here

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.