Message Boards Message Boards

Plot a stream function?

Posted 7 years ago

Hi, I have problem to plot this equation

\[Psi](y,z)=( k[y]' z^2 (k[y]-z))/(8k[y] );
 where
k[y]'=Sqrt[(1-k[y]/p)(1-k[y] p Cos[\[Alpha]]- k[y] Log[k[y]/p])]

and I am expected to get this kind of graph

enter image description here

I get k[y] from this

f[k_?NumericQ]:=p*NIntegrate[1/Sqrt[(1-t)(1-t p^2 Cos[\[Alpha]])-3 M p t Log[t]],{t,k/p,1}]
ky=FindRoot[y==f[k],{k,0}];
Table[{y,ky[[1,2]]},{y,0,a1+\[Delta],\[Delta]}]//N

where
p=1.57516;a1=1.7824;

Can anyone help me with this problem? Thanks in advance!

POSTED BY: Nurul Ainina
3 Replies

You can use Interpolation:

k = Interpolation[
   Chop[{{0., 1.57516 + 0. I}, {0.05, 
      1.57289 + 2.44473*10^-16 I}, {0.1, 
      1.56608 - 5.15215*10^-17 I}, {0.15, 
      1.55475 + 3.28431*10^-14 I}, {0.2, 
      1.53893 - 1.5182*10^-13 I}, {0.25, 
      1.51865 - 2.71443*10^-15 I}, {0.3, 
      1.49396 + 2.74854*10^-16 I}, {0.35, 1.46494}, {0.4, 
      1.43164}, {0.45, 1.39415}, {0.5, 1.35259}, {0.55, 
      1.30705}, {0.6, 1.25767}, {0.65, 1.20459}, {0.7, 
      1.14797}, {0.75, 1.088}, {0.8, 1.02488}, {0.85, 0.958821}, {0.9,
       0.890087}, {0.95, 0.818952}, {1., 0.74573}, {1.05, 
      0.670772}, {1.1, 0.594476}, {1.15, 0.517297}, {1.2, 
      0.439757}, {1.25, 0.362468}, {1.3, 0.286157}, {1.35, 
      0.211719}, {1.4, 0.140297}, {1.45, 0.073469}, {1.5, 
      0.0138314}, {1.55, -0.0326749 + 
       1.68698*10^-15 I}, {1.6, -0.0692389 - 
       3.06896*10^-15 I}, {1.65, -0.136826 - 
       1.66952*10^-15 I}, {1.7, -0.186826 - 
       2.87141*10^-15 I}, {1.75, -0.236826 - 
       2.16633*10^-15 I}, {1.8, -0.286826 - 3.02064*10^-15 I}}]];
Plot[k[y], {y, 0, 1.8}]
POSTED BY: Gianluca Gorni

Dear Nurui,

this is a bit difficult to answer like this. The code fragments are too buggy and it is hard to see what exactly you want to achieve. Here are some observations:

  1. You do not stick to Mathematica's syntax, I suppose.
  2. For example you "define"

    \[Psi](y,z)=( k[y]' z^2 (k[y]-z))/(8k[y] );
    

which I assume is supposed to be a function of y and z. The thing is that functions should have the arguments in square brackets. Also Phi does not appear to be used anywhere in the code that follows. 3. What do you want to achieve with this line:

k[y]'=Sqrt[(1-k[y]/p)(1-k[y] p Cos[\[Alpha]]- k[y] Log[k[y]/p])]

k[y] seems to be the derivative of a function. You do not define it with a delayed assignment (:=), and you never ask Mathematica to solve that ODE. I do not think that this way of defining Psi will/should work.

  1. You do not define all parameters. You use numerical integration but do not define. e.g. Alpha.

  2. I suppose that ky would need to break defined in a delayed way (:=), because it cannot be solved numerically before you give it the value of y, which is a line later.

  3. You code does not appear to be meant to run as you define parameters after everything. You should aim at posting code that at least has an order to it.

  4. Independent variables in functions should also be defined with an underscore.

I think that all in all, you will have to work your way through a book with syntax of the Wolfram Language.

Here, construct the function psi "by foot". First I need to solve for k[y].

sol = NDSolveValue[{D[k[y], y] == Sqrt[(1 - k[y]/p) (1 - k[y] p Cos[\[Alpha]] - k[y] Log[k[y]/p])],k[0] == 0.1} /. {\[Alpha] -> 0/10., p -> 1.57516, a1 -> 1.7824, \[Alpha] -> 2 Pi}, k, {y, 0, 10}]

Now, I can define Psi.

\[Psi][y_, z_] := Re[(Sqrt[(1 - sol[y]/p) (1 - sol[y] p Cos[\[Alpha]] - sol[y] Log[sol[y]/p])] z^2 (sol[y] - z))/(8 sol[y]) /. {p -> 1.57516, a1 -> 1.7824, \[Alpha] -> 0.0}];

You can plot that function like so:

ContourPlot[\[Psi][y, z] /. {p -> 1.57516, a1 -> 1.7824, \[Alpha] -> 0.0}, {y, 0, 1.8}, {z, 0, 15}, PlotPoints -> 50]

enter image description here

I don't think that this is what you want. Also, I don't have the parameters that I need to generate your image. I hope this gives you some starting point.

Cheers,

Marco

POSTED BY: Marco Thiel
Posted 7 years ago

Dear Marco,

Thank you very much for your advice. I have followed them and I still have few to ask.

If I get k[y] from this,

p = 1.57516; a1 = 1.7824; \[Alpha] = 1/2 Pi;

f[k_?NumericQ] := 
 p*NIntegrate[
   1/Sqrt[(1 - t) (1 - t p^2 Cos[\[Alpha]]) - 3  p t Log[t]], {t, k/p,
     1}]
ky = FindRoot[y == f[k], {k, 0}];
Table[{y, ky[[1, 2]]}, {y, 0, a1 + \[Delta], \[Delta]}] // N

and I will get this

{{0., 1.57516 + 0. I}, {0.05, 1.57289 + 2.44473*10^-16 I}, {0.1, 
  1.56608 - 5.15215*10^-17 I}, {0.15, 
  1.55475 + 3.28431*10^-14 I}, {0.2, 
  1.53893 - 1.5182*10^-13 I}, {0.25, 
  1.51865 - 2.71443*10^-15 I}, {0.3, 
  1.49396 + 2.74854*10^-16 I}, {0.35, 1.46494}, {0.4, 1.43164}, {0.45,
   1.39415}, {0.5, 1.35259}, {0.55, 1.30705}, {0.6, 1.25767}, {0.65, 
  1.20459}, {0.7, 1.14797}, {0.75, 1.088}, {0.8, 1.02488}, {0.85, 
  0.958821}, {0.9, 0.890087}, {0.95, 0.818952}, {1., 0.74573}, {1.05, 
  0.670772}, {1.1, 0.594476}, {1.15, 0.517297}, {1.2, 
  0.439757}, {1.25, 0.362468}, {1.3, 0.286157}, {1.35, 
  0.211719}, {1.4, 0.140297}, {1.45, 0.073469}, {1.5, 
  0.0138314}, {1.55, -0.0326749 + 
   1.68698*10^-15 I}, {1.6, -0.0692389 - 
   3.06896*10^-15 I}, {1.65, -0.136826 - 
   1.66952*10^-15 I}, {1.7, -0.186826 - 
   2.87141*10^-15 I}, {1.75, -0.236826 - 
   2.16633*10^-15 I}, {1.8, -0.286826 - 3.02064*10^-15 I}}

I suppose that the ky[[1, 2]]as k[y] will be used in the stream function

\[Psi][y_, z_] := ( 
  Sqrt[(1 - k[y]/p) (1 - k[y] p Cos[\[Alpha]] - k[y] Log[k[y]/p])]
    z^2 (k[y] - z))/(8 k[y] );

but I have problem to apply it. Do you have any suggestion how can I extract the ky[[1, 2]] to be k[y]? Thanks in advance :D

POSTED BY: Nurul Ainina
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract