Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: something wrong with my code??
Replies: 2   Last Post: Jan 26, 2013 1:38 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Chris Degnen

Posts: 125
Registered: 3/5/08
Re: something wrong with my code??
Posted: Jan 26, 2013 1:38 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 25 Jan, 06:34, sylphid707 <sylphid...@hotmail.com> wrote:
> 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.



This method uses ReplaceAll to avoid recomputing f[x]:-

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

And this method maps the if condition, also avoiding recomputing
f[x]:-

f[x_] := (1^-9) (Exp[38.629 x] - 1);
data = If[# > 0.005, 0.005, #] & /@ Table[f[x], {x, -5, 5, 0.01}];
ListLinePlot[data, DataRange -> {-5, 5}, PlotRange -> {0, 0.01},
PlotStyle -> {Thickness[0.005]}]






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.