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

The previous answers assume there are only 2 columns. Here's the same thing, with increasing powers in additional columns.

Matrix( 5, 3, (i,j)->i^(j+1) );
Array( 5..14, 1..2, (i,j)->i^(j+1) );

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

From some quick tests, it appears as though listplot3d prints only one matrix at a time. If it's first argument is a list of lists/matrices, these are concatentated before printing. So, to produce a plot of more than one matrix, I'd recommend creating a separate plot for each matrix and then use the display command (also in the plots package) to combine the separate plots into a single combined plot,

For example:

LL := [[1, 2], [3, 4], [5, 6], [7, 8]]:
M := convert( LL, Matrix ):
display(
   listplot3d( LL, color = "LightBlue"),
   listplot3d( 2*M, color = "Green")
);

You might alos want to take a look at the matrixplot command (also in the plots package).

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'd suggest using unapply to create a function out of BResponseCoefficient. The fact that it's piecewise is irrelevant.

To be a little more specific I'll use the definition of BResponseCoefficient from your post (but I note that your last condition on the second term looks to me as there something might not be exactly as you intended):

BRC := piecewise( t>=0 and t<0.15, 1.1+11*t, t<=0.7, 2.75, t>0.7, 1.92/t )
      *piecewise( t>=0 and t<0.7, 1, t<4, 0.852+0.212*t, t>=4, 1.7 ):
fBRC := unapply( simplify(BRC), t );   # ask Maple to simplify the product into a single piecewise
tlist := <($0..100)/10.>:              # vector of values of t to be used in the table of function values
flist := fBRC~(tlist):                 # vector of function values
interface( rtablesize=200 ):           # increase size of matrices that Maple siill display (default is 10)
<tlist|flist>;                         # two-column table of function values

I hope this is close to what you are wanting to do.

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

If you are asking how to convert the list of "bytes" back to characters, you use the same command used to convert the text into bytes:

"Hello";
"Hello"
convert( %, bytes );
[72, 101, 108, 108, 111]
convert( %, bytes );
"Hello"

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

Using assumptions can work, but sometimes does not give exactly what you might desire.

My preferred way to do this is to let Maple give me all of the solutions and then to select the ones I want or to remove the ones I don't want. The commands used to do this are select and remove, respectively.

restart;

S := solve( x^4=1, x );

1, -1, I, -I

(1)

select( is, [S], positive )[];  # select all positive roots

1

(2)

remove( has, [S], I )[];  # remove all complex-valued roots

1, -1

(3)

selectremove( has, [S], I ); # separate complex-valued and real-valued roots

[I, -I], [1, -1]

(4)

 

 

Sometimes there is no simple Maple command to do the selection. In these cases the first argument must be a Maple procedure that evaluates to true or false for each element of the second argument. Here's an example that selects all solutions with a non-positive imaginary part (note the use of evalf to get the root in a form where Maple knows if the imaginary part is positive or negative).

 

SelectRemove.mw

   

S := solve( x^3+x-1=0, x );

(1/6)*(108+12*93^(1/2))^(1/3)-2/(108+12*93^(1/2))^(1/3), -(1/12)*(108+12*93^(1/2))^(1/3)+1/(108+12*93^(1/2))^(1/3)+((1/2)*I)*3^(1/2)*((1/6)*(108+12*93^(1/2))^(1/3)+2/(108+12*93^(1/2))^(1/3)), -(1/12)*(108+12*93^(1/2))^(1/3)+1/(108+12*93^(1/2))^(1/3)-((1/2)*I)*3^(1/2)*((1/6)*(108+12*93^(1/2))^(1/3)+2/(108+12*93^(1/2))^(1/3))

(5)

evalf([S]);

[.6823278040, -.3411639019+1.161541400*I, -.3411639019-1.161541400*I]

(6)

 

select( x->Im(x)<=0, [S] )[];  # Maple needs help to decide the sign of the imaginary part

Error, selecting function must return true or false

 

 

select( x->evalf(Im(x))<=0, [S] )[];  # select roots whose imaginary part is <=0

(1/6)*(108+12*93^(1/2))^(1/3)-2/(108+12*93^(1/2))^(1/3), -(1/12)*(108+12*93^(1/2))^(1/3)+1/(108+12*93^(1/2))^(1/3)-((1/2)*I)*3^(1/2)*((1/6)*(108+12*93^(1/2))^(1/3)+2/(108+12*93^(1/2))^(1/3))

(7)

 

 


I hope this is useful.

Download SelectRemove.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

The best way to control what fits on one line is to control the width of that line. Two ways in which this can be done are

  1. widen the worksheet window
  2. decrease the size of the font

Both still have their limitations, but can be useful in some situations. Unfortunately, this affects the entire worksheet. It's not possible to use different settings for different parts of a worksheet.

Nothing fancy, but this has worked for me at times.

The previous answer about hiding ouput is the fiinal answer: terminate the command with a colon.

I do take issue with your comment that deleting output deletes associated variables. Changes in the worksheet have no effect on the status of the worksheet until they are executed.

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

If I understand your question, you want the user to enter the sum of two complex numbers, in polar form. If this is correct, the two commands you need to know are polar and evalc (and also convert).

I'll first demonstrate with jwatkins' example:

 

x := 1+5*I:

y := 2-3*I:

xP := polar( x );

polar(26^(1/2), arctan(5))

(1)

yP := polar( y );

polar(13^(1/2), -arctan(3/2))

(2)

xP+yP;

polar(26^(1/2), arctan(5))+polar(13^(1/2), -arctan(3/2))

(3)

evalc( xP+yP );

3+2*I

(4)

 

 

So, for the specific example in your original post:

 

Note that it is necessary to enter the angle as 10*degrees for convert to be able to convert this to radians.

In Maple TA, you could have separate input fields for the r and theta, or you could ask them to enter them as an ordered pair in one input field. Unless you want to require users to include *degrees when their angle is in degrees, you will need to be explicit about whether you expect input in degrees or radians.

I hope this has been helpful.

   

x := polar( 10, convert( 30*degrees, radians ) );

polar(10, (1/6)*Pi)

(5)

y := polar( 15, convert(-10*degrees, radians ) );

polar(15, -(1/18)*Pi)

(6)

evalc( x+y );

5*3^(1/2)+15*cos((1/18)*Pi)+I*(5-15*sin((1/18)*Pi))

(7)

 

Because the results of these computations are so rarely "nice", you may have to work with floating-point numbers; evalf will provide a numeric approximation - then you have to decide how close you expect the user's input to be.

Download PolarAdd.mwPolarAdd.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

My personal favorite is a combination is Kitonum's and Preben's approaches.

eq := (-Omega^2*a*A[2]-Omega^2*m*B[1]+Omega*A[1]*c[1]+B[1]*k[1])*cos(Omega*t)+(Omega^2*a*B[2]-Omega^2*m*A[1]-Omega*B[1]*c[1]+A[1]*k[1])*sin(Omega*t) = 0:
subs({sin(Omega*t)=1, cos(Omega*t)=0}, lhs(eq));   # coefficient of sin(Omega*t)subs({sin(Omega*t)=0, cos(Omega*t)=1}, lhs(eq));   # coefficient of cos(Omega*t)

The benefit I see to this approach is that it is easily extended to cases with other occurrences of sin and cos. Preben's approach lumps all sin terms together and all cos terms togehter. Kitonum's approach can be modified for this, but requires the introduction of a new name for each term. Here's a quick example showing what I would do:

eq := A*sin(a*t) + B*cos(a*t) + C*sin(2*a*t) + D*exp(-t) = 0:
eval( lhs(eq), [sin=1, cos=0, exp=0] );  # example where Kitorum's approach fails
A + C
subs( [sin(a*t)=1, cos(a*t)=0, sin(2*a*t)=0, exp(-t)=0], lhs(eq) ); # my approach
A
subs( [sin(a*t),cos(a*t),sin(2*a*t),exp(-t)]=~[1,0,0,0], lhs(eq) );     # my approach, with ~ operator
A
MyCoeffs := proc( expr, Tlist )
local Clist,Ulist;
Clist := NULL;
Ulist := [1,0$nops(Tlist)-1];
to nops(Tlist) do
Clist := Clist, subs( Tlist=~Ulist, expr );
Ulist := ListTools:-Rotate( Ulist, -1 );
end do;
return Clist
end proc;
s1,c1,s2,e1 := MyCoeffs( lhs(eq), [sin(a*t),cos(a*t),sin(2*a*t),exp(-t)] );
s1, c1, s2, e1 := A, B, C, D

I do have to admit that there are cases where any of these approaches could fail.

I should also point out the coeff is designed for polynomial expressions (of one variable) but coeffs is the corresponding command for multinomial expressions. There are lots of times when coeffs is more useful (and powerful) than coeff.

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 encourage you to post a specific example, then we can give you some explicit pointers. Until then, I think you'll find the axis, labels, and tickmarks options of use. You can find all of these (and many others) in the help page for plot3d,options, or look directly at plot,axis and plot,tickmarks.

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

The showstat command is useful for looking at the implementation of almost any Maple procedure. In this case, because you've already loaded the Student[NumericalAnalysis] package, all you have to type is

with(Student[NumericalAnalysis]):

 

showstat( Secant );


Student:-NumericalAnalysis:-Secant := proc({method::identical(secant) := 'secant'})
   1   return Student:-NumericalAnalysis:-Roots(args,(':-method') = method)
end proc

 

This shows that this command is actually a special case of the Roots command (also in the same package). You know what to do to see the definition of Roots. Be forewarned that Roots can do a lot; it's more than 400 lines of Maple code (and so has been omitted from this post).

showstat( Roots );

 

 

To address your question about getting more information from Secant, I suggest looking at the online help. If you try ?Secant, you will find informaiton about a Tutor for the secant method (maybe this will be of some interest to you?). You can find the NumericalAnalysis Secant in the list of related commands in the left-hand side of the Help window - or you can ask for help for Student,NumericalAnalysis,Secant. Once you are looking at this information, open the Options section and look at the different options for output=. I think you might like what you get with output=information:

