tomleslie

5615 Reputation

17 Badges

10 years, 13 days

MaplePrimes Activity


These are answers submitted by tomleslie

Counterexample: since 5*15 = 75 mod 90 and 75 is not a member of {5, 15, 25, 45, 55, 65}, the set does not exhibit closure under the defined operation and hence cannot be a group

Based on your response last time, best thing I can do is make absolutely no comment on the code whcih you posted.

Assuming I haven't made any typos, I think  the graphs you want are shown below

restart;
with(plots):
ode := diff(y(x), x, x) = x*y(x)+x^(17/12);
ics := y(1000) = 0, y(1001) = 1;
sol:=dsolve({ode,ics}, numeric);
odeplot( sol,[x, y(x)], x=1000..1001);

You cannot write

X:=x

in your procedure because X is a passed parameter. You cannot assign to passed parameters

Also there is some very doubtful logic in the opening statement of the inner 'do' loop.

See attached

JACOBICorr.mw

Lots of logical and a few syntax errors. See the comments in the attached for explanations

ratRoots.mw

What benefit do you gain by getting someone else to do your homework for you?

You may be able to fool your tutors, but trust me the first time you ever go for a job interview, you will either know what you are talking about or you will be thrown out in about 2 minutes?

Having got that off my chest, and sticking to the conditions of the homework problem, the following will work

km:= proc( n::posint, m::nonnegint)
                 local k,
                 mySum:=0:
                 for k from 1 by 1 to n do
                      mySum:=mySum+k^m;
                 od;
                 return mySum;
        end proc:

Of course no-one would actually code it this way: the following is much shorter/more efficient etc etc

km:= proc( n::posint, m::nonnegint)
                  add( k^m, k=1..n):
         end proc:

I think your problem is with your calculation of Phi, since this produces a quantity which makes no sense as the first argument for the command StudentClaculus[Roots].

See the attached (in which I have filtered the number of values down from 2000 to 10 just so that it is much easier for me to see what is going on). Once logical error have been corrected, the filter can be removed.

What do you expect the calculation of Phi to produce???

hw2_Corr.mw

plot( [seq(k*x^2, k=1..5)], x=-10...10);

You have to make sure that the argument to the Norm() function is a vector, rather than a piecewise definition. Two ways to achieve what you want

Method1:

restart;
with(VectorCalculus):
vec:=t->piecewise(t<0, <t|0>, <t|0>):
norms:=t->Norm(vec(t)):
plot(norms, -1..1, discont=true);

Method 2

restart;
with(VectorCalculus):
norms:=t->piecewise(t<0, Norm(<t|0>), Norm(<t|0>)):
plot(norms, -1..1, discont=true);

Use getdata() to extract the data to be plotted from the structure returned by the odeplot() command. Then scale the x-coordinates, as in

restart;
with(plots):
with(plottools):
sol:=dsolve({diff(y(x),x,x)+y(x)=0,y(0)=0,D(y)(0)=0.5},numeric):
A:=Array(1..2):
A[1]:= odeplot( sol,
                        x = -10 .. 10,
                        title="x in radians",
                        titlefont=[roman, bold, 20]
                     ):
A[2]:= plot( 360/(2*Pi)*getdata(A[1])[3][..,1],
                   getdata(A[1])[3][..,2],
                   title="x in degrees",
                   titlefont=[roman, bold,20]
                 ):

Seems like the answe is to use the plots[arrow]() command

Best I have achieved so far is shown in the attached worksheet: plots need "prettifying" by fiddling with the options to the plots[arrow] command, which I don't really have time to do right now

plotVec.mw

As I stated in the worksheet attached to my first response to this question, the function eta() depends on the function H(). The function H() did not exist in your original worksheet, and still does not in your latest worksheet.

So within the definition for eta(), you use H(T[i]): T[i] generally seems to evaluate to a float; but then what is meant by H(T[i])??? Until you resolve thi issue, eta() will not be correctly evaluated, so nether will the integral I2.

See the attached (partial) worksheet whose final few execution groups illustrates this point in more detail

hw2_partial2.mw

I suggest you read the comments in the attached file

hw2_finished_partial.mw

I stopped "fixing" things about half-way through. I suspect that Carl's suggestion of odeplot might be the best way to go, but I found so many logical errors in you original that I coulld not be sure (and only you know)

There are too many errors of logic andd ysntax in your code for me to even work out what you might be trying to achieve

In particular you must understand the difference between an assignment and an equation in Maple - you seem to be using one or the other more or less at random. See the comments in the following code for your probable error/misunderstandings

