12-14-2020, 06:02 AM
(12-13-2020 08:33 AM)Aries Wrote: [ -> ](12-10-2020 06:51 AM)dah145 Wrote: [ -> ]That'll be nice yeah. Thank you.
Hey dah145,
I'm back, here is a simple app:
First off you define the piecewise function (in an interval equal to a period) like this (say for rect(t) function):
Then you "describe" the function as a matrix (and store it to ff, as requested by the app), like this:
Lastly, you can apply fourier(ff):
The graph:
For every row in the matrix (cycle "for"), the program runs the integration and then the results (stored in "s") are counted together.
I hope this can be a valid "starting point", eventually you could do so much more.
Happy XMas to you and everyone here,
Aries
Ive had a stab at translating this for the prime.
Code:
#cas
fourier(ff):=
BEGIN
LOCAL i,n,s,t,fff,a,b,ggg;
0▶s;
rowDim(ff)▶n;
e^(−*w*x)▶ggg;
FOR i from 1 to n
DO
ff[i,1]▶fff;ff[i,2]▶a;ff[i,3]▶b;
s*int(fff*ggg,x,a,b|assumi)▶s
END;
s
END;
#end
The undefined symbol after e^(- in the listing is the imaginary symbol i from the shift keyboard.
Im getting an undefined result from the integration:
Edit: I corrected a mistake in the code
s*int(fff*ggg,x,a,b|assumi)▶s should be
s+int(fff*ggg,x,a,b|assumi)▶s
The result is now [x,0,±∞,±∞] in cas and [10.2581355196,0,+Inf,+Inf] in home
Without the assume the result is 1
Needs more work!
After clearing cas vars, I get this result:
Code:
((−i)*e^(i*w*τ/2)+i*e^((−i)*w*τ/2))/w
After applying exp2trig()
Updated code with exp2trig included in returned value:
Code:
#cas
fourier(ff):=
BEGIN
LOCAL i,n,s,t,fff,a,b,ggg;
0▶s;
rowDim(ff)▶n;
e^(−*w*x)▶ggg;
FOR i from 1 to n
DO
ff[i,1]▶fff;ff[i,2]▶a;ff[i,3]▶b;
s+int(fff*ggg,x,a,b)▶s
END;
RETURN exp2trig(s)
END;
#end