Message Boards Message Boards

How can I include a parameter in ListPlot?

Posted 10 years ago

How can I include in my following ListPlot command that I want theta to have the values 0, 22.5, 45, 67.5 and 90?

Ks[theta_?NumericQ]:=Table[{A,NIntegrate[x f2[A,x],{x,0,1}]},{A,{0,0.05,0.15,0.25,6}}];
ListPlot[Re[Ks],Joined->True,PlotRange->{{0,6},{-0.2,0.8}},Frame->True]

I basically want to plot the result of a numerical integration where x axis is A and y axis is Ks(A) for these 5 theta parameter values, meaning I want to have five lines in the plot.

To define f2 I have used this code http://mathematica.stackexchange.com/questions/11594/integral-equation-numerical-solution-with-ndsolve. My complete algorithm is:

Options[FredholmKind2]={Method->Automatic};
FredholmKind2[{a_,b_,lambda_,k_,g_},n_?IntegerQ,OptionsPattern[]]:=Block[{step,SI,GI,KMatrix,W,DMatrix,f,deltaX,delta},step=(b-a)/n;
  SI=Range[a,b,step];
  GI=g/@SI;
  KMatrix=Outer[k,SI,SI];
  W={step/2}~Join~ConstantArray[step,n-1]~Join~{step/2};
  DMatrix=DiagonalMatrix[W];
  f=If[OptionValue[Method]===NIntegrate,deltaX[x_?NumericQ]:=W.(k[x,#]&/@SI)-NIntegrate[k[x,y],{y,a,b}];
    delta=deltaX/@SI;
    Interpolation[Transpose@{SI,LinearSolve[IdentityMatrix[n+1]+lambda*(DiagonalMatrix[delta]-KMatrix.DMatrix),GI]}],
    Interpolation[Transpose@{SI,LinearSolve[IdentityMatrix[n+1]-lambda*(KMatrix.DMatrix), I]}]];
  f]

n=50;
a=0.;
b=1.;
lambda=-1.;
Kpart[A_?NumericQ][x_,y_]:=(A/2)*(BesselJ[1,A*(x+y)]-BesselJ[1,A*Abs[x-y]]-I*StruveH[1, A*(x+y)]+I*StruveH[1,A*Abs[x-y]]);
Gpart[A_?NumericQ,theta_?NumericQ][x_]:=Sin[x A Cos[theta Degree] Degree]/(A Cos[theta Degree]);
f2[A_?NumericQ,x_?NumericQ]:=FredholmKind2[{a,b,lambda,Kpart[A],Gpart}, n,Method->Automatic][x];
Ks=Table[{A,NIntegrate[x f2[A,x],{x,0,1}]},{A,0,6,.1}];
ListPlot[Re[Ks],Joined->True,PlotRange->{{0,6},{-0.2,0.8}},Frame -> True]
POSTED BY: user E

You have theta as an argument for the function Ks but I don't see it referenced in the function's definition.

If all you want to do is to plot the function for different values of th (theta) then something like this would work,

ListPlot[Table[f[th],{th,{0, 22.5, 45, 67.5, 90}}],Joined->True,PlotRange->{{a,b},{c,d}},Framed->True]

f[th] will be a function that produces a discrete set of points for each value of th.

POSTED BY: Douglas Skinner
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