Doug Meade

 

Doug

---------------------------------------------------------------------
Douglas B. Meade <><
Math, USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
Phone: (803) 777-6183 URL: http://www.math.sc.edu

MaplePrimes Activity


These are answers submitted by Doug Meade

This worksheet creates the following plot, using textplot as I predicted.

NULL

display(
 plot( pts, style=pointline, color=red ),
 textplot( tags, align=[below,right], font = ["times", "roman", 8], color=green ),
 labels=["time (s)", "angle (rad)"],
 tickmarks=[4,DEFAULT],
 title="theta4"
);

 

 

``


(Hmm. In the worksheet I created there are no gridlines. Interesting - and for someone else to investigate.)

Download TaggedPlot.mw

I hope this is useful.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

I don't see the problem.

It took a while for me to figure out how you got the second plot. I assume you did not execute this worksheet in the order in which the commands appear. In particular, I see the definitions of p0, p1, and p2 after the plot. I also see that you load the plots package after the display command. All of this is fine, but makes it harder for someone else to understand what you are doing - and harder for you to come back to this in another session.

You create p0, p1, and p2 with the independent variable ranging from 0.7 to 1.2. This is what Maple shows in the horizontal axis. The vertical axis is chosen, by default, to show everything in each part of each object in the plot. You can override this with the view= option. For example, to force Maple to use use the interval [0,10] in the vertical direction you might use

plot( v0_2, theta=0.7..1.2, view=[DEFAULT, 0..10], ...)

You could replace DEFAULT with 0.7..1.2, or anything else that might be appropriate, but I wanted to show the use of DEFAULT. (You can also use DEFAULT for the vertical range and override the horizontal range.) See the online help for plot,options for more details and examples.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

From the code in your post, each iteration through the loop creates an equation. You want to make an assignment. For this you need to use := (not =).

Also, change a[i,g] to a[i,j].

And, refer to a[1,1] and not the subscripted form.

a[1, 1];

1 4 2
- (1 - Zeta) (2 + Zeta)
8

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

Well, from the code that you have posted, you never make use of the values for a, b, c, and d that are assigned to the name "values".

One way of doing this would be to use assign( values ); prior to defining the function F. Be warned that then all references to a, b, c, and d will have these values.

Another option should be to replace f3(x) with eval(f3(x),values) in the definition of F.

I don't have time to completely check these, but they seem like they should work for you.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

1. because your input is a (column) vector; you use the vertical bar to delimit columns:

V := <<aa2[1,1],aa2[2,1],aa2[3,1]>,<aa2[1,2],aa2[2,2],aa2[3,2]>,<aa2[1,3],aa2[2,3],aa2[3,3]>>;
M := <<aa2[1,1],aa2[2,1],aa2[3,1]>|<aa2[1,2],aa2[2,2],aa2[3,2]>|<aa2[1,3],aa2[2,3],aa2[3,3]>>;

2. the Normalize command only works on vectors, not matrices; use the MatrixNorm command to find the norm of a matrix:

LinearAlgebra:-MatrixNorm( M, Euclidean );

3. To normalize a matrix, you might try:

M2 := M / LinearAlgebra:-MatrixNorm( M, Euclidean );

Note that this is not likely to be too informative unless the elements of the matrix are assigned values, even if they are not constants.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

Here's a solution that looks pretty much like the way you were trying to complete your problem. Because it's possible that the second try will also have x>=y, you should be using "do" nstead of "if".

 

Here's one possible instance of your code (with corrected parentheses):

x:=RandomTools[Generate](integer(range=1..7));
y:=RandomTools[Generate](integer(range=1..7));
if x>= y then
  x:=RandomTools[Generate](integer(range=1..7));
  y:=RandomTools[Generate](integer(range=1..7));
end if;
4
4
6
5

Note that we do not have x<y.

Here's the same thing with "if" replaced with "do":

x:=RandomTools[Generate](integer(range=1..7));
y:=RandomTools[Generate](integer(range=1..7));
while x>= y do
   x:=RandomTools[Generate](integer(range=1..7));
   y:=RandomTools[Generate](integer(range=1..7));
end do;
3
1
5
2
3
2
2
4

I hope this helps,

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

Note that you can plot an expression, not an equation. I assume you are really asking how to plot (the left-hand side of) charEq:

P1 := plot( lhs(charEq), r=-5..5 );

Your computations find the real part of each root. To find the real root(s) use:

soln := solve(charEq, r);
soln := remove( has, [soln], I );
soln := evalf(soln, 5);

Then, you can plot this point with

P2 := plot( [ [soln[],0] ], style=point, color=blue );

Then the two plots can be combined with:

plots:-display( [P1,P2] );

I hope this helps.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

I'm not going to dig into the details of this discussion, but do hope to follow it to see where it leads.

As I do have some experience with Maple's numeric ODE solvers, I know you have to be careful. Some of this has changed (improved) over the years, but that means it's even more likely that Maple is not doing exactly what you expect.

sol is the Maple procedure returned by (numeric) dsolve. When you reference sol(0.782), what exactly do you think Maple is doing?

  1. run numerical algorithm from original time, here I believe this is t=0, to t=0.782
  2. run numerical algorithm using the last computed result as the initial condition
  3. run numerical algorithm using the closest (previously) computed result at an "earlier" time
  4. run numerical algorithm once, computing all possible values and using a lookup for a specific time

Option 1 is not practical as it would require lots of repetitive computations of the same values over and over.

Option 2 makes some intuitive sense, but assumes you make the calls to sol in an organized and logical manner. If you jump around too much, you increase the likelihood of unnecessarily accumulating errors.

Option 3 would appear to be a smarter option, but comes at the expense of increased storage and search requirements.

Option 4 is, I believe, what many users think Maple does (it's the closest to what we would do with a "traditional" (compiled) programming language.  But, Maple is not compiled so does not know - and cannot know - all the possible times when you will want to know the solution.

If all times

It is not unlikely that these three approaches will lead to different values for sol(0.782). This is even more likely given the piecewise structure of your RHS. Do you do anything to limit the stepsize in a manner that ensures that entire pieces of the RHS are not completely skipped?

So, my answer to your question is YES - but don't assume Maple does exactly what you think it's doing.

The Maple help page for dsolve,numeric,IVP contains more details. See, in particular, the start and startinit options. (startinit=true correspons with Option 1 and startinit=false with Option 3).

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

Here's a procedure that creates all of the matrices that you describe:

MakeBm := proc( N )
  local B, n;
  for n to N do
    B[n] := Matrix( N, 1, (j,k)->`if`(j=n,1.1,1.0) )
  end do;
  return B;
end proc:

and a similar version that creates a specific matrix from this family:

MakeBv := proc( N )
  local B, n;
  for n to N do
    B[n] := Vector( N, j->`if`(j=n,1.1,1.0) )
  end do;
  return B;
end proc:

Note that you are actually computing vectors, which can somewhat simplify the definition of the objects:

MakeB := proc( N, n )
  return Matrix( N, 1, (j,k)->`if`(j=n,1.1,1.0) )
end proc:

 

   
   

M := MakeBm( 10 ):

M[3];

Matrix([[1.0], [1.0], [1.1], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0]])

(1)

V := MakeBv(10):

V[3];

Vector[column]([[1.0], [1.0], [1.1], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0]])

(2)

B3 := MakeB( 10, 3 );

B3 := Matrix(10, 1, {(1, 1) = 1.0, (2, 1) = 1.0, (3, 1) = 1.1, (4, 1) = 1.0, (5, 1) = 1.0, (6, 1) = 1.0, (7, 1) = 1.0, (8, 1) = 1.0, (9, 1) = 1.0, (10, 1) = 1.0})

(3)

 

Download MatrixDefn.mw

You could easily modify any of these to also update the special value assigned within each matrix/vector.

I hope this is helpful.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

When I read this post I immediately saw that ALL Langford sequences of a particular order could be found by recursion. My results confirm that there are no Langford sequences for n=2, 5, 6, or 9, and that there are 2 possible ordering for n=3 and 4, 52 for n=7, and 300 for n=8.

Langford( 3 );

[3, 1, 2, 1, 3, 2], [2, 3, 1, 2, 1, 3]

(1)

Langford( 4 );

[4, 1, 3, 1, 2, 4, 3, 2], [2, 3, 4, 2, 1, 3, 1, 4]

(2)

Langford( 5 );

 

for N from 2 to 9 do

  L[N] := [ Langford( N ) ];

end do:

 

nops~(L);

table( [( 2 ) = 0, ( 3 ) = 2, ( 4 ) = 2, ( 5 ) = 0, ( 6 ) = 0, ( 7 ) = 52, ( 9 ) = 0, ( 8 ) = 300 ] )

(3)

 

The result follows, and is attached for others to improve, if they so desire.

restart;

 

