2
$\begingroup$

I'm studying the Ekman spiral for piecewise uniform viscosity. So I have two velocity components (u,v) for every layer. One pair for the surface and one pair for the layer below.

u1[z_] := A*Cos[z/ε] (Exp[z/ε] - Exp[-z/ε]) + B*Sin[z/ε] (Exp[z/ε] + Exp[-z/ε]) + u0*Exp[-z/ε] Cos[z/ε]

v1[z_] := A*Sin[z/ε] (Exp[z/ε] + Exp[-z/ε]) - B*Cos[z/ε] (Exp[z/ε] - Exp[-z/ε]) - u0*Exp[-z/ε] Sin[z/ε]

u2[z_] := Exp[z/(l*ε)] (K*Cos[z/(l*ε)] + L*Sin[z/(l*ε)])

v2[z_] := Exp[z/(l*ε)] (K*Sin[z/(l*ε)] - L*Cos[z/(l*ε)])

A, B, K, L, l, u0 and ε, are constants that I change depending on the occasion I want to study:

A := (ε*(f1 + f2))/(2*r*k1) + u0
B := -(((ε*f2) + (u0*r*k1))/(2*r*k1))
K := 1/(2 k1 r) Exp^(h (1/(l*ε) - 1/ε)) ((2 k1 r u0 + (f1 + f2) ε) Cos[h(1/(l*ε) - 1/ε)] - Exp^((2 h)/ε) (f1 + f2) ε Cos[h (1/(l*ε) + 1/ε)] - (k1 r u0 + f2 ε) (Sin[h (1/(l*ε) - 1/ε)] - Exp^((2 h)/ε) Sin[h (1/(l*ε) + 1/ε)]))
L := 1/(2 k1 r) Exp^(h (1/(l*ε) - 1/ε)) (-(k1 r u0 + f2 ε) Cos[h (1/(l*ε) - 1/ε)] + Exp^((2 h)/ε) (k1 r u0 + f2 ε) Cos[h (1/(l*ε) + 1/ε)] - 2 k1 r u0 Sin[h (1/(l*ε) - 1/ε)] - f1 ε Sin[h (1/(l*ε) - 1/ε)] - f2 ε Sin[h (1/(l*ε) - 1/ε)] + Exp^((2 h)/ε) f1 ε Sin[h (1/(l*ε) + 1/ε)] + Exp^((2 h)/ε) f2 ε Sin[h (1/(l*ε) + 1/ε)])


f := 10^(-4)

u0 := 0.2

f1 := 0.43

f2 := 0.43

k1 := 10^(-2)

k2 := 10^(-3)

ε := Sqrt[2 k1/f]

l := Sqrt[k2/k1]

r := 1027

h := 2

I can plot every layer separately by using the ParametricPlot and ParametricPlot3D comands, for a specific depth and make two seperate spirals.

ParametricPlot[{u1[z], v1[z]}, {z, 0, -2}]
ParametricPlot[{u2[z], v2[z]}, {z, -2, -20}]

What I need to do now, is to merge my two seperate spirals into one spiral. Not to show two different spirals in the same graph though, but one combined spiral-a single curve, that will be built by using the first equations (u1,v1) untill a certain depth (0,-2m) and the other two (u2,v2) below that (-2,-20m). Like a plot of two parametric plots. And i need to show it both in 2D and 3D.

What I practicly have to observe is how the spiral is changing as you move through the layers of diferent viscosities. Is there any way to make it happen?

$\endgroup$
7
  • 3
    $\begingroup$ Graphics can be combined using Show. For any additional advice, edit your question to include your code (InputForm) for a minimal example. $\endgroup$
    – Bob Hanlon
    May 20, 2021 at 15:27
  • $\begingroup$ @BobHanlon First of all thank you for answring! I wasn't so clear probably. What I need to make is to merge my two seperate spirals into one spiral. Not two different spirals in the same graph but one combined spiral-a single curve, that will be using the first equations untill a certain depth and the other two below that. Like a plot of two parametric plots. $\endgroup$ May 21, 2021 at 20:29
  • 1
    $\begingroup$ As stated previously, post code for a minimal example. It is still not clear that Show cannot do what is required. If not, perhaps ConditionalExpression. But without some minimal example we are just guessing -- and many will be unwilling to expend effort if they are just guessing at the problem. $\endgroup$
    – Bob Hanlon
    May 21, 2021 at 20:57
  • $\begingroup$ @BobHanlon thank you for your advice, it's my first time here! Hope now it's more clear! $\endgroup$ May 24, 2021 at 15:21
  • 1
    $\begingroup$ In order to plot your functions you need to provide the values for {A, B, K, l, L, u0, \[CurlyEpsilon]}. Questions should include minimal code and data required to produce results. $\endgroup$
    – Bob Hanlon
    May 24, 2021 at 15:42

