Joe Riel

9530 Reputation

23 Badges

20 years, 24 days

MaplePrimes Activity


These are answers submitted by Joe Riel

See the Functional Operators help page (?->):

f := z -> z + 7+I;

My first thought was to use degree in a call to remove, alas, that won't work because your expression is not a polynomial.  Here is one approach.

Note: edited to make it slightly more general and indicative of a real case
 
 
> f := series(add(k*x^((k-1)/2),k=0..8),x,3);          
                      1/2            (3/2)      2      (5/2)      3
          f := 1 + 2 x    + 3 x + 4 x      + 5 x  + 6 x      + O(x )

> remove(m -> match(m=k*x^p,x,'s') and subs(s,p)>2, f);
                         1/2            (3/2)      2      3
                  1 + 2 x    + 3 x + 4 x      + 5 x  + O(x )

# The structure is not a series, so we can use this trick to eliminate the big-O term
> eval(%,O=0);                                       
                             1/2            (3/2)      2
                      1 + 2 x    + 3 x + 4 x      + 5 x




A nice way to do this is to extend the procedure so that the returned module includes a 'wave' field that is a procedure that returns the value at a given time.  Here is what I did (I'm not confident I computed the waveform correctly, you can fix that). I took the liberty of fixing a bug in the previous (the X should be declared local to the constructor). 

Note: I fixed a bug in the procedure (I forgot to add the dc term, a0).  I combined the plot of the original data with a plot of the fourier waveform, they compare well.


myFourier := proc(period :: positive
                  , amps :: list
                  , numCoeffs :: posint
                  , $
                 )
local t,X;
    module()
    option record;
    export a0,aAreas,bAreas,aCoeffs,bCoeffs,wave;
        a0 := `+`(amps[])/period;
        (aAreas,bAreas) := seq(Matrix(nops(amps),numCoeffs,
                                      (i,j) -> evalf(amps[i]*X(2*(i-1)*j*Pi/period))
                                     )
                               , X in [cos,sin]);
        (aCoeffs,bCoeffs) := seq(Vector[row](numCoeffs,
                                             (i) -> `+`(convert(X[1..nops(amps),i],list)[])*2/period
                                            ),X in [aAreas,bAreas]);

        wave := unapply(a0 + add(aCoeffs[i]*cos(2*Pi*i*t/period) + bCoeffs[i]*sin(2*Pi*i*t/period)
                                 , i = 1..numCoeffs), t);
    end module
end proc:

T := 10:
ys := [14,18.7,9,4.1,6.7,6,6.3,8.4,4,2.9]:
n := nops(ys):
ts := [seq(i/n*T, i=0..n-1)]:

wave := myFourier(n,ys,5);
wave:-a0;
wave:-aAreas;
wave:-bAreas;
wave:-aCoeffs;
wave:-bCoeffs;
p1 := Statistics:-LineChart(ys,xcoords=ts):
p2 := plot(wave:-wave, 0..10):
plots[display](p1,p2);

Another solution is to use create a list (or Vector) and use Statistics[LineChart].  It assumes the domain is the natural numbers (1,2,3,...) though you can provide it with the actual coordinates using xcoords:

For example

X := [seq(-20..20)]:
Statistics:-LineChart(map(x->x^2, X), xcoords=X);

A nice feature of LineChart is that it includes, by default, the points in the plot.

Here's a completely symbolic approach,

restart;
OP := P-O:
OQ := Q-O:
QP := P-Q:
OR := R-O:
QR := R-Q:
eqs := {NULL
        , a1*i + b1*j = OP
        , a2*i + b2*j = OQ
        , OR = 1/3*OP
       }:
elim := eliminate(eqs, {O,P,Q,R}):

# express QR in terms of i and j
collect(subs(elim[1],QR),[i,j]);

                                  (-a2+1/3*a1)*i+(-b2+1/3*b1)*j

Try
N := 5:
assume(seq(T[i]<T[i+1], i=0..N)):
is(T[0]<T[N+1]);
                         true
Your post was truncated because you used the less-than sign (<). To type a less-than sign, use "&lt;" (without the double-quotes).
Your function is too wide for the screen. Try evalf[20](ratio); (the 20 is the number of digits used in the numerical computation).
It's not clear what function is given. Does that equation explicitly define the function y -> x(y) or does it implicitly define a function x -> y(x)? Are you restricted to reals? If complex, then you should try experimenting with the Maple plots[conformal] command. For example,
plots[conformal](exp, map(`*`, -1..1, 9/10*Pi*(1+I)));
You can use ListTools[Categorize] to partition the list of lists, the interesting part is comparing two sublists. The simplest way I could think of is to sort them and then compare them.
a[1] := [1,0,1,0]:
a[2] := [1,1,0,0]:
a[3] := [0,0,1,1]:
ListTools:-Categorize((x,y) -> sort(x) = sort(y)
                      , [a[1]+a[2], a[2]+a[3], a[3]+a[1]]
                     );
            [[2, 1, 1, 0], [1, 0, 2, 1]], [[1, 1, 1, 1]]
This can be made more efficient by using sorting with attributes, suitably modified.
To look at a value at, say, k=30, do i[30]. To find the maximum value of s, do
  K := 60:
  smax := max(seq(s[k], k=1..K));
To find the k's (there could be more than one) that corresponds to the maximum value of s, you could do
   kwc := [seq(`if`(s[k]=smax, k, NULL), k=1..K];
It would help if you showed some of your code. Or a simple representation of it. Otherwise we have to make a lot of assumptions about what you might have done or intend.

You might find the following plot instructive

restart;
a := proc(n::posint)
option remember;
    4*a(n-1)*(1-a(n-1));
end proc:
a(1) := 0.8:
plt1 := plot([4*x*(1-x),x], x=0..1, color=black):
plt2 := plot([seq([[a(i),a(i+1)],[a(i+1),a(i+1)]][], i=1..300)]):
plots[display]([plt1,plt2]);

Here is the approach I would take. First, assign a procedure that, given n, returns a(n). The computation of a(n) requires a(n-1); to make this fast we use the remember option. Also, to terminate the descent we assign the value of a(1).
a := proc(n::posint)
option remember;
    4*a(n-1)*(1-a(n-1));
end proc:
a(1) := 0.8:
Now we need to plot this. The easiest way is to use the Statistics:-LineChart procedure (yeah, that's kind of a deus ex machina, but it works).
Statistics:-LineChart([seq(a(i),i=1..300)]);
The usual way is to apply the evalf (evaluate-using-floating-point) function. Note, however, that in Maple, the symbol for pi is spelled Pi, with a capital P. There is no corresponding symbol for e, however, in Standard GUI, exp(1) is displayed as e (you can also enter it in 2D mode by typing e followed by Ctrl-Shift-Space and selecting the e (exponential) in the pop-up menu). If you are working in the Standard GUI you can select (highlight with mouse) the expression, right click, and select, say, Approximate -> 5 to get a five digit approximation.
First 100 101 102 103 104 105 106 Last Page 102 of 114