1
$\begingroup$

I want to plot the following function with different values of the parameter $b$:

 a = -0.1 Sqrt[0.001^2 + b^2];

 M[t_] := NIntegrate[10w E^(-w/50)((1-Cos[(w+a)t])/(w+a)^2),{w,0,-a,∞}, 
 MaxRecursion -> 100, AccuracyGoal -> 10, Method -> "PrincipalValue"]

 Plot[M[t],{t,0,1000}]

How can I code different plots for different values of parameter $b$ in a single plot?

Note: My actual code is pretty bigger than this. So I cannot define a new series of variables and functions for each value of the parameter and then plot them simultaneously.

$\endgroup$
  • 1
    $\begingroup$ M[t_, b_] := With[{a = -0.1 Sqrt[0.001^2 + b^2]}, (* stuff *)], then use Table[] within Plot[]. $\endgroup$ – J. M. is away Jul 29 '16 at 6:06
  • $\begingroup$ @J.M Thanks man. But can you elaborate on that? $\endgroup$ – Farhad Jul 29 '16 at 6:30
3
$\begingroup$

Following J.M.'s comment (his credit)

M[t_, b_] :=  With[{a = -0.1 Sqrt[0.001^2 + b^2]}, 
  NIntegrate[10 w E^(-w/50) ((1 - Cos[(w + a) t])/(w + a)^2), {w, 
    0, -a, ∞}, MaxRecursion -> 100, AccuracyGoal -> 10, 
   Method -> "PrincipalValue"]]

Then

 Plot[ Table[M[t, b], {b, 1, 2}]//Evaluate, {t, 0, 1}]

Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ Suggest you put Evaluate round the table to see the curves in different colours $\endgroup$ – mikado Jul 29 '16 at 8:06
  • $\begingroup$ its done thanks! $\endgroup$ – chris Jul 29 '16 at 8:17
0
$\begingroup$

Check this formalism. It works.

mList = {1, 3, 4, 6};

Plot[Table[m x, {m, mList}] // Evaluate, {x, 0, 10}, 
PlotLegends -> mList]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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