tomleslie

13876 Reputation

20 Badges

15 years, 175 days

MaplePrimes Activity


These are answers submitted by tomleslie

The code

expr:=1/x*sqrt(x*y);
hastype(expr, radical);
expr:=3*(x*y)^(2/3)+5;
hastype(expr, radical);
expr := sqrt(5);
hastype(expr, radical);
expr:=3+sin(x);
hastype(expr, radical);

returns true, true, true, false

is to use the plottools:-rotate() command. See the last execution group in the attached

restart; with(plots); L := 1

F1 := plot(0.25e-1-sqrt(0.25e-1^2-(x-0.25e-1)^2), x = 0 .. 0.25e-1*L, scaling = constrained); F2 := plot(0, x = 0.25e-1*L .. .25*L, scaling = constrained); F3 := plot(sqrt(0.5e-1^2-(x-.3)^2), x = .25*L .. .35*L, scaling = constrained); F4 := plot(0, x = .35*L .. .42*L); F5 := plot(-sqrt(0.3e-1^2-(x-.45)^2), x = .42*L .. .48*L, scaling = constrained); F6 := plot(0, x = .48*L .. .975*L, scaling = constrained); F7 := plot(0.25e-1-sqrt(0.25e-1^2-(x-.975)^2), x = .975*L .. L, scaling = constrained); BW := display(F1, F2, F3, F4, F5, F6, F7, size = [400, 400], scaling = constrained); display(F1, F2, F3, F4, F5, F6, F7, size = [400, 400], scaling = constrained)

 

 

 

 

 

 

 

 

F8 := plot(-4.475+4.5*x, x = L .. 1.05*L, scaling = constrained); F9 := plot(4.975-4.5*x, x = 1.05*L .. L, scaling = constrained); BW := display(F1, F2, size = [400, 400], scaling = constrained); display(F1, F2, F3, F4, F5, F6, F7, F8, F9, size = [400, 400], scaling = constrained)

 

 

 

 

F10 := plot(.475+sqrt(0.25e-1^2-(x-.975)^2), x = .975*L .. L, scaling = constrained); F11 := plot(.5, x = 0.25e-1*L .. .975*L, scaling = constrained); F12 := plot(.475+sqrt(0.25e-1^2-(x-0.25e-1)^2), x = 0 .. 0.25e-1*L, scaling = constrained); BW := display(F10, F11, F12, size = [400, 400], scaling = constrained); display(F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, size = [400, 400], scaling = constrained)

 

 

 

 

F13 := plot(-0.2e-1*sin(6*Pi*y), y = 0.25e-1*L .. .475*L, scaling = constrained); BW := display(F13, size = [400, 400], scaling = constrained); display(F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, size = [400, 400], scaling = constrained)

 

 

F13 := plottools:-rotate(plot(-0.2e-1*sin(6*Pi*y), y = 0.25e-1*L .. .475*L, scaling = constrained), (1/2)*Pi); BW := display(F13, size = [400, 400], scaling = constrained); display(F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, size = [400, 400], scaling = constrained)

 

 

 


 

Download rotPlot.mw

straight from the first example on the Maple help page accessed by ?Iterative Maps, Bifurcation, that would be the code shown in tha attached.

For some reason, the resulting image does not display here - but it will if you execute the attached in a Maple worksheet, hen you will get the desired image

with(IterativeMaps):
with(ImageTools):
Logistic:=Bifurcation( [x], [r*x*(1-x)], [0.5], 2.5, 4 ):
ArrayTools:-Dimensions( Logistic );
ColouringProcedures:-HueToRGB( Logistic ):
Embed( Logistic );

[1 .. 500, 1 .. 500, 1 .. 3]

(1)

 

Download logistic.mw

If you wish to 'hardiwire' the current values in 'Data' into the function Diameters when you define the latter, then

Data := [L=1000, F=1000, E=206000, d0=10];
Diameters:= unapply( eval(piecewise(x<L/2, d0 ,x<2/3*L, 2*d0 ,x>2/3*L, 1.5*d0), Data), x)

is a better option

The most obvious (but undesirable) way to do this is proabably

  restart;
  A:={};
  for k from 1 by 1 to 5 do
      A:= A union {k};
  od;

