Post Reply 
Classic Fourier Series
01-31-2015, 09:11 PM (This post was last modified: 01-31-2015 09:17 PM by Snorre.)
Post: #11
RE: Classic Fourier Series
Hello Salvo,

a program is always a good idea ;-)

Just two tips:

1st:
You should take care of the argument types your program expects.
Your code seems to expect fun to be an expression (not a function) with t (and only t) being the independent variable, so the typical usage looks like:
fourcoeff(t²,1) or
f(x):=x² and fourcoeff(f(t),1).
By that you have to always remember that fun must be an expression of t. And furthermore, t must not be defined already.
If you change your program slightly by
Code:
...
a0:=int(fun(t),t,0,2*PI)/(2*PI);
ak:=int(fun(t)*cos(k*t),t,0,2*PI)/PI;
bk:=int(fun(t)*sin(k*t),t,0,2*PI)/PI;
...
it'll expect fun to be a function (not an expression) of arity 1. The advantage of this approach is: it doesn't matter how you name the independent variable since your program will replace it by the local t anyway which is totally independent of any global t already defined. That is, you could do something like: t:=["foo","bar"] and g(x):=x² and fourcoeff(g,1).

2nd:
Your program returns a sequence (an object similiar to those created by the builtin seq function), not a vector/list.
That is totally OK as long as it was your intention. Just be aware that sequences behave quite differently when used in further calculations, for example 0+fourcoeff(...) vs. 0+[fourcoeff(...)].
If you want your program to return a vector or list, put the last expression return a0,ak,bk; within brackets or braces: return [a0,ak,bk]; or return {a0,ak,bk};.

Greetings
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Classic Fourier Series - salvomic - 01-27-2015, 07:15 PM
RE: Classic Fourier Series - Snorre - 01-30-2015, 05:20 PM
RE: Classic Fourier Series - salvomic - 01-30-2015, 06:07 PM
RE: Classic Fourier Series - salvomic - 01-30-2015, 06:48 PM
RE: Classic Fourier Series - Han - 01-30-2015, 07:23 PM
RE: Classic Fourier Series - salvomic - 01-30-2015, 07:32 PM
RE: Classic Fourier Series - Han - 01-30-2015, 07:54 PM
RE: Classic Fourier Series - salvomic - 01-30-2015, 09:06 PM
RE: Classic Fourier Series - Han - 01-31-2015, 12:05 AM
RE: Classic Fourier Series - salvomic - 01-31-2015, 06:27 AM
RE: Classic Fourier Series - Tim Wessman - 01-31-2015, 09:29 PM
RE: Classic Fourier Series - salvomic - 01-31-2015, 09:47 PM
RE: Classic Fourier Series - Snorre - 01-31-2015 09:11 PM
RE: Classic Fourier Series - salvomic - 01-31-2015, 09:53 PM
RE: Classic Fourier Series - Han - 02-01-2015, 03:10 AM
RE: Classic Fourier Series - rprosperi - 02-01-2015, 03:22 AM
RE: Classic Fourier Series - Han - 02-01-2015, 03:51 AM
RE: Classic Fourier Series - salvomic - 02-01-2015, 09:32 AM
RE: Classic Fourier Series - salvomic - 02-01-2015, 01:52 PM
RE: Classic Fourier Series - Snorre - 02-01-2015, 05:12 PM
RE: Classic Fourier Series - salvomic - 02-01-2015, 05:34 PM
RE: Classic Fourier Series - salvomic - 02-01-2015, 05:55 PM
RE: Classic Fourier Series - salvomic - 02-01-2015, 07:06 PM
RE: Classic Fourier Series - salvomic - 02-03-2015, 08:06 PM
RE: Classic Fourier Series - Snorre - 02-01-2015, 06:13 PM
RE: Classic Fourier Series - salvomic - 02-01-2015, 06:16 PM
RE: Classic Fourier Series - Snorre - 02-01-2015, 08:37 PM
RE: Classic Fourier Series - salvomic - 02-01-2015, 09:14 PM
RE: Classic Fourier Series - Snorre - 02-01-2015, 09:31 PM
RE: Classic Fourier Series - salvomic - 02-01-2015, 09:47 PM
RE: Classic Fourier Series - Snorre - 02-01-2015, 10:19 PM
RE: Classic Fourier Series - salvomic - 02-01-2015, 10:33 PM
RE: Classic Fourier Series - Snorre - 02-01-2015, 10:39 PM
RE: Classic Fourier Series - salvomic - 02-01-2015, 11:00 PM
RE: Classic Fourier Series - salvomic - 02-01-2015, 11:24 PM
RE: Classic Fourier Series - salvomic - 02-02-2015, 10:59 AM
RE: Classic Fourier Series - salvomic - 04-11-2015, 05:35 AM
RE: Classic Fourier Series - StephenG1CMZ - 10-09-2015, 09:37 PM
RE: Classic Fourier Series - salvomic - 10-10-2015, 07:38 AM



User(s) browsing this thread: 7 Guest(s)