das1404

135 Reputation

6 Badges

12 years, 53 days

MaplePrimes Activity


These are questions asked by das1404

seq(i,i=1..5);  gives output 1,2,3,4,5

seq(i,i=5..1);  seems to get ignored in Maple 7.  It does not return an error message.

I was hoping to step back from a large number to a smaller one in stepsof minus one.  The for loop structure allows negative "increments" - so I experimented by putting the decrement value of -1 between the two dots.  I was expecting it to givean error message, so was surprisd when it gavesome output!

eg  seq(i, i=5.-1.2);  gives output of 38, -1

I'm curious as to what is happening here?  Also, has the seq command been upgraded in later versions of Maple?  eg is it possible to do negative decrements?

Description of program: To try to find 'similar shaped' words.  eg the word 'qwirky' is similar to 'ywivhg' because q, y and g have downstrokes and h, k have an 'upstroke'.  ..at present the 'words' are not words in the dictionary sense.

   I have posed several questions throughout the program, but will focus on the most puzzling which is in the last section of the program, reproduced below.  The variable ii is set at 1 - relating to the first letter, q, of the 'word' qwirky. It correctly outputs the list, listy[4], which contains the letter q.  Similarly if ii is set to 2 it ouputs listy[8] - w.  However when ii is set to 3, it ouputs the number 7, when listy[7] (=[i]) was expected.  Values of ii from 4 to 6 (thelength of 'qwirky') work as expected.  Ideally I would like to dispense with  the ii:=1 statement, and uncomment the for .. do loop:

> for ii from 1 to nops(letters) do
> seq(listy[listsuffix[  Ord(letters[ii] )-96] ][kk], kk=1..nops(listy[listsuffix[Ord(letters[ii] )-96] ]) );
> end do:

  Another question was how to incorporate the sequence, seq() statement in a printf statement - but that's enough for now!!:-)

    After reading thris through and seeing theTags, I see I have used a variable 'letters' in my program - perhaps this is causing problems?  I initially thought Maple had a bug in it - but probably a common thought by students!:-)

 ##End part of program  

> ii:=1:   #####Try putting equal to 2, 3, 4, 5, 6
> #ii:=2 returns w - which is correct, but ii:=3 returns 7 when i is expected. Values 4 to 6 work OK
> printf("List of the listy which contains the particular letter, %d  of 'qwirky'  ie the letter %s",ii, letters[ii]);
> printlevel:=5:
> printf("Nops(word)=%d  nops(letters)=%d\n",nops(word),nops(letters));
> #for ii from 1 to nops(letters) do
> seq(listy[listsuffix[  Ord(letters[ii] )-96] ][kk], kk=1..nops(listy[listsuffix[Ord(letters[ii] )-96] ]) );
> #end do:

Thanks, David S

START of MAPLE PROGRAM here

