Message Boards Message Boards

0
|
7065 Views
|
19 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Unevaluated Sum of a sequence

Posted 8 years ago

How can I get mathematica to write out a sum without evaluating it immediately eg

Sum[3^i,{i,1,10}]  

I want to get the following first 3^1+3^2+3^3+.....3^10 without having to input each term separately.

POSTED BY: Ray Lawicki
19 Replies

You can try this way:

Inactive[Plus] @@ 
 Table[Inactive[Power][3, 
   i], {i, {1, 2, 3, \[CenterEllipsis], i, \[CenterEllipsis], 100}}]
POSTED BY: Gianluca Gorni

Returning to the original question—and letting the sum run from 1 to 100 to give a result where you would indeed want an ellipsis (dots) rather than the whole sum&mdash: This sort of thing is nicely handled by the EllipsisSequences package that is just one small part of David Park's Presentationa application:

     <<Presentations`
     iSum[Inactivate[3^i], {i, 1, 2, 3, , i, , 100}]
3^1 + 3^2 + 3^3 + ... + 3^i + ... + 3^100

Although Park has offered a no-cost version of Presentations without the documentation as well as the complete application with documentation, unfortunately at present the link to his web page on that seems dead.

POSTED BY: Murray Eisenberg

I think there is no built-in function for exactly the thing you need. The closest is AbsArg. You can build the exponential from there:

AbsArg[2 - 2 I] /. {r_, t_} :> r*Exp[I*t]
Abs[2 - 2 I] Exp[I*Arg[2 - 2 I]]

You can define your own function:

ConvertToExponential[z_] := Abs[z] Exp[I*Arg[z]]
POSTED BY: Gianluca Gorni
Posted 8 years ago

I am having some problem with complex number as shown in the attached file. ray

Attachments:
POSTED BY: Ray Lawicki
Posted 8 years ago

Unevaluated Sum of a sequence

POSTED BY: Till Luc Lange
Posted 8 years ago

You could write

f[x_] := x^2 - x + 3;
Plot[#[[2]], {x, -6, 6}, PlotRange -> 15,    PlotStyle -> #[[1]]] 
& /@ {{Red, f[x]}, {Green, f[2 x]}, {Blue,    f[x - 2]}, {Orange, -2 f[x]}}

as well, if you prefer to use /@ instead @@@. /@ is the shortcut for Map[ ] and applies the function to each element of first level in the list. Here each of these elements will be a list again such as{Red, f[x]}.

By the way: Simply writing #1 and #2 won't be succesfull. You need the subscription given by the brackets [[ ]].

POSTED BY: Till Luc Lange
Posted 8 years ago

thank you for your suggestion ray.

POSTED BY: Ray Lawicki

The operators @@ and @@@ are shorthands for two forms of Apply, which is a structural manipulation function. They work on the special way Mathematica expressions are built: they are of the form h[x,y,...], where h is the "head" of the expression. The function Apply replaces the heads of expressions with other heads:

f@@h[x,y,...] gives f[x,y,...] (top level replacement)

f@@@h[g[x],g[y],...] gives h[ f[x], f[y],...] (lower level replacement)

The & operator indicates that what comes before it is a "pure function", whose arguments are indicated with #, or #1,#2,...

It is not uncommon to find & immediately followed by @@ or @@@, but they are distinct objects.

POSTED BY: Gianluca Gorni

The command Table[Inactive[Factorial][i]^i, {i, 10}] produces a List[ 1!, 2!, ...]. What I want is Plus[ 1!, 2!, ...]. The prefix Plus@@ does precisely that: it replaces List with Plus.

POSTED BY: Gianluca Gorni
Posted 8 years ago

thanks I understand the use of@@ ray

POSTED BY: Ray Lawicki
Posted 8 years ago

MY MATHEMATICA IS VERSION 10.0 AND IT DOES WORK FINE BECAUSE I JUST REALISED THAT I WAS USING && RATHER THAN @@ SO THANKS AGAIN. Can you explain how that code works as I don't understand the use of @@ in the line and why I cannot use I! rather the the word factorial. Also I am trying to plot a series of separate graphs in different colour but my code is not working correctly eg I define f(x)=x^2-x+3 (say) ,then Table[Plot[f,{x,-6,6},PlotRange->10],{f,[f(x],f[2x],f[x-2],-2f{x]}}] which produces a table of the graphs but if I now include PlotStyle->{Red,Green,Blue,Orange} I get no graphs.
ray.

POSTED BY: Ray Lawicki
Posted 8 years ago

This seem to work

f[x_]:=x^2-x+3;
Plot[#2,{x,-6,6},PlotRange->10,PlotStyle->#1]&@@@{{Red,f[x]},{Green,f[2 x]},{Blue,f[x-2]},{Orange,-2f[x]}}
POSTED BY: Till Luc Lange
Posted 8 years ago

thanks it does work but I do not understand the following bits of the code #2 what does this do and &@@@ what does this mean and why do we have #1 in plotstyle? being only a beginner I some times do not understand the effect of the above. ray.

POSTED BY: Ray Lawicki

The plus signs show up fine on my system (Mma version 10.3.1). What version are you on?

Attachments:
POSTED BY: Gianluca Gorni
Plus @@ Table[Inactive[Factorial][i]^i, {i, 10}]
POSTED BY: Gianluca Gorni
Posted 8 years ago

thanks for the hint however it does not produce + signs between the elements ,what I wanted was an output as ( 1!)^1+(2!)^2+(3!)^3+(4!)^4..... help ray

POSTED BY: Ray Lawicki
Posted 8 years ago

THANKS,for the response but can I have the following Sum[Superscript[I!, 2], {i, 1, 5}] write out the sequence as a factorial first. , because it responds with1^2+2^2+6^2+24^2+120^2 rather than ( 1!)^2+(2!)^2+(3!)^2+....

POSTED BY: Ray Lawicki

@Gianluca Gorni you could simplify your version to

Sum[Inactive[Power][3, i], {i, 1, 10}]

If @RAY LAWICKI wants nice typesetting this could work:

Sum[Superscript[3, i], {i, 1, 10}]

with further evaluation triggered as

% /. Superscript -> Power
POSTED BY: Vitaliy Kaurov

A first attempt:

Inactive[Plus] @@ Table[Inactive[Power][3, i], {i, 10}]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract