tomleslie

13876 Reputation

20 Badges

15 years, 176 days

MaplePrimes Activity


These are answers submitted by tomleslie

Consider what happens if this code is executed when elenum=2 and [faultcom, faultloc] are not initialised.

Since eleneum is not = 1, the if-clause is false and the else-clause executes. However, unless 'faultcom' and and 'faultloc' have been innitialised, the 'do' loop contains recursive definitions. One way round this would be to initialise 'faultcom' and 'faultloc' as empty sets, as in

faultloc:={}:
faultcom:={}:
if elenum = 1 then
    faultcom := theDiagnosis[1][1][1][1];
    faultloc := theDiagnosis[1][1][1][2];
else
    for numi from 1 to elenum do
        faultcom := faultcom union theDiagnosis[1][1][i][1];
        faultloc := faultloc union theDiagnosis[1][1][i][2];
    end do;
end if;

 

Now the statements if the for-loop are never recursive.

You may also wish to check the use of 'i' as the third index in theDiagnosis[1][1][i][1] and theDiagnosis[1][1][i][2].Shound these be theDiagnosis[1][1][numi][1]  and theDiagnosis[1][1][numi][2]????

 

 

First of all, you need to define the function correctly, and there are several ways to do this. Preben's (perfectly correct) use of "unapply" is one of them - but may(?) not be the simplest to understand

The following just shows the simplest, most basic, way to define a function. Use 'arrow' notation to determine what you wnat to happen to a specific argument. So if you want to square an argument, then you need

a->a^2

which basically means, given a value for 'a', return 'a^2'. Now, in order to be able to call this function, you have to assign it to a name, using something like

myFunc:=a->a^2

So now myFunc(3) will return 9, myFunc(5.0) will return 25.0, and so on.

So for your specific problem, the 'simplest' method is to use

   restart:
#
# Define a function myInt()
#
   myInt:=a->int(exp(-x^2)*sin(a*x),x=0..infinity);
#
# Evaluate this function for a couple of specific
# arguments
#
   myInt( -5.0 );
   myInt(  5.0 );
#
# Plot the function for argument values from -10..10
#
   plot(myInt, -10..10);

Once you have understood the simple method of defining functions, you can proceed to the more 'advanced' methods.

 

that I have a problem distingishing between Maple 'types' and Maple 'properties'.

I always assume that this is a consequence of my own stupidity - because I'm sure that the distinction is 'obvious'.

To answer your immediate question, try

restart:
applyrule(a::integer = 0, x = 1);
applyrule(conditional(type(a, anything), type(a, `=`)) = 0, x = 1);

If you have a vector where each row is an equation in a single variable, then as Maxim has pointe out, the answer is relatively tricvial nad can be achieved with:

  restart:
  V:=Vector([2*x^2+1, x-3, 3*x^3-5*x-2]);
  V/~lcoeff~(V);

However you stete that " each row is an equation with 2 variables" and then state that you want to do something on the basis of " the leading coefficient of one of the variables" - as in the leading coefficient of which variable? You have to bear in mind that Maple will order "more-or-less" equivalent terms in an equation lexicographically so if I enter

V:=Vector([3*y^2-x, x^3-7*y, y^2+3*x^2]);

Maple will flip the third row to 3*x^2+y^2. So when you refer to  "the leading coefficient of one of the variables" you are going to have to get very, very, specific - as in the leading coefficient of which variable????

 

I think(?) your problem stems from the fact that nothing in the Statistics package is 'threadSafe'. If I replace your calls to the 'Statistics' package with some "toy" code, then everything seems to function correctly. See the attached

0927Corr.mw

For a list of packages/commands which are 'threadSafe', just type ?threadSafe at the Maple prompt

 

just because alternatives are good,

a:=2*x-5;
StringTools:-Substitute(convert(a, string), "*", "");

 

Substituting any positve integer for 'k', Maple returns 'infinity'  for sum(binomial(k+i,k),i=0..infinity)

Aaaah, the problems of fitting a sinusoid to data.

Consider the following

  1. If a sinusoid of frequency 'f' fits the data, then sinusoids of frequency '2*f', '3*f', '4*f'....... will also fit the data equally well. So there are an infinite number of solutions
  2. If a sinusoid with phase offset 'phi' fits the data, then the same sinusoid with phase shifts of 'phi+2*Pi', 'phi+4*Pi', 'phi+6*Pi',.... will also fit the data equally well. So again there are an infinite number of solutions