# Similar Words - idea is to create words which look similar in shape to other words
> restart:
> with(StringTools):
> #abcdefghijklmnopqrstuvwxyz
> #a  c, e, o, s, u, x, z
> #b  d, h, k,
> #f  l, t
> #g  j, p, q, y
> #i
> #m  n
> #r  v
> #w
>
> #  Take a word eg 'qwirky' & make words which appear similar -
>
> word:="qwirky":
> numLetters:=length(word):
> printf("Length of word is %d",length(word));
> printf("Why is the length of x+2*y equal to %d - as opposed to just 5?",length(x+2*y));
> printf("Is it because x and y each take up 3 'storage locations' - and one each for +2* ?");  
>
> # Help says:For other objects, the length of each operand of expr is computed recursively and added to the number of words used to represent expr. In this way, the measure of the size of expr is returned.
> #...but I'm not much wiser!:-(
> #I ended up using 'nops' instead, but not sure which is better.
> listy[1]:=[a,c,e,o,s,u,x,z]:
> #printf("Number of letters in listy[1] seq(%s, kk=1..nops(listy[1]))   is %d\n",seq(listy[1][kk], kk=1..nops(listy[1])));
> printf("The previous printf statement - commented out - does not work.  The one below does\n - but that's because I've put in eight 'per cents'\n - I'd like the program to work this out.\n");    
>
> printf("Number of letters in listy[1] %s,%s,%s,%s,%s,%s,%s,%s is %d\n",seq(listy[1][kk], kk=1..nops(listy[1])  ),nops(listy[1]) );
> listy[2]:=[b, d, h, k]:
> listy[3]:=[f, l, t]:
> listy[4]:=[g, j, p, q, y]:
> listy[5]:=[m, n]:
> listy[6]:=[r, v]:
> listy[7]:=[i]:
> listy[8]:=[w]:
> #Which list number, for each letter of the 26 letters?
> #Nos below correspond to a, b,c... ..z
> listsuffix:=[1,2,1,2,1,3,4,2,7,4,2,3,5,5,1,4,4,6,1,3,1,6,8,1,4,1]:
> #printf("listsuffix[12]=%d",listsuffix[12]);
> #printf("listy[4][2]=%s",listy[4][2]);
> printf("Ascii number of Second letter in list 4 is %d",Ord(listy[4][2]));
> printf("Second letter in list 4 is %s",Char(Ord(listy[4][2])));
> #printf("listsuffix[listy[4][2]]=%d",listsuffix[listy[4][2]]);
> #Split into a list of letters
> letters:=convert(word, list):
> #Consider the letters close to the letters - go through all combinations and check to see if any match words in the dictionary.
> #printf("1");
> #printf("%d",Ord(letters[2]));
> #printf("2");
> #printf("Suffix number is %d",listsuffix[Ord(letters[2])-71]);
> #printf("3");
> for i from 1 to length(word) do
> #See which list letter belongs to
> #printf("Letter number %d, %A belongs to list %d\n",i,letters[i],listsuffix[Ord(letters[i])-96]);
> printf("Ascii number of letter number %d, %s in list %d is %d\n",i,letters[i],listsuffix[Ord(letters[i])-96],Ord(letters[i]));
>
> #printf("Ascii number of letter number %d, %s is %d in list %d which is \n",i,letters[i],Ord(letters[i]),listsuffix[Ord(letters[i])-96]);
> #printf("Below may not work");
> #printf("Ascii number of letter number %d, %s is %d in list %d which is seq(%s, kk=1..nops(listy[listsuffix[Ord(letters[ii] )-96] ]) ))\n",i,letters[i],Ord(letters[i]),listsuffix[Ord(letters[i])-96],seq(listy[listsuffix[  Ord(letters[ii] )-96] ][kk], kk=1..nops(listy[listsuffix[Ord(letters[ii] )-96] ]) ) );
>
> #Check out all letters in list, listy[listsuffix[Ord(letters[i])-96]
>
> #seq(  listy[  listsuffix[  Ord(letters[i] )-96]  ], 1..length(listy[                listsuffix[  Ord(letters[i] )-96]);
> #seq(listy[listsuffix[  Ord(letters[ii] )-96] ][kk], kk=1..nops(listy[listsuffix[Ord(letters[ii] )-96] ]) )
> end do:
> #seq(listy[2][kk], kk=1..4);
> #List of listy[2]
> printf("List of listy[2] below:");
> seq(listy[2][kk], kk=1..nops(listy[2]));
> #List of the listy which contains the particular letter of 'qwirky'
> ii:=1:   #####Try putting equal to 2, 3, 4, 5, 6
> #ii:=2 returns w - which is correct, but ii:=3 returns 7 when i is expected. Values 4 to 6 work OK
> printf("List of the listy which contains the particular letter, %d  of 'qwirky'  ie the letter %s",ii, letters[ii]);
> printlevel:=5:
> printf("Nops(word)=%d  nops(letters)=%d\n",nops(word),nops(letters));
> #for ii from 1 to nops(letters) do
> seq(listy[listsuffix[  Ord(letters[ii] )-96] ][kk], kk=1..nops(listy[listsuffix[Ord(letters[ii] )-96] ]) );
> #end do:

#####  END of program.   Below is output for Maple 7   ##########


Warning, the assigned name Group now has a global binding

Length of word is 6
Why is the length of x+2*y equal to 9 - as opposed to just 5?
Is it because x and y each take up 3 'storage locations' - and one each for +2* ?
The previous printf statement - commented out - does not work.  The one below does
 - but that's because I've put in eight 'per cents'
 - I'd like the program to work this out.
Number of letters in listy[1] a,c,e,o,s,u,x,z is 8
Ascii number of Second letter in list 4 is 106
Second letter in list 4 is j
Ascii number of letter number 1, q in list 4 is 113
Ascii number of letter number 2, w in list 8 is 119
Ascii number of letter number 3, i in list 7 is 105
Ascii number of letter number 4, r in list 6 is 114
Ascii number of letter number 5, k in list 2 is 107
Ascii number of letter number 6, y in list 4 is 121
List of listy[2] below:
                                          b, d, h, k
