10 years, 8 days

## Well this works for me...

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);

## Syntax error...

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

## Looks suspiciously like homework?...

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)
end proc:

## Not a problem with t0?...

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

## If I understand correctly...

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

## Two ways...

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);

## Always more than one way to do it!...

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,
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]
):

## Best I have so far...

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

## The function H() still does not exist...

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

## My \$0.02...

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)

## Too many logic/syntax errors...

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;

## Suggestion...

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

#
#
restart;
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:
od:
fclose(fd);

#
# Read file into an list of ASCII codes
#
restart;
#
# 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;

## And another way...

Technically this doesn't break on self-intersection. -it  just generates NULL(s) as subsequent entries in the walk.

This is a bit wasteful, but on a small problem like this, barely noticeable (and trivial to speed up for larger problems)

Interestingly (if I have things correct), all 50 walks terminate on the grounds of self-intersection: most of them quite quickly

#
# Initialise stuff
#
restart;
M:=50: N:=1500: R3:=rand(1..3):
P:=Matrix(N+1, M, fill=[0,0]):
P[2,1..M]:=[1,0]:
#
# Define "turn" functions
#
gostraight:= (p,q)-> `if`( p[1]=q[1], p+~[ 0,p[2]-q[2]], p+~[p[1]-q[1], 0]):
turnLeft:=   (p,q)-> `if`( p[1]=q[1], p+~[ q[2]-p[2], 0], p+~[0, p[1]-q[1]]):
turnRight:=  (p,q)-> `if`( p[1]=q[1], p+~[ p[2]-q[2], 0], p+~[0, q[1]-p[1]]):
dirs:=[`gostraight`, `turnLeft`, `turnRight`]:
#
# Do walks
#
for i from 3 by 1 to N+1 do
for j from 1 by 1 to M do
if   P[i-1,j] = NULL # walk was terminated
# at a previous step
then P[i,j]:= NULL   # so keep it terminated
else ans:= dirs[R3()]( P[i-1,j], P[i-2,j]); # generate new point
# on still-active walk
if     member( ans,
convert( P[1..i-1, j],
list
)
) # check whether current point exists already on walk
then P[i,j]:=NULL # if it does, terminate walk
else P[i,j]:=ans  # otherwise, add new point
fi;
fi:
end do:
end do;
#
# plot all walks
#
plot([seq( convert(P[1..N,j], list), j=1..50)] );
#
# Generate the number of steps in each walk - any
# number less than 1501 indicates that the walk
# terminated on a self-intersection
#
seq( numelems( convert(P[1..N, j], list)), j=1..50);