New Reply

adding many functions in mathematica

 
Share Thread
Jun13-11, 10:52 PM   #1
 

adding many functions in mathematica


Hello. Can someone tell me what I can do to the following code fragment:

sigma = {2,4,6,8}
mu = {1,3,5,7}
gauss[x_, mu_, sigma_] = (1/(2*\[Pi] * sigma^2))*
E^-((x - mu)^2/(2*sigma^2))
lorentz[x_, m_, gamma_] = 1/(\[Pi]*gamma*(1 + ((x - m)/gamma)^2))
spec1 = Apply[Plus, gauss[x, mu, sigma]]
spec2 = Apply[Plus, lorentz[x, mu, sigma]]

spec1 and spec 2 correctly appear as sums of multiple terms, but I cannot plot either as a function of x. Where have I gone wrong?

thanks for any help
PhysOrg.com science news on PhysOrg.com

>> New language discovery reveals linguistic insights
>> US official: Solar plane to help ground energy use (Update)
>> Four microphones, computer algorithm enough to produce 3-D model of simple, convex room
Jun14-11, 12:56 AM   #2
 
The following quick fix will work:

sigma = {2, 4, 6, 8};
mu = {1, 3, 5, 7};

gauss[x_, mu_, sigma_] := E^(-(x - mu)^2/(2*sigma^2))/(2*Pi*sigma^2)
lorentz[x_, m_, gamma_] := 1/(Pi*gamma*(1 + ((x - m)/gamma)^2))

spec1[x_] := Total[gauss[x, mu, sigma]]
spec2[x_] := Total[lorentz[x, mu, sigma]]

Plot[{spec1[x], spec2[x]}, {x, -10, 10}]
Jun14-11, 07:56 AM   #3
 
that works for me. I probably should get better acquainted with that "Apply" operator. Thanks for your help.
New Reply

Tags
mathematica 8

Similar discussions for: adding many functions in mathematica
Thread Forum Replies
adding sine functions General Math 9
MathOO: Adding Object Orientation to Mathematica Math & Science Software 0
Adding cosine functions Precalculus Mathematics Homework 2
Adding two complex functions? Calculus & Beyond Homework 5
Adding Two Wave Functions Introductory Physics Homework 0