Now you *probably* want the solution with minimum frequency, and phase between 0 and 2*Pi - because for a "human", this natural/obvious? However such requirements are not obvious for any kind of fitting program, unless you can specify them in some way.

Mariusz Iwaniuk   has essentially achieved this "obvious" fit, by providing appropriate initial values. Any decent fitting program will (probably) find the *closest* solution (from the infinite number of equally valid alternatives) to these initial values. I have no problem with this. However it does require, to some extent, the use of a 'calibrated human eyeball' in order to generate an appropriate list of initial values.

So what happens when the 'calibrated human eyeball' is not available. Just using the input data, is it possible to compute estimates for all of the parameters, so that a fitting program will come up with the desired "obvious" solution?? The attached will work most of the time - but I can think of circumstances where it will fail!!!

  restart;
  with(Statistics):
  with(Student[Precalculus]):
  X := [seq(i, i = 0 .. 24)]:
  Y := [ 1154, 1156, 1156, 1155, 1152, 1143, 1105, 1069, 1051, 1077,
         1117, 1154, 1154, 1156, 1158, 1157, 1155, 1152, 1128, 1089,
         1058, 1059, 1092, 1130, 1163
       ]:
#
# Get an estimate for the offset term
#
  osEst:=evalf(add(Y)/numelems(Y)):
#
# get an estimate for the amplitude
#
  ampEst:=(max( Y-~osEst)-min( Y-~osEst))/2:
#
# Get an estimate for the frequency
#
  ics:=NULL:
  for i from 2 by 1 to numelems(Y) do
      if   signum((Y[i]-osEst)*(Y[i-1]-osEst))=-1
      then ics:= ics, Line([X[i-1],Y[i-1]-osEst],[X[i], Y[i]-osEst])[4];
      fi;
  od;
  ics:=[ics]:
  freqEst:= 2*Pi/(2*coeff
                    ( Fit
                      ( grad*x+cept,
                        [ seq( j,
                               j=1..numelems(ics)
                             )
                        ],
                        ics,
                        x
                      ),
                      x,
                      1
                    )
                 ):
#
# Get an estimate for the "phase". Has to
# be between 0 and 2*Pi, so just take Pi
# as a reasonably good guess
#
  phaseEst:=eval(Pi):
#
# Now do the fit with an initial guess given
# by the estimates previously calculated
#
  f := Fit( a*sin(b*x+c)+d,
            X,
            Y,
            x,
            initialvalues = [ a = ampEst,
                              b = freqEst,
                              c = phaseEst,
                              d = osEst
                            ]
          ):
#
# Plot the original data and the obtained fit
#
  p1:=plot(X,Y, style=point, color=blue):
  p2:=plot(f, x=0..25, color=red):
  plots:-display([p1,p2]);

 


 

Download fitSin.mw

wouldn't it be easier to define a single function with three arguments, as in

restart;
Z := (s, h, j) -> evalf(subs(x = x1[h](s), y = y1[h](s), Q[h][j]));

You just have to "remember" that the second and third arguments have to be supplied as integers, in the range 1..50 and 1..3 respectively. One could even include a simple test on these indices, as in

Z := (s, h, j) ->`if`( `and`( h::integer, h>=1, h<51, j::integer, j>=1, j<4 ),
                               evalf(subs(x = x1[h](s), y = y1[h](s), Q[h][j])),
                               print("invalid index")
                           );

 

You have  a single ODE containing two indeterminate functions A(t) and B(t).

Now you can solve for either of these indeterminate functions, in terms of the other, using,

restart;
ode:= B(t)*diff(B(t),t$2)*A(t)-A(t)*diff(B(t),t)^2-diff(A(t),t$2)*(B(t))^2+diff(A(t),t)*B(t)*diff(B(t),t)-A(t)=0;
dsolve(ode, B(t));
dsolve(ode, A(t));

But from a single equation, you cannot explicitly obtain both indeterminate functions.

 

'Determinant' is a command within the LinearAlgebra package. Hence in order to use this command, you either have to load the whole LinearAgebra package using

with(LinearAlgebra);

or use the long form calling sequence for this specific command, as in

LinearAlgebra:-Determinant()

