Kitonum

21530 Reputation

26 Badges

17 years, 84 days

MaplePrimes Activity


These are answers submitted by Kitonum

The best and fastest way to enter a matrix is using the angle brackets from the keyboard. Try this and you will forget your palettes.

Example:

A:=<1, 2, 3; 4, 5, 6; 7, 8, 9>;

                                                   

 

If you still want to use this expression, then just remove the back quotes around it:

Matrix(2, 3, {(1, 1) = Typesetting:-msub(Typesetting:-mi("n"), Typesetting:-mrow(Typesetting:-mn("1"), Typesetting:-mo(","), Typesetting:-mn("1"))), (1, 2) = Typesetting:-msub(Typesetting:-mi("n"), Typesetting:-mrow(Typesetting:-mn("1"), Typesetting:-mo(","), Typesetting:-mn("2"))), (1, 3) = Typesetting:-msub(Typesetting:-mi("n"), Typesetting:-mrow(Typesetting:-mn("1"), Typesetting:-mo(","), Typesetting:-mn("3"))), (2, 1) = Typesetting:-msub(Typesetting:-mi("n"), Typesetting:-mrow(Typesetting:-mn("2"), Typesetting:-mo(","), Typesetting:-mn("1"))), (2, 2) = Typesetting:-msub(Typesetting:-mi("n"), Typesetting:-mrow(Typesetting:-mn("2"), Typesetting:-mo(","), Typesetting:-mn("2"))), (2, 3) = Typesetting:-msub(Typesetting:-mi("n"), Typesetting:-mrow(Typesetting:-mn("2"), Typesetting:-mo(","), Typesetting:-mn("3")))});

                                                     


Edit.

Go to the Help page  ?dsolve . There you will find a link to the Help page  dsolve, education , on which there are examples of a number of commands that will give you useful information about your equation. For example, you can find out the type of equation:

 restart;
ode:=diff(y(x),x)=sqrt(1-x^2)/y(x)^2;
DEtools:-odeadvisor(ode);

                                                  ode := diff(y(x), x) = sqrt(-x^2+1)/y(x)^2

                                                                       [_separable]

Using Heron's formula, it is easy to construct a system of equations connecting the lengths of the sides with the lengths of altitudes. Maple easily solves this system and we get formulas expressing the sides of the triangle through its altitudes (a triangle can be an arbitrary triangle - it may not be acute):

p:=(a+b+c)/2: S:=sqrt(p*(p-a)*(p-b)*(p-c)):
Sol:=[solve({hA=2*S/a, hB=2*S/b, hC=2*S/c}, {a,b,c}, explicit)][2];

simplify(eval(Sol, [hA=sqrt(3)/2, hB=sqrt(3)/2, hC=sqrt(3)/2]));  # Examples of use
simplify(eval(Sol, [hA=3, hB=4, hC=12/5]));
simplify(eval(Sol, [hA=2, hB=3, hC=3]));

                         
 

In the first example, we got an equilateral triangle (I took the equal  lengths of altitudes), in the second example - a rectangular triangle (I took the altitudes in the Pythagorean triangle with sides 3, 4, 5), in the third example we got an obtuse triangle.

To avoid problems with names, the graphical structure for each triangle is created using plots:-display command. The animation was not as fast, on each triangle is given 5 frames:

restart;
with(plots):
with(geometry):
for a from 4 to 6 do
b:=a+1: c:=a+2:
angA:=arccos((a+5)/2/(a+2));
point(A,0,0): point(B,c*cos(angA),c*sin(angA)): point(C,a+1,0):
t1||a:=display(draw(triangle(T1||a,[A,B,C]))):
end do:
 
display(seq(t1||i$5, i=4..6), insequence=true, scaling=constrained);

                    

 

Addition. When working with graphics, in particular when creating animations, I almost never use  geometry:-draw  command. I prefer  plot  command, as well as the various commands from  plots  and  plottools  packages. Also, instead of a  for loop, it is more convenient to use  seq  command. Here is the same animation with this technique with the addition of labels for the vertices of triangles:

restart;
with(plots):
angA:=arccos((a+5)/2/(a+2)): 
V:=[seq([[0,0],[(a+2)*cos(angA),(a+2)*sin(angA)],[a+1,0],[0,0]], a=4..6)]: NV:=[A,B,C]:
T:=seq(textplot([seq([V[i,j][],NV[j]], j=1..3)], font=[times,bold,18], align={above,left}),i=1..3):
display(seq(display(T[i],plot(V[i], color=red))$5,i=1..3), insequence, scaling=constrained);

                
Edit.

restart;
evalindets(u(i,j)^2*v(i,j)+u(i-1,j), 'specfunc(u)', f->subsop(1 = op(1,f)+1, f));
                                              
 u(i +1, j)^2*v(i, j) + u(i, j)                                       

or

