1
$\begingroup$

I defined a function u[y].

Λ = -30;
u[η_] := (2*η - 2*η^3 + η^4) + Λ / 6*(η - 3*η^2 + 3*η^3 - η^4);
θ = Integrate[u[η]*(1 - u[η]), {η, 0, 1}] // N;
δ = 1/θ;
u[y_] := (2*y/δ - 2*(y/δ)^3 + (y/δ)^4) + Λ/6*((y/δ) - 3*(y/δ)^2 + 3*(y/δ)^3 - (y/δ)^4);

For values y / δ >1 the function has to return u[y] = 1. How to define this condition?

The result of the function for 0 < y < 80 has to be like the image:

enter image description here

$\endgroup$
2
  • $\begingroup$ Check Piecewise or Condition. Note your code is difficult to read and could be much simplified. $\endgroup$
    – anderstood
    Commented Feb 1, 2018 at 16:46
  • $\begingroup$ How can I use greek letters in this forum in order to simplify the read? @anderstood $\endgroup$
    – Mateus
    Commented Feb 1, 2018 at 16:53

2 Answers 2

1
$\begingroup$

Just add the definition (or condition) u[y_ /; y > δ] := 1:

Λ = -30;
u[η_] := (2*η - 2*η^3 + η^4) + Λ/6*(η - 3*η^2 + 3*η^3 - η^4);
θ = Integrate[u[η]*(1 - u[η]), {η, 0, 1}] // N;
δ = 1/θ;
u[y_ /; y > δ] := 1
u[y_] := (2*y/δ -2*(y/δ)^3 + (y/δ)^4) + Λ/6*((y/δ) - 3*(y/δ)^2 + 3*(y/δ)^3 - (y/δ)^4);

Thus:

Plot[u[y], {y, 0, 100}, PlotRange -> All]

enter image description here

You also can use Piecewise function to get the same plot:

u[y_] := Piecewise[{{1, y > δ}}, (2*y/δ - 2*(y/δ)^3 +(y/δ)^4) + Λ/6*((y/δ) - 3*(y/δ)^2 + 
  3*(y/δ)^3 - (y/δ)^4)]
$\endgroup$
5
  • $\begingroup$ This condition will be applied to the derivative of u[y] as well ? $\endgroup$
    – Mateus
    Commented Feb 1, 2018 at 18:06
  • $\begingroup$ you mean that u'[y]=1 for $y>\delta$? $\endgroup$ Commented Feb 1, 2018 at 18:08
  • $\begingroup$ I think if you plot u'[y] it will not consider the condition (y>δ) for u[y]. It will be plot u'[y] based on u[y]without consider the condition for u[y](y>δ). $\endgroup$
    – Mateus
    Commented Feb 1, 2018 at 18:14
  • $\begingroup$ Yes, in that case, I suggest you use the definition via Piecewise $\endgroup$ Commented Feb 1, 2018 at 18:28
  • $\begingroup$ Perfect! Thank you! $\endgroup$
    – Mateus
    Commented Feb 1, 2018 at 18:47
1
$\begingroup$
u2[y_] := u[Clip[y, {-∞, δ}]]
Plot[u2[y], {y, 0, 100}, PlotRange -> All]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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