This is bad practice because sets are not "mutable" - every time you add an element to a set, you are actually creating a new copy of the set, so it is very inefficient, and henc a bad habit to adopt. (For "small" sets, you *proabbly won't see much impact)

A better(?) way in Maple (versions 2016 and later) is to use the MutableSet() command, as in

  restart;
  A:=MutableSet({});
  for k from 1 by 1 to 5 do
        insert(A, k);
  od:
  A;

 

particularly in a restricted range, it is probably safer to use fsolve(), as in the attached

restart;
equations := S-P*S*((ln(-2*d*w+P+d)-ln(P-d))*(P-d)/(-1+w)+(P+d)*(ln(-P-d)-ln(d*(2*w-1)-P))/w)/(2*d^2) = 0;
plot( eval( lhs(equations),
            {P = 1/2, S = 1, d = 1/10}
          ),
      w = 0 .. 1
    );
fsolve( eval( equations,
              [P = 1/2, S = 1, d = 1/10]
            )
      );

S-(1/2)*P*S*((ln(-2*d*w+P+d)-ln(P-d))*(P-d)/(-1+w)+(P+d)*(ln(-P-d)-ln(d*(2*w-1)-P))/w)/d^2 = 0

 

 

.4492863635

(1)

``

Download getRoot.mw

 

solve([a+b, c+b]);
numelems([%]);
solve([a+b, -b^2+c^2]);
numelems([%]);
                     {a = c, b = -c, c = c}
                               1
         {a = -c, b = c, c = c}, {a = c, b = -c, c = c}
                               2

 

Roots of a cubic equation will be returned using the solve() command

The nature of these roots, for various values of the discriminant are explained here https://en.wikipedia.org/wiki/Discriminant

I'm not sure that this is the best place to gain understanding of basic mathematics - I still favour a textbook for that!. However you *might* gain some insight if you replace the procedure

f := proc(x, y, z)
    (x^2 + y^2 + z^2)^2
end proc;

in your worksheet with

f := proc(x, y, z)
      1
end proc;

Do you recognise the returned value of 'soln'?

If one restricts the problem to matrices with real eigenvalues, then this can be achieved.

However, since one is varying at least one matrix entry, it is "awkward" to ensure that eigenvalues *stay* real, unless the starting matrix is restricted to be of a cerain type - eg symmetric. However with this restriction, it is relatively easy to generate plots showing how the eigenvalues and eigenvectors (plotted as spacecurves) vary as a function of the parameter. See the attached

realEV.mw

 

It is *possible* to do something similar for the general case - ie where both eigenvalues and eigenvectors are allowed to be complex. The complexplot() command can be used to display how the eigenvalues vary in the complex plane as a function of the parameter.

However it is more difficult to come with a meaningful(?) way of representing complex eigenvectors, since functions in C3 cannot be plotted in R3. The best(?) I could think of, was to use two spacecurves for the real and imaginary parts of each eigenvector. These plots can get a little "messy" and difficult to interpret since any given eigenvalue/eigenvector may fluctuate between real and complex as the parameter i changed. For what it is worth, a worksheet which handles(?) this case is attached

complexEV.mw

For both of these sheets (particularly) the latter), the output can be difficult to interpret for some input matrices. Can only suggest that you re-execute (which will give you a new matrix each time), until "smooth" curves are obtained: these are simpler to grasp, and will probably assist your understanding of the more complicated cases

Use a fairly simple select() command, as in the attached

I commented out a few things in your worksheet which aren't very relevant