restart;
evalindets(u[i,j]^2*v[i,j]+u[i-1,j], 'specindex(u)', f->subsop(1 = op(1,f)+1, f));
                                           
 u[i+1, j]^2*v[i, j]+u[i, j]



Edit.
                                                  

of the harmonic mean of the lengths of the three altitudes of the triangle ABC:

restart;
with(geometry):
triangle(ABC, [point(A,0,0),point(B,2,0), point(C,1,3)]):
altitude(hA, A, ABC): altitude(hB, B, ABC): altitude(hC, C, ABC):
line(AB,[A, B]): line(AC,[A, C]): line(BC,[B, C]):
intersection(A1,hA,BC): intersection(B1,hB,AC): intersection(C1,hC,AB): 
a:=simplify(distance(A,A1));
b:=simplify(distance(B,B1));
c:=simplify(distance(C,C1));
simplify(((a^(-1)+b^(-1)+c^(-1))/3)^(-1));
evalf(%);

 

Happy New Year to you!

restart;
with(GraphTheory):
A,B,C:=seq(RandomGraphs:-RandomGraph(8, 0.5), i=1..3);
plots:-display(DrawGraph~(<A | B | C>));

     

 


 

Obviously that the denominator is a periodic function (with respect to x-variable with period  2*Pi  and respect to t-variable with period  8*Pi ). Let us prove that the denominator of your fraction for any values of the variables is greater than 0. Due to the periodicity it is enough to check this on the rectangle  x=0..2*Pi , t=0..8*Pi . It's simplest to do this test geometrically. Here are two ways: using  plot3d  command and using  Explore command (we obtain slices of the graph  T(x,t)  for different  t ):

V := (x, t)->((5185/2592)*cos(x+(7/4)*t)+(5/72)*cos(3*x+(9/4)*t)+(1/18)*cos(2*x+(1/2)*t)+(1/72)*cos(4*x+4*t)+41489/20736)/``((5/36)*cos(x+(7/4)*t)+(1/32)*cos(2*x+(7/2)*t)+(5185/11664)*cos(3*x+(9/4)*t)+(1/2592)*cos(6*x+(9/2)*t)+(20737/41472)*cos(2*x+(1/2)*t)+(1297/10368)*cos(4*x+4*t)+29985553/26873856);
T:=expand(op(2,denom(V(x,t))));
plot3d(T, x = 0 .. 2*Pi, t = 0 .. 8*Pi, view = 0 .. 3, axes = normal);
Explore(plot(T, x=0..2*Pi, 0..3), t=0...evalf(8*Pi));


Analytically, we can establish the positivity of the denominator using  DirectSearch:-GlobalOptima  command:

DirectSearch:-GlobalOptima(T, [x = 0 .. 2*Pi, t = 0 .. 8*Pi]);


This package should be downloaded from the Maple Application Center and installed on your computer.

Use back quotes for this.

Example:


Addition. With back quotes you can make nonstandard names consisting of any symbols and even whole phrases, for example:

restart;
`My matrix`:=<1,2; 3,5>;
``('`My matrix`')^`-1`=`My matrix`^(-1);

                                                       

I propose a solution based on two procedures  SetPartition  and  Partition . More about them you can read  here  and  here. For completeness, I included the texts of both procedures in the worksheet below. The example is considered for 12 books, the number of pages for which are randomly generated. This method gives an exact solution, because is based on consideration of all variants of partitions.


 

SetPartition:=proc(S::set, Q::list(posint), K::symbol:=nonordered)  # Procedure finds all partitions of the set  S  into subsets of the specific size given Q.
local L, P, T, S1, S2, n, i, j, m, k, M;
uses ListTools,combinat;
if `+`(op(Q))<>nops(S) then error "Should be `+`(op(Q))=nops(S)" fi;
L:=convert(Q,set);
T:=[seq([L[i],Occurrences(L[i],Q)], i=1..nops(L))];
P:=`if`(K=ordered,convert(T,list),convert(T,set));
S1:=S;  S2:={`if`(K=ordered,[],{})}; n:=nops(P);
for i to n do
m:=P[i,1]; k:=P[i,2];
for j to k do
S2:={seq(seq(`if`(K=ordered,[op(s),t],{op(s),t}), t=choose(S1 minus `union`(op(s)),m)), s=S2)};
od; od;
if K=ordered then {map(op@permute,S2)[]} else S2 fi;
end proc:

Partition:=proc(n::nonnegint, k::{posint,range}, res::{range, nonnegint} := 1, S::set:={$0..n})  # Generates a list of all partitions of an integer n into k parts
local k_Partition, n1, k1, L;
k_Partition := proc (n, k::posint, res, S)
local m, M, a, b, S1, It, L0;
m:=S[1]; M:=S[-1];
if res::nonnegint then a := max(res,m); b := min(n-(k-1)*a,M)  else a := max(lhs(res),m); b := min(rhs(res),M) fi;
S1:={$a..b} intersect S;
if b < a or b*k < n or a*k > n  then return [ ] fi;
It := proc (L)
local m, j, P, R, i, N;
m := nops(L[1]); j := k-m; N := 0;
for i to nops(L) do
R := n-`+`(op(L[i]));
if R <= b*j and a*j <= R then N := N+1;
P[N] := [seq([op(L[i]), s], s = {$ max(a, R-b*(j-1)) .. min(R, b)} intersect select(t->t>=L[i,-1],S1) )] fi;
od;
[seq(op(P[s]), s = 1 .. N)];
end proc;
if k=1 then [[b]] else (It@@(k-1))(map(t->[t],S1))  fi;
end proc;
if k::posint then return k_Partition(n,k,res,S) else n1:=0;
for k1 from lhs(k) to rhs(k) do
n1:=n1+1; L[n1]:=k_Partition(n,k1,res,S)
od;
L:=convert(L,list);
[seq(op(L[i]), i=1..n1)] fi;
end proc:

roll := rand(100 .. 1000):
L := {seq([i, roll()], i = 1 .. 12)}:
L1:=map(t->t[2], L); # Number of pages in 12 books

{105, 199, 296, 382, 399, 400, 451, 649, 850, 858, 960, 989}

(1)

Parts := Partition(12, 3); # All possible partitions of the number 12 into 3 summands

[[1, 1, 10], [1, 2, 9], [1, 3, 8], [1, 4, 7], [1, 5, 6], [2, 2, 8], [2, 3, 7], [2, 4, 6], [2, 5, 5], [3, 3, 6], [3, 4, 5], [4, 4, 4]]

(2)

Mean := (1/3)*add(L[i, 2], i = 1 .. nops(L));

6538/3

(3)

evalf[4](Mean); # Number of pages for each worker

2179.

(4)

Err := infinity:
for p in Parts do S := SetPartition(L, p);
for s in S do r := max(seq(abs(`+`(seq(s[i, j, 2], j = 1 .. nops(s[i])))-Mean), i = 1 .. 3));
if r < Err then Sol := s; Err := r end if end do end do:
evalf[2](Err);  # The maximum deviation from Mean
map(t->[seq(t[i, 2], i = 1 .. nops(t))], convert(Sol, list)); # The final result

20.

 

[[858, 850, 451], [960, 199, 649, 382], [989, 400, 105, 399, 296]]

(5)

add~(%);

[2159, 2190, 2189]

(6)

 


 

Download Division_of_books.mw

Instead of  test relation  command from the pop-up window, use  is  command. It makes easy to add other commands or assuming option:

R := sin(Pi*x/T)*cos(Pi*x/T) = 1/2*(sin(Pi*x/T+Pi*x/T)+sin(Pi*x/T-Pi*x/T)):
is(combine(R));
                                         
  true


Another example:

      

 

Addition. Now as for your first example. Maple is more suitable for calculations, and not for the proof of various symbolic identities. In your example, m is an arbitrary positive integer. If you specify its value, then there are no problems:

restart;
P := a[0]+Sum((2*(1-(-1)^k))/T*(Int(cos(2*Pi*k*x/T), x = 0 .. t)), k = 1 .. m);
Q := a[0]+Int(Sum(2*(1-(-1)^k)/T*cos(2*Pi*k*x/T), k=1..m), x=0..t);
is(value(eval(P=Q, m=10)));

                 

 

1. Unfortunately in your code, the equations of the trajectory of motion as a function of time are not indicated. Then you could write a much more compact code that calculates the coordinates of the vectors you are interested in for any  t .

2. To plot vectors (arrows) in space, you can use  plots:-arrow  command.

See corrected code

Simplification1.mw

 

Edit.

We do not need ourselves to write the code for the solution by Runge-Kutta method. As it is written in the help by default  dsolve command with  numeric  option finds the numerical solution using a Fehlberg fourth-fifth order Runge-Kutta method (rkf45  method). Here is the solution of your problem with specific values of the parameters and the plot of this solution:

restart;
Sol:=dsolve({m*l*diff(theta(t),t,t)+b*diff(theta(t),t)+m*g*sin(theta(t))=A*cos(omega*t), theta(0)=1, D(theta)(0)=0}, theta(t), numeric, parameters=[m,l,g,b,A,omega]);
Sol(parameters=[1,2,9.8,1,4,0.3]):
plots:-odeplot(Sol, [t,theta(t)], t=0..40, size=[900,300]);

               

 

 

In Maple 2017.3 :

Eq:=diff(u(x,y),x,x)+diff(u(x,y),y,y)=0;
bc:=u(x,0)=0, u(x,a)=0, u(0,y)=sin(y), u(infinity,y)=0;
pdsolve({Eq, bc}, u(x,y)) assuming a>0; 
# The symbolic result
F:=eval(rhs(%), [a=5, infinity=50]);  # An approximate result for plotting
plot3d(F, x=0..5, y=0..Pi);  # Visualization

          

                   

             

First 135 136 137 138 139 140 141 Last Page 137 of 290