Joe Riel

9660 Reputation

23 Badges

20 years, 5 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Here's the basic idea

plots:-animate(plots:-pointplot, [[i,i^2]], i=[seq(1..100)], symbol=circle);

For data generated in a loop the following should work

n := 100:
for i to n do
    data[i] := i^2;
end do:

plots:-animate(plots:-pointplot, [[k,data[k]]], k=[seq(1..n)], symbol=circle);
Error, points cannot be converted to floating-point values

Alas, there is a bug in `plots/animate`, it isn't evaluating the result after plugging in values. I'll submit an SCR against that.

Apparently one of the arguments must be integer[8] to work properly:

for i in [1,2,4,8] do
    for j in [1,2,4,8] do
        A := Array([1], 'datatype'=integer[i]);
        B := Array([1], 'datatype'=integer[j]);
        C := A +~ B;
        if C[1]::integer then
            printf("%d %d\n", i, j);
        end if;
    end do;
end do;
1 8
2 8
4 8
8 1
8 2
8 4
8 8

I suspect this was done to reduce overflow issues. The safer thing might be to create the output as datatype=anything, but that isn't ideal.

You might also consider using ?iquo, however, that doesn't work with non integer numeric arguments.

One approach is to use the ?difforms package (a rather old package, but still useful for some tasks).

y := r*sin(theta);
                               y := r sin(theta)

with(difforms):
defform(r=scalar,theta=scalar);
d(y);
                    sin(theta) d(r) + r cos(theta) d(theta)

Fleshing out Alec's suggestion:

evalf[30](eval({seq(Eqn(j),j=1..n)}, EV));

It's not just more elegant, it is O(n) instead of O(n^2).

How are you computing the sequence?  Here's one approach to plotting this

x_next := proc() global x; x := 9*sqrt(x+6) end proc:
x := 2.30:
plot([[1,x],seq([k,x_next()], k=2..30)]);

As for the matrix problem, the issue there is that Maple is computing the exact result, so the fractions contain large integers which makes the output look weird.  If you only want floating point values, do

TP := evalf(T)^1000:

Do you want to plot a surface, that is p(t,H) as both t and H vary?  Or do you just want to plot a curve vs t for various H?  For the latter do, for example

deqs := { diff(x(t),t) = h*sin(t) + y(t), diff(y(t),t) = x(t), x(0)=0, y(0)=0}:
integ := dsolve(deqs, numeric, parameters=[h]):
integ(parameters=[1]);
plots:-odeplot(integ, [[t,x(t)],[t,y(t)]], 0..1);

Are you using the ImageTools package that is included with Maple? 

This can be improved, but might get you started

toSecs := proc(s :: string)
local T;
    T := StringTools:-ParseTime("%R", s);
    return 60^2*T:-hour + 60*T:-minute + T:-second;
end proc:

data :=[ [3,2,"11:15"] , [4,5,"11:17"] , [6,3,"11:25"] , [7,9,"11:49"] ]:

data2 := map[3](applyop, toSecs, 3, data);
     data2 := [[3, 2, 40500], [4, 5, 40620], [6, 3, 41100], [7, 9, 42540]]

data3 := sort( data2, (x,y) -> x[3] < y[3]);
     data3 := [[3, 2, 40500], [4, 5, 40620], [6, 3, 41100], [7, 9, 42540]]

data4 := map2([op], [1..2], data3);
                   data4 := [[3, 2], [4, 5], [6, 3], [7, 9]]

I see that answers the wrong question.  Sorting wasn't needed.  Are you planning on plotting with a 3D plot, otherwise how else do you plot the pair against a time? You should be able to modify the above to work, that is, with the conversion from H:M to seconds you can plot these points in a 3D using a points plot

plots:-pointplot3d(data2, connect, axes=boxed);

It works fine.  Did you load StringTools?

(**) L := ["34mt5","tru532","64E22N"]:
(**) select(StringTools:-HasDigit, L);
                                                       ["34mt5", "tru532", "64E22N"]

Here's an algebraic way to do that (I recall suggesting this years ago on one of the usenet groups):

Let L be the list of (repeated) factors:

L := [2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 5, 5, 5, 7, 7, 107]:

Rather than counting, just convert them to names and add them up. Maple will automatically compute the coefficients:

S := add(X[x], x in L);
                               8 X[2] + 4 X[3] + 3 X[5] + 2 X[7] + X[107]

There are various ways to convert that to the desired form.  For the class, however, I'd probably stick with a more programmatic approach.

 



 


 

You could use applyop, as Alec suggested in another thread.  For example

L := [[seq(1..10)]$3]:
map[3](applyop, `-`, 2, L);
L := [[seq(1..10)]$3]:
      [[1, -2, 3, 4, 5, 6, 7, 8, 9, 10], [1, -2, 3, 4, 5, 6, 7, 8, 9, 10], [1, -2, 3, 4, 5, 6, 7, 8, 9, 10]]

However, for large structures you probably want to work with Arrays.

An easy way is

map(p->p[[2,1]],  P);

Same idea, but trickier, is

map(`?[]`,P,[[2,1]]); 

 A final variation on the theme,

`?[]`~(P,''[[2,1]]'');  

 

 

 

Note that LengthSplit returns an expression sequence of lists, so for equivalency you'll want to enclose it in a list. 

A nicer alternative to your original is to use the step parameter of seq:

[seq([a[i],a[i+1]], i=1..nops(a), 2)];

Just for my amusement

convert(Matrix(nops(a)/2,2,a),listlist); 


The error message is an important clue.  Generally you cannot assign to a formal parameter.  Here you have

simp := proc(L, k)
   ...
   L := ...
   ...
end proc:

 

First 67 68 69 70 71 72 73 Last Page 69 of 114