List of the listy which contains the particular letter, 1  of 'qwirky'  ie the letter q
{--> enter printf, args = "Nops(word)=%d  nops(letters)=%d\n", 1, 6
Nops(word)=1  nops(letters)=6
                                              30
<-- exit printf (now at top level) = }
{--> enter StringTools:-Ord, args = "q"
                                             113
<-- exit StringTools:-Ord (now at top level) = 113}
{--> enter StringTools:-Ord, args = "q"
                                             113
<-- exit StringTools:-Ord (now at top level) = 113}
{--> enter StringTools:-Ord, args = "q"
                                             113
<-- exit StringTools:-Ord (now at top level) = 113}
{--> enter StringTools:-Ord, args = "q"
                                             113
<-- exit StringTools:-Ord (now at top level) = 113}
{--> enter StringTools:-Ord, args = "q"
                                             113
<-- exit StringTools:-Ord (now at top level) = 113}
{--> enter StringTools:-Ord, args = "q"
                                             113
<-- exit StringTools:-Ord (now at top level) = 113}
                                        g, j, p, q, y

Am trying to create a gif file of  a cantilevered door opening with the aid of a coil spring.  The program is given below in text format.  At the end is a for/do loop which gives a series of pictures of the side view of the door opening.  I'd like to animate these and be able to create a gif file. The use of animate seems to require a function F(x,t) of two variables - one being time. My calculations do not involve time.  Any help gratefully received.

 