f := x^3-7*x^2+14*x-6

Student:-NumericalAnalysis:-Secant(f, x = [2.7, 3.2], tolerance = 10^(-2))

Student:-NumericalAnalysis:-Secant(f, x = [2.7, 3.2], tolerance = 10^(-2), output = sequence)

Secant(f, x = [2.7, 3.2], tolerance = 10^(-2), output = information)

Matrix([[n, p[n], `relative error`], [0, 2.7, `- `], [1, 3.2, `- `], [2, 3.100884956, 0.3196347024e-1], [3, 2.858406793, 0.8482983024e-1], [4, 3.026267866, 0.5546801553e-1], [5, 3.005775850, 0.6817546292e-2]])

(1)

 

You might find other combinations of options that provide slightly different and more useful information, depending upon your ultimate needs and uses for this information.

I hpe this has been helpful.

Download Secant_Method2.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

plot3d allows for colors to be specified via a procedure. If there is no other solution, you could create your point plot as a 3D plot and specify the orientation so that it appears as a 2D plot.

See the help for plot3d,colorfunc for details about how to specify a color function. Then plot3d,options for information about the orientation option.

If all goes well, you might be able to use plottools,transform to convert your 3D plot to a 2D plot. I do not know if this will retain the coloring from the 3D plot.

If you provide us with some additional details about what you are doing, includiing the points you want to plot and the parameter used to produce the coloring, maybe one of us can put these ideas into practice 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

plot( x[2]^2, caption = typeset("A plot of %1.", x[2]^2) );

See the Maple help for plots,typesetting 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

Sure. Here's how I would do this:

GenerateMatrix( eqns, [x(t),y(t)] ):      # the colon suppresses all output
%[2]                                      # % is the last result, and [2] selects the second object

If you use this it would be best to have both commands in the same execution group. If you don't, there's a chance ou execute the second command sometime without executing the GenerateMatrix command immediately before it. Then the output would be different.

I would assign the results to names, for example:

GM := GenerateMatrix( eqns, [x(t),y(t)] ):
ans := GM[2];

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

Have you looked at the VolumeOfRevolution command in the Student[Calculus1] package?

This single command can handle most of the typical examples encountered by calculus students. Here's a quick demo from your problem:

with( Student[Calculus1] ):

VolumeOfRevolution( x, x^2+1, x=0..2, output=animation );

 

 

VolumeOfRevolution( x, x^2+1, x=0..2, output=integral );

Int(Pi*abs(x^4+x^2+1), x = 0 .. 2)

(1)

 

VolumeOfRevolution( x, x^2+1, x=0..2, output=sum );

(1/3)*Pi*(Sum(abs(-((1/3)*i-1/6)^2+(((1/3)*i-1/6)^2+1)^2), i = 1 .. 6))

(2)

VolumeOfRevolution( x, x^2+1, x=0..2, output=value );

(166/15)*Pi

(3)

 

map~(p->VolumeOfRevolution( x, x^2+1, x=0..2, output=p), integral=value );

Int(Pi*abs(x^4+x^2+1), x = 0 .. 2) = (166/15)*Pi

(4)

 

Download VolumeOfIntegralDemo.mw

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

The OP was very close to getting the desired answer. The problem is best described as a classic mismatch between analytic and numerical methods.

a := 1; w0 := 1; w1 := 3; K := 10; h0 := .25; A := 3; alpha := .7; b := .6; c := .2;

f := A*x^(b*alpha)*(alpha*A*x^(b*alpha)/(a+w0*h0+(x-h0)*w1))^(alpha/(1-alpha))-(alpha*A*x^(b*alpha)/(a+w0*h0+(x-h0)*w1))^(1/(1-alpha)):
M := maximize(f, x = 0 .. 1):
0.8295280335

The result from maximize is an approximation. When this maximum value is passed to solve, Maple tries to find a symbolic solution to this numeric problem. Maybe it should know better, but I'm not surprised that it did not get an answer. It would make more sense, at least to me, to use fsolve:

fsolve(f = M, x);

But this just returns unevaluated. Why? Because this maximum value is approximate. If it's ever so slightly larger than the exact maximum, then there truly is not a solution to this equation. As has been suggested by other responders, this value is accurate only to a few digits. Let's through away a few digits from the maximum value:

fsolve(f = .829528, x);
0.5357195187
fsolve(f = .82952803, x);
0.5354902012
fsolve(f = .829528033, x);
0.5355263036
fsolve(f = .8295280333, x);
0.5355353790
fsolve(f = .8295280334, x)
0.5355415721
fsolve(f = .8295280335, x);

I don't know if it's realistic to expect Maple to do any better than this. It's not a black box, and it can answer only the questions that are posed to it - not the ones that we hope it understands that we are asking.

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
1 2 3 4 5 6 7 Last Page 3 of 44