LSrecur := proc( n::nonnegint, N::posint, LS )

  global LL, poss;

  local k, S, Z;

  uses ListTools;

  if n=0 then                          # all numbers placed in list (successful completion)

    LL := LL, LS;

  end if;

  Z := [SearchAll( 0, LS )];

  for k in Z do                        # loop through all unfilled locations in list

    poss := false;                     # need to reset poss for subsequent iterations

    S := LS;

    if k+n+1<=2*N and S[k+n+1]=0 then  # check if possible to place current number in both locations in list

      poss := true;

      S[k],S[k+n+1] := n$2;            # place current number in both locations in list

      S := LSrecur( n-1, N, S );       # look for a possible location for the next (smaller) element

    end if;

  end do;

  if poss then                         # check if list successfully sucompleted

    return S;                          # YES? pass completed list up to calling procedure

  else

    return NULL;                       # NO?  pass nothing up to calling procedure

  end if;

end proc:

Langford := proc( N::posint )

  global LL;

  local k, S, S2;

  LL := NULL;                          # initialize list of all Langford sequences

  for k from 1 to N-1 do               # loop through all possible locations for largest element

    S := [ 0 $ 2*N ];

    S[k],S[k+N+1] := N$2;

    LSrecur( N-1, N, S );              # look for a possible location for next (smaller) element

  end do;

  return LL

end proc:

undebug( Langford, LSrecur );

 

   
   


To follow all of the function calls, and passed valued, change undebug to debug.

I would've had this posted before vv's solution but I was trying to make a few improvements - and added comments to my code.

Download Langford.mw

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

Let me start with the second question. I assume you are trying to find all solutions to these transcendental functions. The first one is not too hard to do by hand. sin(beta*L)=0 whenever beta*L is an integer multiple of Pi. If you allow complex valued solutions, then sinh(beta*L)=0 whenever beta*L is an integer multiple of i*Pi.

In the attached worksheet I created a procedure that obtains this result, and can also be applied to the other two equations. I'm not sure exactly what you are hoping for in these cases, but I hope this does move you a little closer to what you seek.

Note that the key to my procedure is the use of RootOf and allvalues. I think you will find other ways to work with beta*L in your expressions (maybe with freeze and thaw).

As for the determinants of your large matrices, Maple is able to find the determinants. I am not sure what you are trying to solve for in the first matrix. In E2 I assume you are hoping to solve for s. In this case the determinant is quartic in s and Maple does find 4 solutions. I have not spent any time to dig into the structure or other symmetries of that result.

mehmet.mw

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

I added grid=[200,200] and obtained a better graph; inceasing this to grid=[500,500] produced an even smoother plot, but you lose all of the coloring because there are so many gridlines. TO help this, also add style=patchnogrid. As your subsequent contour plot shows, the support of this function is very narrow. If Maple's grid happens to skip over the support altogether, you'll get the isolalted peaks as you show in your post.

For full explanations of these, and other plot3d options, see the help for plot3d,options.

I hope this is helpful.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

I don't have an answer, but hope that I can add a little more detail to Lenin's original post.

He has an integrand in one "math container" and wants to see the solution, with steps, in another math container. There is a button to have the integral evaluated. Here's the "click action" for the button:

use DocumentTools in 
   with(Student[MultivariateCalculus]):
   Do(%resul=MultiInt(%fvvs,x=1..4,y=-1..6,output=steps));
end use;

As his posting and following responses indicate, only while the requested output is all steps, Maple shows only the final answer.

On one hand, Maple's treatment seems reasonable. In regular usage, the "result" of MultiInt is the value of the integral. This is what I would expect to get if I assigned a name to the result of the MultiInt command, or referenced this result via a label (or with %).

But, Lenin's request is also very reasonable. I can see lots of educational situations in which the steps should be included as part of the output. (I can also see where I might want to have the "value" of MultiInt be the full list of steps, and extract a particular step for further processing.)

I hope someone else can take this description and provide a satisfying respose for Lenin (and for me).

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

Buried within a loop, such as in your example, Maple does not automatically display results. You should see the results of the printf command. To see the plot3d result, print it:

print( plot3d( PS1, ... ) );

There is a way to control the "level" at which Maple stops printing results. See the help for printlevel (?printlevel).

I hope this is useful.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

I get an almost immediate response:

11.00=11.244522435+log(x);
11.00 = 11.244522435 + ln(x)
solve( { (3) }, [x] );
[[x = 0.7830784198]]

Not sure what's happening on your system.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
1 2 3 4 5 6 7 Last Page 2 of 44