Post Reply 
Classic Fourier Series
04-11-2015, 05:35 AM (This post was last modified: 04-11-2015 05:36 AM by salvomic.)
Post: #38
RE: Classic Fourier Series
New version

Use, as always:fourcoeff(func, k) or fourcoeff(func, var, k), es. fourcoeff(COS(t/2), t, 1) of fourcoeff(x^2, 2)...

This now permits a choose from 3 interval: [0, 2PI], [-PI, PI], [other], where "other" gives the opportunity to input a value for a parameter T to get an interval like [-T/2, T/2]; es. input 2 to have [-1, 1], for a non trigonometric function of a function...
The program return then a_0, a_n, b_n (trigonometric form), and c_n (exponential form) of Fourier's Series for a given number (int: n -> 1, 2, 3...)

Code:

ChooseInterval()
BEGIN
LOCAL choice;
CHOOSE(choice,"Interval","From 0 to 2π","From −π to π", "Other");
RETURN choice;
END;

inputT()
// input routine for choice 3
BEGIN
INPUT(T, "Interval", "Period T",  "Input T for [-T/2, T/2]", 2);
RETURN T;
END;

#cas
fourcoeff(args):=
// Coefficienti di Fourier formula normale,  by Salvo Micciché v 1.0
// input funzione fourcoeff(func, k) o espressione fourcoeff(expr, var, k)
BEGIN
local argv,argc,f,k;
local ak, bk, a0,ck;
local scelta;
argv:=[args];
argc:=size(argv);
f := argv(1);
k := argv(argc);
IF argc=3 THEN f:=zip('unapply', f, argv(2)); END;

scelta:= EXPR(" FourCoeff.ChooseInterval()");

CASE
IF scelta=1 THEN 
a0:=(int(f(t),t,0,2*PI))/(PI);
ak:=(int(f(t)*cos(k*t),t,0,2*PI))/PI;
bk:=(int(f(t)*sin(k*t),t,0,2*PI))/PI;
ck:=( int(f(t)*e^(-i*k*t),t,0,2*pi))/(pi);
RETURN {"[0,2π] a₀ aₙ bₙ", a0,ak,bk, "cₙ", ck}; 
END;

IF scelta=2 THEN
a0:=(int(f(t),t,-pi,pi))/(pi);
ak:=(int(f(t)*cos(k*t),t,-pi,pi))/pi;
bk:=(int(f(t)*sin(k*t),t,-pi,pi))/pi;
ck:=( int(f(t)*e^(-i*k*t),t,-pi,pi))/(pi);
RETURN {"[-π,π] a₀ aₙ bₙ", a0,ak,bk, "cₙ", ck}; 
END;

IF scelta=3 THEN 
EXPR("FourCoeff.inputT()");
// input T for interval [-T/2, T/2] es. 2pi -> [-pi, pi], 2 -> [-1,1] ...
a0:= exact( (int(f(t),t,-(T/2),T/2))*2/T );
ak:=exact( (int(f(t)*cos((2*PI*k/T)*t),t, -T/2, T/2))*2/T);
bk:=exact( (int(f(t)*sin((2*PI*k/T)*t),t,-T/2,T/2))*2/T );
ck:=exact( ( int(f(t)*e^(-i*k*t),t, -(T/2),T/2))*2/T );
RETURN {"[t₀,T] a₀ aₙ bₙ", a0,ak,bk, "cₙ", ck}; 
END;

DEFAULT RETURN("Choose periodicity interval");
END; // case

END;
#end

(in case of error, substitute the underscript in RETURN {"[t₀,T] a₀ aₙ bₙ", a0,ak,bk, "cₙ", ck} with the _n ...)

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website 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: 8 Guest(s)