restart;
with(RandomTools):
with(LinearAlgebra):
with(Statistics):
with(plots):
UseHardwareFloats:
interface(rtablesize = infinity):
  N := 51;
  n := 50;
  G := Matrix(N, N, Generate(distribution(Normal(0, 1)), makeproc = true), shape = symmetric):
  TG := Transpose(G):
  H := (G+TG)*(1/2):
  Eigenvs := simplify(Eigenvalues(H));
#
# Scale the entries in Eigenvs by the factor
# 1/sqrt(2*N) ans sort into ascending numerical
# order
#  PosEigenvs := convert(Eigenvs/sqrt(2*N), list);
#
   PosEigenvs:=sort( 1/sqrt(2*n)*convert(Eigenvs, list));
#
#  In the OP's original this command did nothing useful
#
#  seqPosEigenvs := seq([PosEigenvs[i]], i = 1 .. N);
#
# So many things wrong with the following; in the following
# loop, each index value will cause the previous one to be
# overwritten, so the only output will be the equation, NB
# *not* an assignment,
#
# Spacing=seqPosEigenvs[n]-seqPosEigenvs[n-1]
#
  for i to n-1 do
      Spacing = seqPosEigenvs[i+1]-seqPosEigenvs[i]
  end do;
#
# So once this loop has finished, the variable Spacing has not
# been assigned to anything (although it has been used as one
# side of an equation) - this is not good and effects are going
# to ripple on for ever
#
# In the following two lines note that
#
# NormalisedSpacing := Spacing/avgSpacing; and
# avgSpacing := Spacing/n;
#
# so
#
# NormalisedSpacing := Spacing/(Spacing/n)
#
# which is guaranteed to return 'n' - whatever Spacing has been
# previously assigned to  - and it has not been assigned to
# anything!
#
  avgSpacing := Spacing/n;
  NormalisedSpacing := Spacing/avgSpacing;
#
# Spacing has not been assigned to anything, and since the
# following is an equation not an assignment, pGOE will not
# be assigned to anything either
#
  pGOE = (1/2)*Pi*Spacing*exp(-(1/4)*Pi*Spacing^2);
#
# In the following - so many errors
#
# 1) Again the body is an equation, not an assignment, which
#    is probably wrong
# 2) diffSpGOE cannot be used as both an indexed and an
#    unindexed variable
# 3) diffSpGOE[0] is unassigned so even if subsequent values
#    were indexed, no sensible assignments would be made
# 4) pGOE was used in an equation above, but not an assignment
#    so pGOE has no numeric value and in any case is not an
#    indexed variable so using pGOE[i+1] is just meaningless
# 5) As noted above NormalisedSpacing has been set equal to
#    n: note that again this is not an indexable
#
  for i from 0 to n-1 do
      diffSpGOE = diffSpGOE[i]+pGOE[i+1]-NormalisedSpacing[i+1]
  end do; percentagedifference := 100*diffSpGOE/n;

You can either read a file byte-by-byte and test as you read, or read all bytes into a list and then run tests on the list.

Examples are given below - obviously you will have to change the fileName to something relevant for your machine. The test file I used is a relatively short (20 lines) text file created using a text editor in Windows.

All that the following code does is print the position of C/R or L/F in the stream - obviously you will probably want to do something more interesting

#
# Read and test byte-by-byte
#
   restart;
   fd:=fopen("J:/Users/TomLeslie/myMaple/projectEuler/utilities/digGet.mpl", READ, BINARY);
   b:=readbytes(fd)[]; # read first byte
   pos:=1;
   while b>0 do #readbytes returns 0 at end-of-file
            if      b=10 # ASCII 10 is linefeed
            then printf(" L/F at byte number %d\n", pos);
            elif   b=13 # ASCII 13 is carriage return
            then printf(" C/R at byte number %d\n", pos);
            fi:
            pos:=pos+1:
            b:=readbytes(fd)[]; # read next byte
   od:
   fclose(fd);

#
# Read file into an list of ASCII codes
#
   restart;
   fd:=fopen("J:/Users/TomLeslie/myMaple/projectEuler/utilities/digGet.mpl", READ, BINARY);
   A:=readbytes(fd, infinity):
#
# traverse list looking for L/F or C/R
# (ASCII codes 10 and 12)
#  
   for j from 1 by 1 to numelems(A) do
        if      A[j]=10 # ASCII 10 is linefeed
        then printf(" L/F at byte number %d\n", j);
        elif   A[j]=13 # ASCII 13 is carriage return
        then printf(" C/R at byte number %d\n", j);
        fi:
  od;

First 109 110 111 112 113 114 115 Last Page 111 of 123