Kitonum

21435 Reputation

26 Badges

17 years, 29 days

MaplePrimes Activity


These are answers submitted by Kitonum

You can take any initial value (also any range) for the parameter yourself.
Example:

restart;
plots:-animate(plot, [m*x, x=-10..10, -10..10], m=1..5, frames=100);

Here is a simple procedure for this and an example:

Code of the procedure

P:=proc(A::Matrix, B::Matrix)
local m1,n1,n2;
m1:=op([1,1],A);
n1:=op([1,2],A);
n2:=op([1,2],B);
Matrix(m1,n2, (i,j)->add(A[i,p].B[p,j], p=1..n1));
end proc:


Example

A:=Matrix(2,3,{seq(seq((i,j)=LinearAlgebra:-RandomVector(2,generator=-9..9), i=1..2),j=1..3)});
B:=Matrix(3,2,{seq(seq((i,j)=LinearAlgebra:-RandomVector(2,generator=-9..9), i=1..3),j=1..2)});

Matrix(2, 3, {(1, 1) = Vector(2, {(1) = 2, (2) = -9}), (1, 2) = Vector(2, {(1) = 3, (2) = 1}), (1, 3) = Vector(2, {(1) = -9, (2) = -7}), (2, 1) = Vector(2, {(1) = 3, (2) = 6}), (2, 2) = Vector(2, {(1) = -8, (2) = -8}), (2, 3) = Vector(2, {(1) = 0, (2) = -3})})

 

Matrix(%id = 18446746086682646398)

(1)

P(A,B);

Matrix(2, 2, {(1, 1) = 122, (1, 2) = 104, (2, 1) = -80, (2, 2) = -12})

(2)

 


Addition. Below is an example of another method (without a custom procedure):
 

A:=Matrix(2,3,(i,j)->LinearAlgebra:-RandomVector(2,generator=-9..9));
B:=Matrix(3,4,(i,j)->LinearAlgebra:-RandomVector(2,generator=-9..9));
subsindets(A.B, `*`,t->`.`(op(t)));

Download P.mw

At the beginning of the code, you enter a recursive function  Tm . But your method does not work. Take a look:
 

restart;
Tm:=(t,m)-> 2*t*Tm(t,m-1)-Tm(t,m-2):
Tm(t,0):=1:
Tm(t,1):=t:
Tm(3,4);  # Example

     Error, (in Tm) too many levels of recursion


You can use the following procedure to correctly determine:
 

restart;
Tm:=proc(t,m)
option remember;
if m=0 then return 1 else
if m=1 then return t else
2*t*Tm(t,m-1)-Tm(t,m-2) fi; fi;
end proc:
Tm(3,4);  # Example

                                   577


You can also get an explicit formula for TM :
 

restart;
Tm:=unapply(rsolve({Tm(t,m)=2*t*Tm(t,m-1)-Tm(t,m-2), Tm(t,0)=1, Tm(t,1)=t}, Tm(t,m)),t,m);
Tm(3,4);
simplify(%);

We can use the inert form integral for this:

G := Int( exp( -epsilon * ( x^4 + x^2 ) ), x = -10 .. 10);
plot( G, epsilon=0 .. infinity );
         

          


 

restart

Dice1 := rand(1 .. 6)

Tal1 := Statistics:-Tally([seq(Dice1(), i = 1 .. 1000)], output = table)

table( [( 1 ) = 185, ( 2 ) = 169, ( 3 ) = 159, ( 4 ) = 180, ( 5 ) = 153, ( 6 ) = 154 ] )

(1)

EffectifDice1 := [seq(Tal1[i], i = 1 .. 6)]

[185, 169, 159, 180, 153, 154]

(2)

FreqDice1 := (1/1000)*EffectifDice1

[37/200, 169/1000, 159/1000, 9/50, 153/1000, 77/500]

(3)

A1 := evalf(sum(FreqDice1[i]*(FreqDice1[i]-1/6)^2, i = 1 .. 6))

0.1577317778e-3

(4)

NULL


 

Download QuestionSimulation_new.mw

RootFinding:-Analytic(exp(x)*sin(x)-exp(1), re=0..100, im=-1..1);
plot(exp(x)*sin(x)-exp(1), x=0..100,-3..3, size=[900,300]);  # Check

