Optimize Your Mathematica Code with These Helpful Tips and Tricks

  • Context: Mathematica 
  • Thread starter Thread starter sylphid707
  • Start date Start date
  • Tags Tags
    Code Mathematica
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
sylphid707
Messages
1
Reaction score
0
First of all, this might give seasoned Mathematica users some serious eye sores cause I'm a newb at this xD

f[x_] := (1^-9) (Exp[38.629 x] - 1);
data = Table[if[[f[x], {x, -5, 5, 0.01}] > 0.005, 0.005, f[x]]];
ListPlot [data, DataRange -> {-5, 5}, Joined -> True,
PlotRange -> {0, 0.01}, PlotStyle -> {Thickness[0.005]}]


What I want to do this is do a plot of a sweep from -5 to 5 with 0.01 stepsize, and if the output value exceeds 0.005, the output value will just be 0.005. It will kind of look like a heavyside step function/unit step function.
Any help would be greatly appreciated xD.
 
Physics news on Phys.org
You mean something like this?

f[x_] := (1^-9) (Exp[38.629 x] - 1);
data = Table[{x, If[f[x] > 0.005, 0.005, f[x]]}, {x, -5, 5, 0.01}];
ListPlot[data, PlotJoined -> True, PlotRange -> {0, 0.01}, PlotStyle -> {
Thickness[0.005]}]