nm

11353 Reputation

20 Badges

13 years, 20 days

MaplePrimes Activity


These are questions asked by nm

This is the context: I call LinearAlgebra:-LinearSolve to solve system of linear equations. If there are infinite solutions, then Maple return the solution that has free variables, calling them using  _t[n] where can change each time and be different. It can also be _t0[n] and _t1[n] etc.. but these all are indexed variables.

I want to obtain a list of all these free variables in the resulting solution vector, so that later I can assign them some values.

But I do not know what can be. And how many of them there are. There could be _t[3] and _t[4] for example in the same solution vector.

Here is what I do now, where I just check for indexed type. This seems to work, since only _t[n] should be in the resulting solution if any.

restart;
A:=Matrix([[0,1,-1],[-1,-2,2],[-1,-2,2]]):
v:=Vector([-1,1,1]):
sol := LinearAlgebra:-LinearSolve(A,v);

map(x->select(type,x,'indexed'),convert(sol,set))

I do not know how to tell it to look for all something that starts with  _t and also indexed type.

Is there a better way to obtain list of all _t[n] that LinearAlgebra:-LinearSolve could return? Will LinearAlgebra always return the free variables as indexed variables so I am sure the above will always work?  Do you see a problem with the above solution?

It is annoying that some functions in Maple wants input like (a,b,c,.....) which represents numbers, and I am not able to find how to use such a function, because the list of numbers I have are in a list.

For example, ilcm and igcd.  This is not a good design. The input should have been a list or set, or vector, etc.... 

I wanted to find least common multiplier of a list of numbers. These numbers are allready in a list, since this is a result of a computation done earlier. Now I want to find ilcm of them. 

How to use ilcm in this case? How to unpack them to make ilcm happy? In Mathematica there a special function to do this, called Sequence, which takes a list and unpack it to call function. 

But I am not able to find one in Maple. There is no convert(list,exprseq). 

Here is a MWE

v:=[2,4,7];
ilcm( v ); #does not work, since ilcm does not accept a list

The variable v above has to be in a list (or set, or vector). This is result from another computation. This is all done non-interactive. 

So I am looking for some magic function to use it like this

v:=[2,4,7];
ilcm( convert_to_expression_sequence(v) )

Is there a way to unpack or convert list to expression sequence, so I can use ilcm?

This is my attempt. But I suspect there is a build-in way in Maple to do this which I have not found yet.

restart;

convert_list_to_exprsequence:=proc(L::list)::exprseq;
local r:=NULL,item;

for item in L do
    r:=r,item;
od;

return r;
end proc:

v:=[2,4,7];
ilcm(convert_list_to_exprsequence(v)); #now it works

                  #28

Maple 2020.1

For entering system of linear ode's, from textbook, such as this example

I can either use x[1],x[2]  or x__1 and x__2.

Maple dsolve works with both. The Latex generated is also exactly the same Which is x_{1} and x_{2}.

The only minor difference I see is on the screen in the worksheet (I only use 1D), where the subscript looks a little nicer in the case of x[1] vs. x__1

The subscript in the case of x[1] is upright while the one in x__1 is italic. I like the first one more.

Other than this cosmetic difference, Are there are subtle sematic differences between the two forms in terms of computation? I know x[1] create table x. OK.  While x__1 is a separate symbol. No table is created.,

Which would be  a safer/better option to use in this case?   Or is it just a matter of choice?

sys:=[ diff(x[1](t),t)=x[1](t)+x[2](t),diff(x[2](t),t)=x[1](t)+3*x[2](t)];
sys:=[ diff(x__1(t),t)=x__1(t)+x__2(t),diff(x__2(t),t)=x__1(t)+3*x__2(t)];

In some way, using x__1(t) might be a little easier to read on the eye than x[1](t) since there is only one type of paranthesis involved.

ps. I tried to search for __ in Maple help to read more about it, but ?__ do not show it. I am sure __ is in the help under some other name.

For display only purposes, to get the Latex looking better, I replace the constant of integrations Maple using which is _C1, _C2., etc... to c[1],c[2],..... 

This is something I do at the very end of computation, just before I get the Latex of the expression.

The way I do this now, is not good. .And I am asking if there is a better way to do this replacement. In Mathematica, I can do this using a patterm where I tell it to replace  C?  by c[?] where ? means anything.

Is it possible to do something like this in Maple? Here is an example

sol:=dsolve(diff(x(t),t$3) = x(t));

This gives solution as

And just before ask for the Latex of this, I change it to 

This is done using a function. Please see worksheet below.

The problem with the current solution is that I do not know how many _C there are, so I assumed 10 as worst case, which works for my case. But I prefer a more general solution, may be using pattern in the subs command?


 

restart;

replace_all_C:=proc(expr::anything)
local n,N,c;
local new_expr;
local max_count :=10; #worst case, since do not know how many

    new_expr:=expr;
    for n from 1 to max_count do
        N:=convert(n,string);
        new_expr:=subs( :-parse(cat("_C",N))=:-parse(cat("c[",N,"]")),new_expr);
    od:
    return new_expr;
end proc:

sol:=dsolve(diff(x(t),t$3) = x(t));
tmp:=replace_all_C(sol)

x(t) = _C1*exp(t)+_C2*exp(-(1/2)*t)*sin((1/2)*3^(1/2)*t)+_C3*exp(-(1/2)*t)*cos((1/2)*3^(1/2)*t)

x(t) = c[1]*exp(t)+c[2]*exp(-(1/2)*t)*sin((1/2)*3^(1/2)*t)+c[3]*exp(-(1/2)*t)*cos((1/2)*3^(1/2)*t)

 


 

Download q.mw

And now I get the latex of tmp in the above, instead of sol which looks better.

 

 

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. 

For example if the eigenvalue is repeated 2 times, there will be only one eigevector associated with it.

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

My question is: Does Maple have support for finding such additional eigenvectors?  The standard Eigenvectors does not seem to do this. Here is an example.

restart;
A :=Matrix([[1,-2],[2,5]]);
(eigen_values, eigen_vectors) := LinearAlgebra:-Eigenvectors(A);

By hand, using the defective eigenvalue method it is possible find second eigenvector for this eigenvalue, which is linearly independent of the one returned by Maple. Such as 

The method to find these additional eigenvector is described in number of places such as 

https://en.wikipedia.org/wiki/Defective_matrix

And the pdf at the bottom show a more detailed example.

I can code this method by hand to find complete set of L.I. eigenvectors for this defective eigenvalue.  

But before doing that, I thought to ask if Maple have buildin support for this, such as a single command to do this or some package.

I looked at help for LinearAlgebra and I am still not able to see anything, It only says this:

With an eigenvalue of multiplicity  k>1 , there may be fewer than  k linearly independent eigenvectors. In this case, the matrix is called defective.  By design, the returned matrix always has full column dimension.  Therefore, in the defective case, some of the columns that are returned are zero.  Thus, they are not eigenvectors.  With the option, output=list, only eigenvectors are returned.  For more information, see LinearAlgebra[JordanForm] and LinearAlgebra[SchurForm].
 

This PDF also describes using Maple, how to do it for one example

https://wps.prenhall.com/wps/media/objects/884/905485/chapt5/proj5.4/proj5-4.pdf

This PDF also describes how to do it by hand without using Maple, starting at end of page 3

http://www.math.utah.edu/~zwick/Classes/Fall2013_2280/Lectures/Lecture23_with_Examples.pdf

It is not too hard to code this method in Maple. But if Maple allready can do it, using some command, it will be better ofcourse.

 

First 112 113 114 115 116 117 118 Last Page 114 of 199