0

I'd like to plot the following piecewise function with Fourier series in wxMaxima:

enter image description here

for given values of constants.

Here's my current input in wxMaxima:

a_1(t):=A_0+sum(A_n*cos(n*ω*(t-t_0))+B_n*sin(n*ω*(t-t_0)), n, 1, N);
a_2(t):=A_0;
a(t):=if(is(t>=t_0)) then a_1(t) else a_2(t);
N=2$
ω=31.416$
t_0=-0.1614$
A_0=0$
A_1=0.227$
B_1=0$
A_2=0.413$
B_2=0$
plot2d([a(t)], [t,0,0.5])$

Unfortunately, it doesn't work. I get the expression evaluates to non-numeric value everywhere in plotting range error. What can I do to make it work? Is it possible to plot this function in wxMaxima?

UPDATE: It works with modifications suggested by Robert Dodier:

a_1(t):=A[0]+sum(A[n]*cos(n*ω*(t-t_0))+B[n]*sin(n*ω*(t-t_0)), n, 1, N);
a_2(t):=A[0];
a(t):=if t>=t_0 then a_1(t) else a_2(t);
N:2$
ω:31.416$
t_0:-0.1614$
A[0]:0$
A[1]:0.227$
B[1]:0$
A[2]:0.413$
B[2]:0$
wxplot2d([a(t)], [t,0,0.5], [ylabel,"a"])$

enter image description here

FEA-eng
  • 106
  • 6
  • 1
    Should be possible with modifications. The main thing is that foo_n is a simple variable name, distinct from foo[n], which is a subscripted variable. (I know wxMaxima displays foo_n and foo[n] the same. This is a kind of terrible convenience; terrible because it obscures the difference, which, it turns out, is crucial.) So you need to replace every A_0, A_1, B_1, etc with A[0], A[1], B[1], etc. and in particular replace A_n and B_n with A[n] and B[n], respectively. Also, assignment is `foo: bar` and not `foo = bar`; the "=" is an equation, not an assignment. – Robert Dodier Jun 05 '22 at 21:08
  • 1
    Less important: the parentheses around the condition in `if` aren't necessary, nor is `is` necesssary in `if`, so you can write `if t >= t_0 then ...`. (It's okay to write `t_0` instead of `t[0]` so long as you don't need for the index to be a variable.) – Robert Dodier Jun 05 '22 at 21:09
  • Thank you very much, it works perfectly with these modifications. – FEA-eng Jun 05 '22 at 22:30
  • Great, glad to hear you got it working. – Robert Dodier Jun 05 '22 at 23:16

0 Answers0