Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 354 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

If p is your formula constructed with Maple's standard boolean operators (and, or, notxor, implies), then do

Logic:-Export(Logic:-Import(p), 'form'= 'MOD2')

You can also construct your input formula using the Logic package's own boolean operators: &and&or&not, etc. I recommend against this for cases of direct user input because these operators do not follow standard rules of operator precedence, so an extreme number of parentheses are required.

These are called partial derivatives. The f_y means the partial derivative with respect to y, and f_z is with respect to z.

Here's one way, the command. This command refers to the variables based on their positions in the function's definition, which is the first line below:

f: = (y, z) -> y * sin (z) + 2 * cos (y):
#Partial derivative with respect to the first variable, y:
D[1](f)(Pi/2, Pi); #Pi is capitalized.
                               -2

#Partial derivative with respect to the second variable, z:
D [2] (f) (Pi / 2, Pi); 
                               1   
                             - - Pi
                               2   

Referring to the independent variables by their position numbers may seem like a bad idea at first, but it turns out to be a lot less to type than referring to them as y and z.

Put your cursor within the section that you want to execute and press Enter (or Return on some keyboards).

Simply using x[1] as an unassigned name doesn't create a table x; however, assigning to x[1] does create a table. The unintentional creation of these tables is one of the most common causes of bugs in Maple programs. Thus, it's safer to use x__1. But, if you actually want the subscript to be programmatically indexable (as in k:= 1; x[k];), then it's much easier to use x[...].

Maple's StringTools understands regular expressions, which is a common language (especially in Unix and Linux commands) used for pattern matching and substitution. See the Wikipedia article "Regular expression". For a brief tutorial, see help page ?StringTools,Regular_Expressions. With this machinery in the background, it's trivial to generalize what you asked for into a procedure that performs almost any desired substition of names in any expression:

RegSubsName:= (e, S::`=`(string))-> 
    subsindets(e, name, n-> cat(``, StringTools:-RegSubs(S,n)))
:

Example usage:

dsolve(diff(y(x),x$3) = y(x)); 
RegSubsName(%, "^_C"= "c__");
Physics:-Latex(%);

 

VV's Answer shows you how to get the generalized eigenvectors that you want.

The purpose of this Answer is to correct several of your misconceptions about defective matrices.

You wrote:

  • When a real matrix have repeated eigenvalue (i.e. multiplicity >1) and the matrix is not the identity matrix, then it is called defective eigenvalue. 

defective eigenvalue is one for which the space spanned by the corresponding eigenvectors has dimension less than the (algebraic) multiplicity of the eigenvalue. While it's true the such eigenvalues always have multiplicity greater than 1, the converse is not true: A repeated eigenvalue is not necessarily defective. There's nothing special about the identity matrix in this regard. There's nothing special about real matrices.

  • There is an algorithm to generate another (linearly independent) eigenvector from this same eigenvalue called the defective eigenvalue method.

The algorithm that you speak of does not generate (true) eigenvectors; rather, it generates generalized eigenvectors. Given the matrix A and vector v__2 from your example, you can easily check that A.v__2 <> 3*v__2, and thus v__2 is not an eigenvector.

Maple's Eigenvectors does return a maximal linearly independent set of true eigenvectors. 

I assume that the data in the Excel file is a two-column matrix, the first column being times and the second being values of Q. If that's not the format, slight adjustments to the following will be needed.

First, import the Excel file to a Maple matrix:

QX:= ExcelTools:-Import(filename):

Then,

QI:= Interpolation:-LinearInterpolation(QX);
Q:= t-> `if`(t::numeric, QI(t), 'procname'(t)):

Set up your ode system odesys just like you have above, including the Q(t). Then

sol:= dsolve(odesys, numeric, known= Q);

 

The process can be easily generalized to exchange any "outer" function or set of functions with any "inner" function or set of functions, and to do it at arbitrary functional positions:

ExchangeFuncs:= proc(
    e, 
    F::[{name, set(name)}, {name, set(name)}],
    p::[posint, posint]:= [1,1]
)
    evalindets(
        e,
        And(
            specfunc(anything, F[1]), 
            'patfunc'(
                anything$(p[1]-1), 
                And(specfunc(anything, F[2]), 'patfunc'(anything$p[2])), 
                anything
            )
        ),
        u-> 
            op([p[1],0], u)(
                op([p[1], ..p[2]-1], u),
                op(0,u)(op~([..p[1]-1, p, p[1]+1..], u)[]), 
                op([p[1], p[2]+1..], u)
            )
    )
end proc
:    
#Example (inner functions are outer functions' 2nd argument):
e:= f(1, g(2,3)) + h(4, i(5,6)):
#Apply outer functions to inner functions' 1st argument:
ExchangeFuncs(e, [{f,h}, {g,i}], [2,1]); 
                 g(f(1, 2), 3) + i(h(4, 5), 6)

