Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13264 > unrolled thread

something wrong with my code??

Started bysylphid707 <sylphid707@hotmail.com>
First post2013-01-25 06:34 +0000
Last post2013-01-26 06:38 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  something wrong with my code?? sylphid707 <sylphid707@hotmail.com> - 2013-01-25 06:34 +0000
    Re: something wrong with my code?? Chris Degnen <degnen@cwgsy.net> - 2013-01-26 06:38 +0000

#13264 — something wrong with my code??

Fromsylphid707 <sylphid707@hotmail.com>
Date2013-01-25 06:34 +0000
Subjectsomething wrong with my code??
Message-ID<kdt90p$994$1@smc.vnet.net>
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.

[toc] | [next] | [standalone]


#13282

FromChris Degnen <degnen@cwgsy.net>
Date2013-01-26 06:38 +0000
Message-ID<kdvtlk$fpo$1@smc.vnet.net>
In reply to#13264
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]}]


[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web