Notice that the exponential function with the base  e  must be encoded in Maple as  exp(x)  (not  as  e^x ). e is just a symbol in Maple.

Unfortunately, I do not see the possibility to significantly speed up this calculation. I just rewrote your code as a procedure, slightly simplifying it. The procedure returns  true  if the matrix is  MDS  and  false  otherwise. The example of a matrix of 12 order is considered. This calculation took about 35 minutes on my computer.


 

restart;

IsMDS:=proc(A::Matrix)
local n, k, P, p, q, F, r;
uses combinat, LinearAlgebra;
n:=op([1,1],A);
for k to n do
 P := choose(n, k);
 for p in P do
 for q in P do
 F := A(p, q);
 r := Determinant(F);
 if r = 0 then return false end if;
end do; end do;
end do:
true;
end proc:

ts:=time():
interface(rtablesize=100):
A:=LinearAlgebra:-RandomMatrix(12);
IsMDS(A);
time()-ts;

Matrix(12, 12, {(1, 1) = -69, (1, 2) = -30, (1, 3) = -75, (1, 4) = 42, (1, 5) = -81, (1, 6) = -97, (1, 7) = -63, (1, 8) = -5, (1, 9) = 58, (1, 10) = -29, (1, 11) = 48, (1, 12) = 28, (2, 1) = 17, (2, 2) = -50, (2, 3) = -3, (2, 4) = 55, (2, 5) = 11, (2, 6) = -92, (2, 7) = 27, (2, 8) = 47, (2, 9) = -43, (2, 10) = 9, (2, 11) = -60, (2, 12) = -81, (3, 1) = -87, (3, 2) = 98, (3, 3) = 19, (3, 4) = 34, (3, 5) = -76, (3, 6) = 73, (3, 7) = 58, (3, 8) = -54, (3, 9) = -85, (3, 10) = 81, (3, 11) = 51, (3, 12) = -36, (4, 1) = 37, (4, 2) = 5, (4, 3) = 69, (4, 4) = -55, (4, 5) = 82, (4, 6) = 44, (4, 7) = 2, (4, 8) = -72, (4, 9) = -85, (4, 10) = 35, (4, 11) = 20, (4, 12) = -88, (5, 1) = 33, (5, 2) = -23, (5, 3) = -89, (5, 4) = 54, (5, 5) = -29, (5, 6) = 92, (5, 7) = 54, (5, 8) = -79, (5, 9) = 19, (5, 10) = 80, (5, 11) = -46, (5, 12) = 91, (6, 1) = -17, (6, 2) = 19, (6, 3) = 95, (6, 4) = 79, (6, 5) = 29, (6, 6) = 73, (6, 7) = 47, (6, 8) = 75, (6, 9) = 25, (6, 10) = 20, (6, 11) = 35, (6, 12) = -62, (7, 1) = 58, (7, 2) = -93, (7, 3) = 77, (7, 4) = -99, (7, 5) = 35, (7, 6) = -39, (7, 7) = 90, (7, 8) = -85, (7, 9) = 17, (7, 10) = 39, (7, 11) = -54, (7, 12) = -94, (8, 1) = -21, (8, 2) = 12, (8, 3) = -84, (8, 4) = -32, (8, 5) = -70, (8, 6) = 62, (8, 7) = -41, (8, 8) = -19, (8, 9) = 81, (8, 10) = -35, (8, 11) = -17, (8, 12) = 27, (9, 1) = 15, (9, 2) = 82, (9, 3) = -63, (9, 4) = -9, (9, 5) = -43, (9, 6) = 11, (9, 7) = -79, (9, 8) = 57, (9, 9) = 89, (9, 10) = 26, (9, 11) = -25, (9, 12) = 18, (10, 1) = -58, (10, 2) = -4, (10, 3) = 96, (10, 4) = 69, (10, 5) = -23, (10, 6) = 61, (10, 7) = 9, (10, 8) = 83, (10, 9) = 92, (10, 10) = -74, (10, 11) = 78, (10, 12) = 18, (11, 1) = 75, (11, 2) = 14, (11, 3) = 69, (11, 4) = 31, (11, 5) = -14, (11, 6) = 28, (11, 7) = 45, (11, 8) = -45, (11, 9) = -2, (11, 10) = 13, (11, 11) = 23, (11, 12) = 63, (12, 1) = -31, (12, 2) = 78, (12, 3) = 72, (12, 4) = -66, (12, 5) = 37, (12, 6) = -48, (12, 7) = -10, (12, 8) = 68, (12, 9) = -46, (12, 10) = 32, (12, 11) = -67, (12, 12) = 86})

 

