Kitonum

21530 Reputation

26 Badges

17 years, 86 days

MaplePrimes Activity


These are answers submitted by Kitonum

The plot of the function  psi(x,eta) = x*f(eta)+int(h(s), s = 0 .. eta):


restart;

eq1:=diff(f(eta),eta,eta,eta)+f(eta)*diff(f(eta),eta,eta)-(diff(f(eta),eta))^2+1:

eq2 := diff(h(eta),eta,eta)+f(eta)*diff(h(eta),eta)-diff(f(eta),eta)*h(eta):

bc:=f(0)=0,D(f)(0)=0,D(f)(6)=1,h(0)=0,D(h)(6)=1:

A1:=dsolve({eq1,eq2,bc}, numeric, method=bvp[midrich], abserr = 1.*10^(-10), output=operator);

plot3d(eval(x*f(eta)+int(h(s), s = 0 .. eta), A1), x=0..1, eta=0..1, axes=normal); 

 

Tilde means element-wise operator.  Let  P  is any command.

P~([A, B, C]);  

is equivalent to

[P(A), P(B), P(C)]; 

 

Tilde as the element-wise operator appeared in Maple 13 or Maple 14. Instead tilde, you can use the older command  map :

map(P, [A, B, C]);

 

For details see help  ?element-wise operators   and   ?map

 

 

Your example:

a := 4;

b := 5;

cat(`a+b`,` = `, convert(a,symbol)+convert(b,symbol), ` = `, a+b);

                                        

 

 

 

I used the excellent  vv's idea of reducing the problem to the study of a function of one variable  t . Substitution  x=t/n  works for all  n<>0 . The case  n=0  is trivial and can be easily dealt with separately. Because  yy  is periodic with the period  2*Pi, it is enough to look for the maximum in the range  0..2*Pi .

Here is a symbolic solution:

y := 0.11083e-1+0.66489e-1*cos(n*x)+0.22089e-1*cos(2*n*x)+0.8903e-2*cos(3*n*x)-0.293e-3*cos(4*n*x):

yy := convert(subs(x = t/n, y), fraction);

maximize(yy, t = 0 .. 2*Pi, location);  # location option gives values  t  for maximum points

plot(yy, t = 0 .. 2*Pi);  # Visual verification

                     

 

 

 

 

Custom procedure  P  makes it faster:

restart;

P:=proc(M1::posint,M2::posint)

local A, B, k, r, c;

A:=M1; B:=M2;

k:=0:

while B>0 do

r:=irem(A,B,'q'):  A:=B:  B:=r:

k:=k+1: c[k]:=q:

od:

convert(c, list);

end proc:

 

M1:=146996733613391:

M2:=1348471408813:

teks:= CodeTools:-Usage(P(M1,M2));

    

I did not realize what time you want to reduce. If you need a custom code that solves the same problem, here it is

restart;

M1:=146996733613391:

M2:=1348471408813:

k:=0:

while M2>0 do

r:=irem(M1,M2,'q'):  M1:=M2:  M2:=r:

k:=k+1: c[k]:=q:

od:

convert(c, list);

                                 [109, 101, 115, 115, 97, 103, 101]

t:= `Hello Bob  `;

cat(t$5);

Slightly more efficient will be the enumeration in a nested seq . Also I use LinearAlgebra[Determinant] mod 2 :

restart;

NestedSeq:=proc(Expr::algebraic, L::list)

local S;

eval(subs(S=seq, foldl(S, Expr, op(L))));

end proc:

M:=[i||(1..16)]:

GROUP:=[NestedSeq('`if`(LinearAlgebra[Determinant](Matrix(4, M)) mod 2<>0, cat(op(M)), NULL)',M=~0..1)]:

nops(GROUP);

                                                      20160

 

Perhaps you have confused  YP__1  with  YP[1] . These are different things. The first is a simple symbol, which look like an indexed symbol, the second is a true indexed symbol.  Compare what they look like in output:

restart;

whattype ~ ([YP__1, YP[1]]);

YP__1, YP[1];

                                

 

If they are not confused with one another, then everything is OK:

Eq:= YP[1]=Y[2]:

subs(YP[1]=dGx, Eq);

or

Eq:= YP__1 = Y__2:

subs(YP__1=dGx, Eq);

 

 

 

 

If some elements are repeated in a list,  ListTools:-SearchAll  command finds all the positions:

L := [x,z,y,x,x,z]:

ListTools:-SearchAll(x, L);

                                            1, 4, 5

 

Similar commands there are in  StringTools  package.

This is a less elegant way than the previous 2 methods, but it is conceptually simpler and more general, since it allows you to apply some manipulations to an explicitly specified elements of a list.

A := [[2,3], [4,5], [6,7]]:

[seq(A[i,1]/A[i,2], i=1..nops(A))];

                                                [2/3, 4/5, 6/7]

 

The same can be done not only with the lists, but with the other objects (sequences, sets, vectors, matrices, etc.)

For the column names you can use uppercase letters, for example,  U0, U1, U2  and so on. Maple distinguishes between uppercase and lowercase letters.

LengthOfIntersection procedure finds in the form of an explicit piecewise function the length intersection of 2 segments (real closed intervals) (see the original question). Now we can not only find this length for a given x, but also differentiate, integrate, etc.

LengthOfIntersection := proc (x::name, A::list(realcons), B::list(realcons))

local h, B1, d;

h := min(A[2]-A[1], B[2]-B[1]);

d := abs(B[2]-B[1]-A[2]+A[1]);

B1 := B+~x;

piecewise(convert(solve(B1[2] <= A[1], {x}), `and`), 0,

convert(solve({B1[2] < A[1]+h, A[1] < B1[2]}, {x}), `and`), B1[2]-A[1],

convert(solve({B1[2] <= A[1]+h+d, A[1]+h <= B1[2]}, {x}), `and`), h,

convert(solve({B1[1] < A[2], A[1]+h+d < B1[2]}, {x}), `and`), A[2]-B1[1],

convert(solve(A[2] <= B1[1], {x}), `and`), 0);

end proc:

 

Examples of use:

f := unapply(LengthOfIntersection(x, [1, 3], [0, 5]), x):

f(x);

f(2);

diff(f(x), x);

int(f(x), x = -4 .. 3);

plot(f, -5..5, color=red, thickness=3, scaling=constrained);

                                                     

 

                                              

 

You can do 

for i to 4 do i^2 end do;

i;

i := 'i'; 

i;

 

Now  i  is symbol

whattype(i);

                                  symbol

Alternative option:

V:=[a5, a6, a7]:

map(t->[t,0], V):

seq(seq(seq([i,j,k], k=%[3]), j=%[2]), i=%[1]);

    

 

 

First 188 189 190 191 192 193 194 Last Page 190 of 290