restart;
> with(plots): with(plottools):
> #Problems:
> #gif file???  Use of animate
> # - - - - - - -
> printlevel:=0:
> #h=doorheight;  h1=dist from floor to pivot point; base=dist of cantilever #connection to end of garage door
> h:=206:h1:=115:
> doorheight:=h:
> base:=24:
> #Spring data
> sbase:=0.4*base:  #sbase is height of base of spring connection point
> #Lower & upper proportions of spring length as ratio of spring length
> propn1:=0.2: propn2:=0.95:  #propn2 > propn1
> #alpha is inclination angle of coils in the spring
> alpha:=Pi/6:
> #nc is Number of Coils in Spring
> nc:=24:   #92 in my actual spring
> #Garage door (closed position lightly shown)
> gdupright:=line([0,0],[0,h], linestyle=2, color=grey):
> #cr is Cantilever Radius
> cr:=h1-base:
> #Counter-balance extension length is cr_ext
> cr_ext:=12:  # 62
> doorwidth:=0.05*h:
> guidewidth:=doorwidth*1.015:
> #macro(skyblue = COLOR(RGB, 0.1960, 0.6000, 0.8000));
> macro(palegreen=COLOR(RGB, .5607, .7372, .5607)):
> #g1 (top) & g2 are guides for door support
> #g_ext is guide extension proportion of guides above the door
> g_ext:=0:  
> g1:=line([-doorwidth/2,doorheight*(1+g_ext)+guidewidth],[doorheight*(1+g_ext),doorheight*(1+g_ext)+guidewidth], color=palegreen):
> g2:=line([-doorwidth/2,doorheight*(1+g_ext)],[doorheight*(1+g_ext),doorheight*(1+g_ext)], color=palegreen):
> garagefloor:=line([-h*.65,0],[doorheight,0], color=black):
> rooflevel:=line([-h*.65,(1.05+g_ext)*h+guidewidth],[doorheight,(1.05+g_ext)*h+guidewidth], linestyle=2,color=grey):
> #Pivot point - pivpoint
> pivp_x:=0.019*h:   #doorwidth:
> #printf("pivp_x= %8.2f doorwidth= %7.1f\n",pivp_x,doorwidth):
> pivpoint:=circle([pivp_x,h1],doorwidth/2, color=red): #doorwidth/2 for radius - #use cr to check
> #mpp is mid point of rotation
> mpp := point([pivp_x,h1], color=black):
> #connect_point[j]:=circle([pivp_x+cr_ext*sin(theta),h1+cr_ext*sin(theta)],doorwidth/2, color=red):
> lastj:=4:    #Number of angle diplays -1 (for 0)
> #printf("Rotation Angle of cantilever (degrees) & distance along the guide arm (cm)  hc   kc"):
> # - - - - - - - - - - - - - -
>
> for j from 0 to lastj do
>
> theta:=j*Pi/lastj:
> # hc was changed from cr*sin(theta)
> hc:=pivp_x-cr*sin(theta):kc:=h1-cr*cos(theta):
> x:=pivp_x-cr*sin(theta)+sqrt((h-base)^2-(h-kc)^2):
> #printf("%8.2f %7.1f    %5.2f   %5.2f\n",theta*180/Pi,x,hc,kc);
> if j=lastj then phi:=Pi/2:
>  else
> phi:=arctan((cr*sin(theta)+x-pivp_x)/(cr*(1+cos(theta))));
> end if:
> #Sides of door, starting at NW corner & going anti-clockwise
> door1 := line([x-doorwidth*cos(phi),h+doorwidth*sin(phi)],[x,h] , color=black):
> door2 := line([x,h],[x-h*sin(phi),h-h*cos(phi)] , color=black):
> door3 := line([x-h*sin(phi),h-h*cos(phi)],[x-h*sin(phi)-doorwidth*cos(phi),h-h*cos(phi)+doorwidth*sin(phi)], color=black):
> door4 := line([x-h*sin(phi)-doorwidth*cos(phi),h-h*cos(phi)+doorwidth*sin(phi)],[x-doorwidth*cos(phi),h+doorwidth*sin(phi)], color=black):
> #Counter balance arm
> cba:=line([x-(h-base)*sin(phi),h-(h-base)*cos(phi)],[pivp_x+cr_ext*sin(theta),h1+cr_ext*cos(theta)],color=blue):
> #Spring calcs # ???
> spring:=line([pivp_x,sbase],[pivp_x+cr_ext*sin(theta),h1+cr_ext*cos(theta)], linestyle=2, color=grey):
> #Turnbuckle
> tbuck1:=line([pivp_x,sbase],[pivp_x+cr_ext*propn1*sin(theta),sbase+propn1*(h1-sbase+cr_ext*cos(theta))], color=black):
> #for tbuck2 see below - it requires angle chi
> chi:=arctan(cr_ext*sin(theta)/(h1-sbase+cr_ext*cos(theta))):
> tbuck2:=arc([pivp_x,sbase],doorwidth/6,Pi/2-chi..3*Pi/2+.2, color=blue):
> #sl is spring length (l is the letter L lower case)
> sl:=sqrt(cr_ext^2+(h1-sbase)*((h1-sbase)+2*cr_ext*cos(theta))):
> for i from 0 to nc do
> x1[i]:=pivp_x+(propn1+(propn2-propn1)*i/nc)*sl*sin(chi):
> y1[i]:=sbase+(propn1+(propn2-propn1)*i/nc)*sl*cos(chi):
> connect_point:=circle([pivp_x+cr_ext*sin(theta),h1+cr_ext*cos(theta)],doorwidth/4, color=blue):
> printlevel:=1:
> #printf("x[%g] = %8.2f  y[%g] = %8.2f theta = %8.2f chi = %8.2f\n", i,x[i],i,y[i],theta*180/Pi,chi*180/Pi);
> #####---PRINT STATEMENT  (NB 2 #)
> #printf("i=%g x = %4.2f  y = %5.2f theta = %6.3f chi = %7.3f  Sp len=%5.3f\n",
> #i, x1[i],y1[i],theta*180/Pi,chi*180/Pi,sl);
>
> s_coil[i]:=line([x1[i]-doorwidth/2,y1[i]-doorwidth/2*tan(alpha-chi)], [x1[i]+doorwidth/2,y1[i]+doorwidth/2*tan(alpha-chi)], color=blue):
> end do:
> #Coords of end of spring (& counter-balance arm) are #[pivp_x+cr_ext*sin(theta),h1+cr_ext*cos(theta)]
> #Line from top of spring to kicker bolt
>
> #connectline[j]:=line([pivp_x+cr_ext*sin(theta),h1+cr_ext*cos(theta)], #[x1[nc]+doorwidth/2,y1[nc]+doorwidth/2*tan(alpha-chi)], color=green):
>
> printlevel:=-1:
> frame[j]:=plots[display](door1,door2,door3,door4,garagefloor,rooflevel,g1,g2,gdupright,pivpoint,cba,mpp,connect_point,seq(s_coil[i],i=0..nc), tbuck1,tbuck2, scaling=constrained, axes=none):
> end do;
> # - - - - - - - - - - - - - -
> printlevel:=1:
> for j from 0 to lastj do
> frame[j];
> end do;
> # - - - - - - - - -
> animate( frame[j],j=0..lastj,t=1..2,frames=50);

Program:

restart;

printlevel:=3:

for a from 3 to 30 do

   for b from 23 to 30 do

       for k from b to 30 do

         for d from 4 to 30 do

            for e from 10 to 30 do

  big:=max(sqrt(a^2+b^2), sqrt(k^2+d^2), b+k,e,d+e-a):

  small:=min(sqrt(a^2+b^2), sqrt(k^2+d^2), b+k,e,d+e-a):

First 9 10 11 Page 11 of 11