Message Boards Message Boards

0
|
4770 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Plotting multiple functions on the same axes using Evaluate@Map

Posted 9 years ago

Hello all,

I am trying to understand what I am getting wrong in trying to plot a function using a few different parameters with Map. Example code is below, I am trying to plot the numerical integral of my function over the same x range, with a different extra parameter, I have a working method (right.png) for Plot[] using Evaluated->True, but this is not portable to e.g LogLinearPlot[] so I am trying to use Evaluate@Map instead, and this is where things go wrong.

f[x_, k_, a_] := Sqrt[1 + a Sin[k x]]/(
 1 + (k Cos[k x])/(1 + a Sin[k x]))
colors = (("DefaultPlotStyle" /. (Method /. 
        Charting`ResolvePlotTheme["Default", ListLinePlot])) /. 
    Directive[x_, __] :> x);
Plot[Evaluate@
  Map[NIntegrate[f[x, 2 \[Pi]/l, #], {x, 0, l}]/l &, {0.05, 0.1, 
    0.2}], {l, 10*^-6, 10*^-3}, PlotStyle -> colors, Frame -> True, 
 FrameLabel -> {"\!\(\*SubscriptBox[\(\[Lambda]\), \(ri\)]\)", 
   "<\!\(\*SubscriptBox[\(\[Beta]\), \(ph\)]\)>", 
   "Variation of average wake velocity with ripple wavelength"}, 
 PlotLegends -> LineLegend[colors, {"a=0.05", "a=0.1", "a=0.02"}]]

Obviously I am not understanding fully how evaluation works because I am not getting the results I expect (wrong.png), I just get three flat lines, as if the first data point has been mapped to all the x values in the domain. Can someone help me out here please?

Matthew

P.S This is what I am aiming at with (working) code for Plot[]:

f[x_, k_, a_] := Sqrt[1 + a Sin[k x]]/(
 1 + (k Cos[k x])/(1 + a Sin[k x]))
colors = (("DefaultPlotStyle" /. (Method /. 
        Charting`ResolvePlotTheme["Default", ListLinePlot])) /. 
    Directive[x_, __] :> x);
Plot[Map[NIntegrate[f[x, 2 \[Pi]/l, #], {x, 0, l}]/l &, {0.05, 0.1, 
   0.2}], {l, 10*^-6, 10*^-3}, PlotStyle -> colors, Frame -> True, 
 Evaluated -> True, 
 FrameLabel -> {"\!\(\*SubscriptBox[\(\[Lambda]\), \(ri\)]\)", 
   "<\!\(\*SubscriptBox[\(\[Beta]\), \(ph\)]\)>", 
   "Variation of average wake velocity with ripple wavelength"}, 
 PlotLegends -> LineLegend[colors, {"a=0.05", "a=0.1", "a=0.02"}]]
Attachments:
POSTED BY: Matthew Tooley
2 Replies
POSTED BY: David Reiss
POSTED BY: David Reiss
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