4918 Reputation

9 years, 185 days

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

Well...

m:=Matrix(  [ [ alpha(t), alpha__b(t)],
[ beta__b(t), beta(t)]
]
);
diff~(m,t);

After this point it depends very much on your definitions of the four functions involved (and the initial conditions)

Check parentheses...

I f I manage to put parentheses in your expressions correctly, then try

x:=t->cos(t)/(1+sin(t)^2):
y:=t-> sin(t)*cos(t)/(1+sin(t)^2):
plot([x(t), y(t), t=-Pi..Pi]);

Not completely clear...

Still not completely clear what you want, but the attached worksheet covers many of the possible options - you just have to pick the one you want

contours.mw

You can get more info from the CodeTools package: for example if you define some ( arbirary) procedure - as an example

tproc:=proc( n )
ifactor(n!+1):
end proc:

then

CodeTools[Usage](tproc(38));

will return some interesting info, including timing: NB the numeric value 38 in the above is arbitrary - big enough to show reasonable compute times, and small enough that the procedure does not take *forever* to complete

Possibly the multiple execution group is...

This is a bit of a random guess, but a for loop can only extend acros a single execution group (AKAIK). So if your original code extends across multiple execution groups, then a simp;e cut and paste won't work. If your code has mutiple execution groups, then try selecting all of the code you need for the body of your "for" loop and use

Edit->Split or Join->Join Execution Group

to create this code within a single execution group

Having done this, put a

for........do

****body****

end do

wrapper around the result

Well you can fake it a bit...

Your basic problem is that by using the quantity 1.5 - ie a float - then you are implicitly telling Maple to do floating point arithmetic. For your specific example, you can get (more or less) the answer you want by

restart;
y:=x->(3/2)^x:
diff(y(x),x);

Of course this will only work when the coefficient can written as a rational :-(

But not the answer you want?...

indets(EQ);

to the end of your worksheet, Maple tells me that the unknowns in EQ are

Luckily if I check the number of equations in EQ by using

numelems(EQ);

It returns 11 - meaning that you have 11 equations in 11 unknowns - so looking good so far. However if I try to solve this system of equtions for the unknowns, using

fsolve(EQ, indets(EQ));

then Maple returns

{P = -2.214980447207460142384437982552893015581,
b[1] = 0., b[2] = 0., b[3] = 0., b[4] = 0., b[5] = 0., b[6] = 0., b[7] = 0., b[8] = 0., b[9] = 0., b[10] = 0.}

Although I have no doubt that this answer is correct, I have the strangest feeling that it is not the answer you want!

Not sure what you mean by "I cannot put the ruler on the sides of my worksheet". Maple does not have rulers on for its worksheets. If you want to change the size of a plot, just select it (mouse right-click) and then drag the appropriate window handle

If you want to do this in a somehat more programmatic way, then you can use the 'size' option to the plot command. Consider the following

plot(x^2, x=-10..10, color=red, size=[0.5,"square"]);

This will produce a plot whose size is given by a fraction of your screen size - in the above case, about 1/2. Any number less than 10 will be interpreted as a multiplier on monitor size, so

plot(x^2, x=-10..10, color=red, size=[2,"square"]);

will produce a plot which is around twice the size of you screen and "scroll bars" will appear on your Maple window, so that you can move around the whole plot.

The way Maple interprets the first numerical argument to the size option is as follows

1. If it is less that 10, then it is a multiplier on you monitor size
2. If it is greater then 10, it is interpreted as a fixed number of pixels

Thus if you want to produce the same plot in 5 different sizes, run the following

restart;
for j from 0.2 by 0.2 to 1 do
plot(x^2, x=-10..10, color=red, size=[j,"square"]);
od;

The default size which Maple uses seems to be around 0.25, which you can see by comparing the output of

plot(x^2, x=-10..10, size=[0.25,"square"]); # specified size
plot(x^2, x=-10..10); # default size

The second entry to 'size' opotion controls the shape (ie aspect ratio) of the plot window. I advise you to read the size entry in the plot options - see ?plot/option

Oh dear...

What do you hope to gain when someone does your homework for you???

The more intersting part of you problem is the part

Use the IVT to prove existence of a root to the equation x^3 +10x^2 -100x +50=0 in the interval [-20,10]. Use again the IVT to show that there is a 1st root in [-17,-15], a 2nd toot in [0,1] and a 3rd root in [ 5,6].

If you can do this, then you will get most of the marks available: becuase the final part

Find or approximate those roots with Maple. (the bolded is what I need help).

is trivial. In fact it is so trivial that in this case I don't mind doing your homework - you just have to bea ble to explain why it works, because I'm not going to

f:= x-> x^3 +10*x^2 -100*x +50:
r:=-20:
for i from 1 to 3 by 1 do
r:=RootFinding[NextZero](f, r);
od;

 First 97 98 99 100 101 102 103 Last Page 99 of 110
﻿