NB I did this in Maple 2018. You are using Maple 7 which was superseded in 2002. I cannot guarantee that the following will *work* in a Maple version which is 16 years old. My installed versions only go back about 5 years:-(

restart:
#interface(imaginaryunit, errorbreak=0, errorcursor=true, #labelling=false):
#with(SolveTools);

# Investigating sets and expression sequences
#S:={q, w,e}:
S:=7,2,5:
whattype(S);
#L4:=convert(S,list):  #Doesn't work for expression sequences
L4:=[S]; # this converts the expression sequence to a list, L4
L4[3];   # outputs 3rd element of L4 which is 5
# End of investigation

#print(`Next part - solving two equations:  Ranj and height H given`);
#print(`To find angle of inclination, alfa, and velocity, V`);  
g:=9.81:Ranj:=80:H:=15:
L:=solve({4*V^2*cos(alfa)^2-g*Ranj^2/(Ranj*tan(alfa)-2*H), Ranj*g-V*sin(2*alfa)},{V, alfa}):  #::real}):
#L:=solve([4*V^2*cos(alfa)^2-g*Ranj^2/(Ranj*tan(alfa)-2*H), #Ranj*g-V*sin(2*alfa)],{V, alfa}):  #::real}):
# ::real, alfa::real:
#printf("L is of type %a", whattype(L));
#whattype(L);
#L2:=convert(L,list);  #gives error message
#L2:=[L]:
# L2;
# print(`Next:  To distinguish between real and complex solutions`);
# print(`Output in if statement is not working as expected.`);
# nops([L]);
# for i from 1 to nops([L]) do
#   if type(L[i],complex(float)) then
#         #if type(L[i],nonreal) then
#   printf("Complex solution for i=%d\n",i);
#                         else
#   printf("else part of if: i=%d\n",i);
#    print( L[i]);
#  end if;
# end do;  #for
#
##################################
# get the real solutions
#
  select( i->type~(rhs~(i),realcons)[], [L]);

exprseq

L4 := [7, 2, 5]

5

[{V = 1193.173195, alfa = .3589084910}, {V = 1193.173195, alfa = -2.782684163}]

(1)

 

Download getReal.mws

of starting a (possibly-tangential?) argument.

In Maple 2016 the MutableSet() command was introduced. This data structure appears to allow all of the operations you require, and promises to do them "efficiently".

  1. It is certainly much more 'efficient' than the basic set {} when performing 'mutations'. See the test on the ?MutableSet help page
  2. It *seems* to allow all "normal" set operations eg intersect, union, minus, subset etc, although you can't (in general?) mix-and-match ordinary and mutable sets
  3. I haven't used this data structure extensively, but on the few occasions where it was appropriate, I don't recall any significant "issues".
  4. The one area where one can anticipate problems is with commands which take a normal set as an argument - eg the 'sys' argument to dsolve(). In general these will not accept a MutableSet() - although obviously convert(...,set) can be used. I view this as a trade-off: occasional use of convert() in a program is OK, extensive use of convert() indicates that I picked the wrng data container in the first place!

It is of course true that one really shouldn't use sets (mutable or otherwise) unless one has decided that it is definitely the optimal data container. 1-D arrays will almost always be better bet

seems to be functional.

Not quite sure why one has to use separate dsolve() commands, just because the ODEs are uncoupled

restart

with(student)

with(ODETools)

PDEtools[declare](u(y), theta(y), prime = y)

` u`(y)*`will now be displayed as`*u

 

` theta`(y)*`will now be displayed as`*theta

 

`derivatives with respect to`*y*`of functions of one variable will now be displayed with '`

(1)

N := 1; H__a := 6; D__a := 5; G__r := 4; R__e := 1; R__d := .1; `&theta;__R` := .2; `&theta;__&infin;` := .2; Q := .2; R__e0 := .3; Lambda := .2; lambda := 1; P__r := .72; A := 0; `&beta;__1` := .1; `&beta;__2` := .1

u(y):=sum((p^(i))*u[i](y),i=0..N):

theta(y):=sum((p^(i))*theta[i](y),i=0..N):

Eq1 := diff(u(y), `$`(y, 2))-(H__a^2+1/D__a)*u(y)+G__r*(theta(y)+`&theta;__&infin;`)/R__e-R__e0*(diff(u(y), y))-A

diff(diff(u[0](y), y), y)+p*(diff(diff(u[1](y), y), y))-(181/5)*u[0](y)-(181/5)*p*u[1](y)+4*theta[0](y)+4*p*theta[1](y)+.8-.3*(diff(u[0](y), y))-.3*p*(diff(u[1](y), y))

(2)

Eq2 := diff((1+(4/3)*R__d*(theta(y)*(`&theta;__R`-1)+1)^3)*(diff(theta(y), y)), y)-P__r*R__e0*(diff(theta(y), y))+Q*R__e*(Lambda*exp(-lambda*y)+theta(y)+`&theta;__&infin;`)

HPMEq1 := (1-p)*(diff(u(y), `$`(y, 2))+G__r*`&theta;__&infin;`/R__e-A)+p*Eq1

HPMEq2 := (1-p)*(diff(theta(y), `$`(y, 2))+Q*R__e*(Lambda*exp(-lambda*y)+`&theta;__&infin;`))+p*Eq2

for i from 0 to N do
    equ1[i] := coeff(HPMEq1, p, i) = 0;
    equ2[i] := coeff(HPMEq2, p, i) = 0;
    cond[i] := u[i](-1) = -beta__1*(D(u[i]))(-1),
               u[i](1) = -beta__2*(D(u[i]))(1),
               theta[i](-1)=0,
               theta[i](1)=0:
    S1[i]:=dsolve({equ1[i],cond[i][1..2]}):
    S2[i]:=dsolve({equ2[i],cond[i][3..4]}):
    theta[i]:= unapply(rhs(S1[i]),y):
    u[i]:= unapply(rhs(S2[i]),y):
end do;

diff(diff(u[0](y), y), y)+.8 = 0

 

diff(diff(theta[0](y), y), y)+0.4e-1*exp(-y)+0.4e-1 = 0

 

u[0](-1) = -.1*(D(u[0]))(-1), u[0](1) = -.1*(D(u[0]))(1), theta[0](-1) = 0, theta[0](1) = 0

 

u[0](y) = -(2/5)*y^2+(2/25)*y+49/125

 

theta[0](y) = -(1/50)*y^2-(1/25)*exp(-y)+((1/50)*exp(-1)-(1/50)*exp(1))*y+1/50+(1/50)*exp(1)+(1/50)*exp(-1)

 

proc (y) options operator, arrow; -(2/5)*y^2+(2/25)*y+49/125 end proc

 

proc (y) options operator, arrow; -(1/50)*y^2-(1/25)*exp(-y)+((1/50)*exp(-1)-(1/50)*exp(1))*y+1/50+(1/50)*exp(1)+(1/50)*exp(-1) end proc

 

diff(diff(u[1](y), y), y)+1.436000000*exp(-y)+.8440000000-(219/250)*y^2-(181/5)*((1/50)*exp(-1)-(1/50)*exp(1))*y-.7180000000*exp(1)-.7300000000*exp(-1)+.3320000000*y = 0

 

diff(diff(theta[1](y), y), y)+0.611200000e-1+.3999999999*(.3200000000*y^2-0.6400000000e-1*y+.6864000000)^2*(.6400000000*y-0.6400000000e-1)*(-(4/5)*y+2/25)-.1066666666*(.3200000000*y^2-0.6400000000e-1*y+.6864000000)^3+.1888000000*y-0.8000000000e-1*y^2 = 0

 

u[1](-1) = -.1*(D(u[1]))(-1), u[1](1) = -.1*(D(u[1]))(1), theta[1](-1) = 0, theta[1](1) = 0

 

u[1](y) = (1/2)*(-211/250+(359/500)*exp(1)+(73/100)*exp(-1))*y^2-(83/1500)*y^3+(73/1000)*y^4+(181/1500)*y^3*exp(-1)-(181/1500)*y^3*exp(1)-(359/250)*exp(-y)+(829/7500-(224/375)*exp(1)+(1697/3750)*exp(-1))*y+26591/75000+(5747/15000)*exp(1)+(14981/75000)*exp(-1)

 

theta[1](y) = (18666666661/42724609375000)*y^8-(18666666661/53405761718750)*y^7+(5879999998093/1525878906250000)*y^6-(17266666661059/7629394531250000)*y^5+(7023382248292087/366210937500000000)*y^4-(33253033748336767/915527343750000000)*y^3-(156614659133061643/12207031250000000000)*y^2+(249515236232966929/6408691406250000000)*y-2727299731655790397/256347656250000000000

 

proc (y) options operator, arrow; (1/2)*(-211/250+(359/500)*exp(1)+(73/100)*exp(-1))*y^2-(83/1500)*y^3+(73/1000)*y^4+(181/1500)*y^3*exp(-1)-(181/1500)*y^3*exp(1)-(359/250)*exp(-y)+(829/7500-(224/375)*exp(1)+(1697/3750)*exp(-1))*y+26591/75000+(5747/15000)*exp(1)+(14981/75000)*exp(-1) end proc

 

proc (y) options operator, arrow; (18666666661/42724609375000)*y^8-(18666666661/53405761718750)*y^7+(5879999998093/1525878906250000)*y^6-(17266666661059/7629394531250000)*y^5+(7023382248292087/366210937500000000)*y^4-(33253033748336767/915527343750000000)*y^3-(156614659133061643/12207031250000000000)*y^2+(249515236232966929/6408691406250000000)*y-2727299731655790397/256347656250000000000 end proc

(3)

 

Download odeIter.mw

 

you want to add 273 to the enries in the second column (without dealing with units), then the following will work

   restart;
#
# Generate a random matrix for test purposes
#
   with(LinearAlgebra):
   M:=RandomMatrix(10,3);
#
#  Add 273 to every entry in column 2
#
   M[..,2]:=273+~M[..,2]:
#
# Display result
#
   M;

 

  1. A rectangle is defined by two points
  2. A point is defined by two coordinates
  3. Therefore a rectangle is defined by four values - think bottom -left-corner (x1,y1) and top-right -corner (x2,y2)
  4. So for 21 rectangles, all I need is a 21x4 matrix, where the entries in each row represent x1, y1, x2, y2

Given the appropriate 21x4 matirx, the attached will generate/plot the rectangles.

NB since you don't provide them, I have generated the coordinates for the rectangles as a random matrix

I could make all the rectangles different colors,different linestyles etc, but let's fix the basics first

restart;
with(LinearAlgebra):
with(plots):
with(plottools):
M:=RandomMatrix(21, 4):
display( [ seq
           ( rectangle
             ( [M[i,1], M[i,2]],
               [M[i,3], M[i,4]],
               style=line
             ),
             i=1..21
           )
         ],
         axes=none
       );

 

 

 

Download genRect.mw

First 130 131 132 133 134 135 136 Last Page 132 of 207