true

 

2090.344

(1)

%/60*minutes;

34.83906667*minutes

(2)

 


 

Download MDS.mw

 

Since the system is easily reduced to a linear system, it can easily be solved symbolically, that is, absolutely exactly:

Sys:=convert({(T[1]-T[0])/(10000-T[1]+T[0]) = -2.000000000, (T[2]-T[0])/(20000-T[2]+T[0]) = 0, (T[3]-T[0])/(50000-T[3]+T[0]) = 50, .1*T[0]+.3*T[1]+.55*T[2]+0.5e-1*T[3]-5000 = 0}, fraction);
solve(Sys);


                

To solve this problem you can use  PosIntSolve  procedure from this post. This procedure allows you to find the number of non-negative (or positive) integer solutions of a linear Diophantine equation with positive coefficients. For convenience, here are the text of the procedure and 2 examples.

restart;

PosIntSolve:=proc(L::list(posint), n::nonnegint, s::symbol:=nonneg)
local N, n0;
option remember;
if s=pos then n0:=n-`+`(op(L)) else n0:=n fi;
N:=nops(L);
if N=1 then if irem(n0,L[1])=0 then return 1 else return 0 fi; fi;
add(PosIntSolve(subsop(1=NULL,L),n0-k*L[1]), k=0..floor(n0/L[1]));
end proc:

The problem: find the number of non-negative integer solutions of equations  51*x1+53*x2+50*x3=197  and   51*x1+53*x2+50*x3=2697  .

Solutions:

PosIntSolve([51, 53, 50], 197);
PosIntSolve([51, 53, 50], 2697);
                                                             
0
                                                             28
 

Replace  "5"  temporarily some symbol:

applyrule(a*x+a=a*``(x+1), subs(5=a, sqrt(5*x+5+y))):
subs(a=5, %);
                             
sqrt(5*(x+1)+y)

Actually no error. When you differentiate the internal function  r*sin(theta)*(r*cos(theta)-a)^(-1)  by a-variable, then the factor (-1) occurs 2 times.

The result above is incorrect, since the straight line and the parabola in this example intersect not at one, but at two points. To avoid errors for different curves, use different parameter names. Here is the right solution:


 

restart;
L1 := [t-2,(t-2)^2]:        
L2 := [(3*s/2)-4,(3*s/2)-2]:
solve(Equate(L1,L2));
plot([[op(L1),t=-1..5],[op(L2),s=0..5]], color=[red,blue]);  # Check

 

{s = 2, t = 1}, {s = 4, t = 4}

 

 

 


 

Download parametrics.mw

Red arrows (tangent vectors) show the direction of increasing parameter:
 

f:=[t-2,(t-2)^2];
df:=diff(f, t);

[t-2, (t-2)^2]

 

[1, 2*t-4]

(1)

P:=plot([op(f), t=-0.5..4.5], color=blue):
V:=plots:-arrow([seq([f, df], t=0..4)], length=1, color=red, border=false):
plots:-display(P,V, scaling=constrained, size=[400,500]);

 

 


 

Download arrows1.mw

Try the following:

plot([x+deltax, z, x=0..l]);
 

Here is the plot that OP wished according to his link:

restart;
f:=x->sqrt(1-x^2):
g:=x->-sqrt(1-x^2):
y1:=f(a)+D(f)(a)*(x-a):
y2:=g(a)+D(g)(a)*(x-a):
y3:=[-1,t,t=-1.5..1.5]:
y4:=[1,t,t=-1.5..1.5]:
Opt:=x=-2..2,color="Blue":
plots:-display(plot([seq(op([y1,y2]),a=-0.99..0.99,0.02)],Opt),plot([y3,y4],Opt), view=[-2..2,-1.5..1.5], scaling=constrained, size=[700,500],tickmarks=[spacing(0.5),spacing(0.5)],  axis[1]=[gridlines=40], axis[2]=[gridlines=30]);


Output:
                    

 

 

First 97 98 99 100 101 102 103 Last Page 99 of 289