1 Answer 1

1
$\begingroup$
Clear["Global`*"]

f = 10^(-4);
u0 = 1/5;
f1 = 43/100;
f2 := 43/100;
k1 = 10^(-2);
k2 = 10^(-3);
ε = Sqrt[2 k1/f];
l = Sqrt[k2/k1];
r = 1027;
h = 2;

A = (ε*(f1 + f2))/(2*r*k1) + u0;

B = -(((ε*f2) + (u0*r*k1))/(2*r*k1)) // Simplify;

Exp^z is incorrect syntax and should be either Exp[z] or E^z

K = 1/(2 k1 r) E^(h (1/(l*ε) - 
         1/ε)) ((2 k1 r u0 + (f1 + f2) ε) Cos[
        h (1/(l*ε) - 1/ε)] - 
      E^((2 h)/ε) (f1 + f2) ε Cos[
        h (1/(l*ε) + 1/ε)] - (k1 r u0 + 
         f2 ε) (Sin[
          h (1/(l*ε) - 1/ε)] - 
         E^((2 h)/ε) Sin[
           h (1/(l*ε) + 1/ε)])) // Simplify;

L = 1/(2 k1 r) E^(h (1/(l*ε) - 
         1/ε)) (-(k1 r u0 + f2 ε) Cos[
        h (1/(l*ε) - 1/ε)] + 
      E^((2 h)/ε) (k1 r u0 + f2 ε) Cos[
        h (1/(l*ε) + 1/ε)] - 
      2 k1 r u0 Sin[h (1/(l*ε) - 1/ε)] - 
      f1 ε Sin[h (1/(l*ε) - 1/ε)] - 
      f2 ε Sin[h (1/(l*ε) - 1/ε)] + 
      E^((2 h)/ε) f1 ε Sin[
        h (1/(l*ε) + 1/ε)] + 
      E^((2 h)/ε) f2 ε Sin[
        h (1/(l*ε) + 1/ε)]) // Simplify;

u1[z_] := 
 A*Cos[z/ε] (Exp[z/ε] - Exp[-z/ε]) +
   B*Sin[z/ε] (Exp[z/ε] + 
     Exp[-z/ε]) + 
  u0*Exp[-z/ε] Cos[z/ε]

v1[z_] := 
 A*Sin[z/ε] (Exp[z/ε] + Exp[-z/ε]) -
   B*Cos[z/ε] (Exp[z/ε] - 
     Exp[-z/ε]) - 
  u0*Exp[-z/ε] Sin[z/ε]

u2[z_] := 
 Exp[z/(l*ε)] (K*Cos[z/(l*ε)] + 
    L*Sin[z/(l*ε)])

v2[z_] := 
 Exp[z/(l*ε)] (K*Sin[z/(l*ε)] - 
    L*Cos[z/(l*ε)])

Using Show

Show[
 ParametricPlot[{u1[z], v1[z]}, {z, 0, -2}],
 ParametricPlot[{u2[z], v2[z]}, {z, -2, -20}],
 PlotRange -> All]

enter image description here

Using Piecewise to define a single function

ParametricPlot[
 Evaluate@Piecewise[{
    {{u1[z], v1[z]}, -2 <= z <= 0},
    {{u2[z], v2[z]}, -20 <= z < -2}}], {z, -20, 0},
 PlotPoints -> 75,
 MaxRecursion -> 5,
 PlotRange -> All,
 ColorFunction -> Function[{x, y, z}, ColorData["Rainbow"][z]],
 PlotLegends -> BarLegend[{"Rainbow", {-20, 0}},
   LegendLabel -> Style[z, 14, Bold]]]

enter image description here

$\endgroup$
2
  • $\begingroup$ If you want to change the parameters use Manipulate $\endgroup$
    – Bob Hanlon
    May 24, 2021 at 23:31
  • $\begingroup$ If you set Exclusions -> None in the Piecewise solution, it generate a single line. Not particularly important in the OP's apparent application, but the purist in me would like a continuous function represented by a continuous Line[]. :) $\endgroup$
    – Michael E2
    Feb 19, 2022 at 1:08

Your Answer

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

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