Ask Your Question

terces907's profile - activity

2020-01-12 21:17:45 +0200 received badge  Famous Question (source)
2019-03-12 21:13:48 +0200 received badge  Famous Question (source)
2016-12-28 00:01:47 +0200 received badge  Notable Question (source)
2015-04-24 19:27:31 +0200 received badge  Popular Question (source)
2014-07-24 23:36:22 +0200 received badge  Famous Question (source)
2014-06-29 21:52:29 +0200 received badge  Notable Question (source)
2014-06-29 21:52:29 +0200 received badge  Popular Question (source)
2014-06-26 16:36:36 +0200 received badge  Notable Question (source)
2014-06-23 10:58:46 +0200 received badge  Popular Question (source)
2014-01-21 11:41:17 +0200 received badge  Student (source)
2014-01-21 11:30:02 +0200 asked a question How to solve Fourier transform problem using Sage?

Find the Fourier transform of the function

 f(x) = { 1, -1 < x < 1
          0, |x| > i }

i. Use Fourier series

ii. Use Fourier integral

How can i use Sage to solve this problem?

2013-10-31 13:59:10 +0200 received badge  Supporter (source)
2013-10-31 13:59:09 +0200 marked best answer Why Sage cannot pass a value of variable from one function to another nested function?
sage: n, k = var('n, k')
sage: f(x,k) = sum((2/n)*(sin(n*x)*(-1)^(n+1)), n, 1, k)
#where n = 1,2,3 ... k
sage: f
(x, k) |--> -2*sum((-1)^n*sin(n*x)/n, n, 1, k)

I'm not sure what you think is wrong here. The 2 and a factor of -1 were both factored out, that's all.

However, I do agree that this doesn't expand. What is happening is that we are sending the sum to Maxima

if algorithm == 'maxima':
    return maxima.sr_sum(expression,v,a,b)

and then ordinarily when it returns, it is still a Maxima object (which may be a bug?). But when we put it in the function, it becomes a Sage object - but we don't have a Sage "sum" object. So I think that is what would have to be fixed.


That this is possible is shown by the following Maxima example (which I put on the ticket):

(%i1) f: -2*'sum((-1)^n*sin(n*x)/n,n,1,2);
                                2
                               ====       n
                               \     (- 1)  sin(n x)
(%o1)                      - 2  >    ---------------
                               /            n
                               ====
                               n = 1

(%i8) f, nouns;
                                 sin(2 x)
(%o8)                       - 2 (-------- - sin(x))
                                    2
2013-10-31 13:58:54 +0200 commented answer Why Sage cannot pass a value of variable from one function to another nested function?

That mean i cannot define the function like that right? It will be very nice if i can define it similar to the second example. it will be consistent with the real equation on my paper.

2013-10-31 13:09:56 +0200 asked a question Why Sage cannot pass a value of variable from one function to another nested function?

The first i ran this:

sage: f(x)=(2/n)*(sin(n*x)*(-1)^(n+1))
sage: sum(f, n, 1, 2) #using summation function
-sin(2*x) + 2*sin(x)

So, In this case the result was evaluated correctly.

But if i tried to combine the first line and the second line together:

sage: f(x,k) = sum((2/n)*(sin(n*x)*(-1)^(n+1)), n, 1, k)
#where n = 1,2,3 ... k
sage: f(x,2)
-2*sum((-1)^n*sin(n*x)/n, n, 1, 2)

The result wasn't finished!

Why sage cannot evaluate mathematical expression in this case?

Another tried to prove that Sage can pass its variable from left function to right function even though the right function was a nested function:

sage: f(x) = sin(arcsin(x)) 
sage: f(0.5)
0.500000000000000

Edit: (See the same question on SO.)

2013-10-30 06:46:35 +0200 received badge  Scholar (source)
2013-10-30 06:46:35 +0200 marked best answer Sage showed "TypeError: need a summation variable" when i used sum function with for loop

Your last line is equivalent to

[sum(f,1,1,20), sum(f,2,1,20)]

For each of these, Sage complains that it doesn't know on which variable to sum on (x or n?).

2013-10-30 05:44:24 +0200 received badge  Editor (source)
2013-10-30 05:43:42 +0200 asked a question Sage showed "TypeError: need a summation variable" when i used sum function with for loop

I try to make a summation list and the commands are below this:

sage: var('n')

sage: var('x')

sage: f = (2/n)*(sin(n*x)*(-1)^(n+1))

sage: funclist = [sum(f,n,1,20) for n in range(1,3)]

but i found an error message:

TypeError: need a summation variable

How to solve this problem?