acer

32470 Reputation

29 Badges

20 years, 4 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Even a linear fade-in/out for each note (rather than a merging glissando) reduces the clicks I had previously. Now I hear just a minor click between re-runs, when looping it.

The fade could be constructed more automatically, based on the sample rate and duration.

restart;
with(AudioTools):

MK := proc(f::numeric)
        AudioTools:-Create(duration=0.5,rate=44100,
             x->evalhf(sin(x*2*Pi*f/44100))):
      end proc:

S1:=Array(1..22050,x->evalhf(piecewise(x<0.6*22050,5/3*x/22050,
                                       x<0.8*22050.0,1.0,
                                       5*(1.0*22050-x)/22050.0)),
           datatype=float[8]):
S2:=Array(1..22050,x->evalhf(piecewise(x<0.2*22050,5*x/22050,
                                       x<0.8*22050.0,1.0,
                                       5*(1.0*22050-x)/22050.0)),
           datatype=float[8]):
S3:=Array(1..22050,x->evalhf(piecewise(x<0.2*22050,5*x/22050,
                                       x<0.4*22050.0,1.0,
                                       5/3*(1.0*22050-x)/22050.0)),
           datatype=float[8]):

Cmaj:=Create(Vector([S1.MK(261.62),
                     map(u->S2.MK(u),
                         [293.67,329.63,349.23,
                          392.00,440.00,493.88])[],
                     S3.MK(523.25)])):

Write(cat(kernelopts(homedir),"/mapleprimes/Cmaj.wav"),Cmaj):

But I have yet to adjust for even loudness (for the average teenage listener, say).

@ActiveUser My computer computes the Array and exports it to a 4.0sec duration .wav file very quickly, doing it all in a fraction of a second in real time. These pure tones Arrays could be constructed quickly in a routine that runs wholly under evalhf, even in Maple 12. So I suspect that it could be built faster, using AudioTools only for its Write command.

But I won't have time to look at that before Sunday night at the earliest. And I wouldn't know for sure until next week whether it's all just slower in Maple 12 (or whether you might just have a slow machine).

And of course I have no idea what you mean when you say you've used a for-loop, because you haven't been polite enough to show your code.

@ActiveUser 

Here's a C major scale, from C[4] (Middle C) to C[5] (Tenor C), with A[4]=440.00Hz and equal temperament.

restart;
with(AudioTools):

MK := proc(f::numeric)
        AudioTools:-Create(duration=0.5,rate=44100,
             x->evalhf(sin(x*2*Pi*f/44100))):
      end proc:

Cmajor:=Create(Vector(map(MK,[261.62,293.67,329.63,349.23,
                              392.00,440.00,493.88,523.25]))):

Write(cat(kernelopts(homedir),"/mapleprimes/Cmajor.wav"),
      Cmajor):

When I play the exported .wav file I hear a click between the pure tones. It might be possible to remove it by having a windowing effect to have the power taper at the ends of the notes, ie. a fade-in/out, or a glissando. (I won't use any windowing functionality from the SignalProcessing package because the OP has Maple 12.)

I have not used any equal loudness contour so as to make all these pure tones have the same loudness (in phons).

@Christian Wolinski Yes, I used vi to delete validly enclosed XML blocks, and bisection searched for the problematic part.

The GUI should be more robust in handling an invalid blob of Typesetting, and not fall flat. I will submit a bug report.

@Christian Wolinski In your attachment most of the 2D Input is no longer typeset, and most inputs are changed from executable input to mere text, and some heading styles are gone.

Show us what work you've done so far with this homework task.

Upload it in an attachment (green up-arrow)m in a Reply/Comment.

Show us what work you've done so far with these homework tasks.

Show us what work you've done so far with these homework tasks.

@pgordon1998 Your task is to write procedures and assign them to PowerSet and RandSet. Your output indicates that so far those names are still unassigned. Did you write such procedures? Did you assign them to those names?

@pgordon1998 Your output shows that you have not yet assigned anything to list_to_set (or set_to_list).

Did you write previous code for a procedure for list_to_set? That's the task. Perhaps you've written a procedure for it, but did not assign it properly?

@susanhl I've tried to tell you that I think that your original method (and Tom's "fix" for it) has several dubious aspects to it.

You could use dsolve(...,numeric) to find the first time t at which the displacements match their targets.

I've edited my Answer to illustrate how your original could be used to try and find the solution with smallest positive t.

@susanhl I'm now supposing that you're simply trying to solve eindx and eindy together. That is, to find values for t and v0 which satisfy both those equations.

This can be done directly in your worksheet, without any weird indexing, any use of fixed accuracty approximations of Pi, etc. And especially without any dubious looking RootOfs or float coefficients with very large exponents.

I've used Maple 16 below, like your original.

Perhaps you'd want to supply ranges for t or v0 in the call to fsolve? And there may be more than one solution.

restart

kernelopts(version);

`Maple 16.01, X86 64 LINUX, May 6 2012, Build ID 744592`

mbal := 0.28e-2:

rbal := 0.2e-1:

Cw := .47:

g := 9.81:

A := Pi*rbal^2:

beta := 3.33*Pi*(1/180):

s0x := .2:

s0y := .25:

rho := 1.293:

l := 2:

vx := diff(sx(t), t);

diff(sx(t), t)

vy := diff(sy(t), t);

diff(sy(t), t)

ax := diff(sx(t), `$`(t, 2));

diff(diff(sx(t), t), t)

ay := diff(sy(t), `$`(t, 2));

diff(diff(sy(t), t), t)