but one of the definitions in the attached *ought* to cover what you want


 

  restart;
#
# Define the function in a way which is easy
# to manipulate
#
  tau:=30:
  f:= t-> 12*Heaviside(-t)*exp(t/(4.2))*(1+t/(4.2))+0.6e-1*Heaviside(-t+tau):
  g:= t-> f(t)+f(-t):
#
# Plot the "original" pulse, centred at t=0
# just as a check
#
  p1:=plot( g, -40..40);
#
# Now just plot multiple "translations" of this
# original plot, spaced by "tau". Note that these
# are *simple translations" of the original pulse,
# so multiple curves are generated. Contributions
# from these pulses are not added to produce a
# single signal
#
  p2:=[seq( plottools:-translate(p1,tau*j,0), j=-5..5)]:
  plots:-display
         ( [ seq
             ( plottools:-translate(p1 ,tau*j, 0 ),
               j=-5..5
             )
           ]
         );
#
# Define a new function which does a simple shift-
# and-add of the original plot
#
  h:= t-> add(f(t+n*tau)+f(-(t+n*tau)), n=-10..10):
#
# Have to increase numpoints option in order
# to get a reasonably smooth curve
#
  plot(h, -400..400, numpoints=50000);

 

 

NULL


 

Download plotPulses.mw

When you "activate" a piece of software, you send to the software provider (at least) two pieces of information. The first of these is software activation code: the second is something specific to the hardware on which. you have installed the software. Often (but not always) this will be the serial number of the hard drive on which the software was installed.

Thus if you try to install the same software on different hardware, the software supplier may interpret this as some kind of "piracy". However most software suppliers recognise that we all update our computers (ie replace hardware), or hard drives go belly-up (ie replace hardware). So if you explain the problem to them, they can quickly reset their database to allow you to install on new hardware.

The only time you might have a problem is if you do multiple re-installs on multiple new hardware - because this starts to look like serious software piracy!

So as Acer has suggested - just get in touch with customer help at custservice@maplesoft.com. Tell them you have bought a new computer - and they will fix it for you

In Maple terms, a 'package' is a suite of commands/procedures which significantly extends Maple functionality, and whose commands/procedures can be 'called' from your own worksheet. Now I have been unable to load this package/worksheet in any kind of meaningful way. But, from what I can tell this "package" just seems to be educational. In other words, it essentially consists of remarks such as

If you want to do this ........

Then run this Maple command

This does not extend Maple functionality in any way. It might be considered more as an extension to Maple help.

My recommendation would be not to bother with this "package". It offers no new functionality. Just explain the problems you are having with the in-built Maple commands. Someone here will probably be able to fix them

Because for 0-100% of your original integral there are always two solutions. One where the upper limit is positive, and another where the upper limit is negative.

If you want to consider the case of 150% of the original integral, then there is a solution with a negative upper limit. In fact, so far as I can tell, if you want a value greater than your original integral, then there is a finite upper limit - which is negative!


 

  restart;
#
# So do the original integral
#
  ans1:= int( 14*t*exp(-t/3),
              t=0..infinity
            );
#
# Now find the value of the upper limit which
# gives 90% of the original ntegral
#
  ans2:= fsolve( int( 14*t*exp(-t/3),
                      t=0..ul
                    )
                 =0.9*ans1
               );
#
# Well that was a surprise - a negative value
# for the upper limit, so let's just check it
#
  int( 14*t*exp(-t/3),
       t=0..ans2
     );
#
# Out of idle curiousity let's restrict the
# upper limit to be positive
#
  ans3:= fsolve( int( 14*t*exp(-t/3),
                      t=0..ul
                    )
                 =0.9*ans1,
                 ul=0..infinity
               );
  int(14*t*exp(-t/3),t=0..ans3);
#
# It is possible to observe the fact that two
# solutions occur simply by plotting the value
# of the integral as a function of the upper
# limit. This shows clearly looking for a value
# between 0 and 100% of the case where the upper
# limit is infinity, will alwasy give two
# solutions, one positive and one negative.
# If one is searching for values greater than
# 100% of the original integral, then this can
# be achieved with a negative upper limit
#
  plot( int( 14*t*exp(-t/3),
             t=0..ulim
            ),
        ulim=-4..50
      );

 

 


 

Download ul.mw

 

First 155 156 157 158 159 160 161 Last Page 157 of 207