#Apply outer functions to inner functions' 2nd argument:
ExchangeFuncs(e, [{f,h}, {g,i}], [2,2]);
                 g(2, f(1, 3)) + i(5, h(4, 6))

To do the job that you requested:

MySumOfInt:= ExchangeFuncs(MyIntOfSum, [Int, Sum]);

Or you may want to make the second argument [{Int, int}, {Sum, sum}].

You can reverse the exchange, which'll return the original:

ExchangeFuncs(MySumOfInt, [{Sum, sum}, {Int, int}]);

There's no need to do something different in the code itself. The plotting can be done as an afterthought:

plots:-listplot([seq(A[i], i= 1..1000)]);

Use a digraph in GraphTheory, like this:

GT:= GraphTheory:
G:= GT:-Graph({
    [[1,2], 35], [[3,4], 20], [[6,5], 15], [[8,7], 40],
    [[2,8], 222], [[4,2], 111], [[6,4], 333], [[8,6], 444]
}):
GT:-SetVertexPositions(
    G,
    [[-1,2], [0,1], [2,2], [1,1], [2,-1], [1,0], [-1,-1], [0,0]]
):
plots:-display(
    subs(
        ["111"= x__1, "222"= x__2, "333"= x__3, "444"= x__4], 
        GT:-DrawGraph(
            G, 
            stylesheet= [
                edgefont= [times,bold,16],
                vertexcolor= black,
                vertexfontcolor= black,
                vertexfontsize= 6
            ]
        )
    ),
    view= [(-.75..1.75)$2]
);

All sizes, colors, and positions can be adjusted, of course.

Okay, so you mean that you want a vector-field plot of the gradient. That's do-able, and shown below. To understand my comment about streams, you need to look at that procedure by expanding the Code Edit Region in the worksheet that you posted. Here it is:

streams:=proc(n,fcn,pts,name) 
       local f,k,DISK,p; 
       f:=transform((r,th) -> [r*cos(th),r*sin(th)]): 
       DISK:=disk([0,0],1,color=red); 
       for k from -n by 2 to n do 
             p[k]:=implicitplot(fcn=2*k/n,x=-n/2..n/2,y=-Pi..Pi,numpoints=pts): 
       od: 
       display(seq(f(p[2*i]), i=-n/2..n/2), DISK, view=[-n/2..n/2,-n/2..n/2], scaling=constrained, axes=boxed, title=name); 
end:

As you can see, it uses implicitplot, which doesn't work for vector fields.

To do the plot of the gradient, first take out (or comment out) these lines:

with(Physics[Vectors]):
Setup(mathematicalnotation= true):
V:= Gradient(V):

And add these lines:

dV:= VectorCalculus:-Gradient(V, [x,y]):
plots:-fieldplot(dV, x= -2..2, y= -2..2, fieldstrength= log[10]);

Then re-execute the worksheet (so that the restart is used). You'll get this field plot:


There are many options to control the appearance, size, and relative size of the arrows. See the help page ?plots,fieldplot for details.

I don't know what you meant by scene= [P, P(t)]. I changed it to scene= [t, P(t)]. I don't know what you meant by conditions. I just omitted that. If the below is not what you want, then if you can explain what you meant, I'll probably be able to tell you how to do it.

DEtools:-DEplot(
   diff(P(t),t) = P(t)*(7-P(t))-10, P(t), t= -10..10, P= -10..10, 
   scene= [t, P(t)], number= 1, stepsize= .01
);

To include a trajectory in the plot, you of course need intial conditions,

Let's say that LL is a list of lists of real numbers; it doesn't matter how many. Then do

plot(map(ListTools:-Enumerate, LL));

Presumably, ff is a procedure, and we'd need to see its full code to determine its "thread safety". If you've experienced weird behavior with this, a lack of thread safety is the likely cause. 

You can implement that formula with overload, like this:

restart:
`Psi/original`:= eval(Psi):
unprotect(Psi):
Psi:= overload([
    proc(r::And(positive, fraction), $)
    option overload;
    local n:= trunc(r), f:= r-n, p, q, k;
        (p,q):= (numer,denom)(f);
        simplify(
            q*add(`/`~([seq](p..(n-1)*(q+1), q))) +
            2*add(cos(2*Pi*k*f)*ln(sin(Pi*k/q)), k= 1..iquo(q-1,2)) - 
            Pi/2*cot(Pi*f) - ln(2) - ln(q) - :-gamma
        )
    end proc,

    `Psi/original`
]):
protect(Psi, `Psi/original`)
:
Psi(1/12);

Or, if you want more control over when the conversions are performed, you could do the exact same thing to `expand/Psi` rather than Psi.

First 88 89 90 91 92 93 94 Last Page 90 of 395