v0x := cos(beta)*v0;

cos(0.1850000000e-1*Pi)*v0

v0y := sin(beta)*v0;

sin(0.1850000000e-1*Pi)*v0

`&Sigma;Fx` := -Fdx = mbal*ax;

-Fdx = 0.28e-2*(diff(diff(sx(t), t), t))

`&Sigma;Fy` := -Fz-Fdy = mbal*ay;

-Fz-Fdy = 0.28e-2*(diff(diff(sy(t), t), t))

Fz := mbal*g;

0.27468e-1

Fdx := .5*rho*vx^2*A*Cw;

0.1215420e-3*(diff(sx(t), t))^2*Pi

Fdy := .5*rho*vy^2*A*Cw;

0.1215420e-3*(diff(sy(t), t))^2*Pi

ics1 := sx(0) = s0x, (D(sx))(0) = v0x;

sx(0) = .2, (D(sx))(0) = cos(0.1850000000e-1*Pi)*v0

ics2 := sy(0) = s0y, (D(sy))(0) = v0y;

sy(0) = .25, (D(sy))(0) = sin(0.1850000000e-1*Pi)*v0

verplaatsingx := dsolve({ics1, `&Sigma;Fx`}, sx(t)):

verplaatsingy := dsolve({ics2, `&Sigma;Fy`}):

eindy := rhs(verplaatsingy) = rbal:

eindx := rhs(verplaatsingx) = l:

S1 := fsolve({eindx,eindy}, {t,v0}, {t=0..infinity});

{t = 2.505529244, v0 = .8156407228}

eval(t,S1);

2.505529244

S2 := fsolve({eindx,eindy}, {t,v0}, {t=0..eval(t,S1)}, avoid={S1});

{t = .2655908244, v0 = 7.694586917}

S3 := fsolve({eindx,eindy}, {t,v0}, {t=0..eval(t,S2)}, avoid={S1, S2}):
op(0,eval(S3,1)); # unevaluted return, ie. no earlier root

fsolve

#
# Let's write a loop to try and find the least
# positive value of t which solves {eindx,eindy}.
# This stops when no solution with smaller positive
# value for t is found.

continue := 'continue': found := {}: lastT := infinity:
while continue <> false do
  printf("searching on %a\n",t=0..lastT);
  S := fsolve({eindx,eindy}, {t,v0}, {t=0..lastT}, avoid=found);
  if op(0,eval(S,1)) <> fsolve then
    lastT,lastv0 := eval(t,S),eval(v0,S);
    printf("  solution found for %a\n",t=lastT);
    found := S;
  else
    printf("  no smaller solution found");
    continue := false;
  end if;
end do:

searching on t = 0 .. infinity
  solution found for t = 2.505529244
searching on t = 0 .. 2.505529244
  solution found for t = .2655908244
searching on t = 0 .. .2655908244

  no smaller solution found

t=lastT, v0=lastv0;

t = .2655908244, v0 = 7.694586917

 

Download ttbuddymaple_ac4.mw

Why don't you show us how far you managed to get with this so far.

Why don't you show us how far you managed to get with this so far.

If the problem occurs even without your using PackageTools:-Install then remove that aspect from your upload.

Some people may execute your workbook's worksheet without realizing that doing so installs your module into their harddrive (thus affecting the Maple namespace for all future sessions, unless they realize that it should be uninstalled.)

@Carl Love For singular values it can depend on the size. By that I mean that an iterative technique for computing only selected singular values might be slower that a highly optimized dedicated routine for finding all singular values of a dense Matrix. One piece of Matlab documentation say, "Using svds is not the most efficient way to find a few singular values of small, dense matrices. For such problems, using svd(full(A)) might be quicker. For example, finding three singular values in a 500-by-500 matrix is a relatively small problem that svd can handle easily."

The singular value functions in the MKL implementation of LAPACK are fast, and difficult to beat for modestly sized Matrices. That's true even for the DGESVD that Maple 2019's SingularValues uses, which does not provide for computing only a selection of singular values. There is a newer Jabobi implementation DGEJSV available in MKL, computing a range of singular values, but no direct link to it in Maple as yet. (See also here. And the older Jacobi implementation DGESVJ without the range functionality, also without a direct link from Maple.)

The most important things to keep in mind here, for performance of this computation in Maple, is to have the Matrix with datatype=float[8] and shape=symmetric. Here's a comparison of SingularValues versus Eigenvalues (the latter done with and without shape=symmetric). The very small singular values are computed by Eigenvalues less accurately for this example. But perhaps the small speed improvement over SingularValues might make it attractive for computing only a selection of the "larger" singular values.

singvals.mw

I made an old Post about computing only a selection of eigenvectors, for a real symmetric Matrix. That code can be modified to compute only eigenvalues. It needs revision and updating, on account of how the external compiled functions are named and accessed in modern Maple. It may not be possible to compare properly, because since the date of that Post Maple's Eigenvalues has switched from using a generic LAPACK DSYEVX (with MKL BLAS) to the MKL DSYEVD. The former allows computation of only a selection of eigenvalues, while the latter does not. But their performance difference is significant, with the MKL being so optimized that a partial eigenvalue computation with that DSYEVX against the full eigenvalue computation with MKL DSYEVD still favors the latter. It's also complicated since it may not be possible to define_external from Maple to the MKL functions directly. I'll add a comment if I find a performance breakthrough for selected eigenvalues or singular values.

(It may still be able to edge out the selected eigenvectors computation, although that's off-topic.)

First 204 205 206 207 208 209 210 Last Page 206 of 594