Kitonum

21445 Reputation

26 Badges

17 years, 47 days

MaplePrimes Activity


These are answers submitted by Kitonum

This means extraction the sequence of expressions from a list  or a set. [...][]  or  {...}[]  are equivalent to  op([...])  or  op({...})

 

Addition: see help on  set  or  list

The procedure  Sort  solves the problem. In  Sort procedure  the procedure  OrderOfDerivative , which returns the order of derivatives, was used.

restart;

OrderOfDerivative:=proc(A)

local n, A1;

n:=0;

A1:=A;

while op(0,A1)=diff do

A1:=op(A1)[1]; n:=n+1;

od;

n;

end proc:

 

Example of use:

OrderOfDerivative(diff(x(t),t,t));

                               2

 

The code of the basic procedure  Sort :

Sort:=proc(Expr)

local  L;

L:=sort([op(Expr)], (a,b)->OrderOfDerivative(indets(a, `function`)[1])>=OrderOfDerivative(indets(b, `function`)[1]) );  # The sorted list of op(Expr)

``(add(select(s->has(s,diff), L)))+add(select(s->not has(s,diff), L));  # Conversation  L  into  sum

end proc:

 

 

Example of use:

Expr:=a*diff(x(t),t)+b*x(t)+r*diff(x(t),t,t)+a*diff(y(t),t)+b*diff(y(t),t,t)+c*y(t): # The initial expression

Sort(Expr);

             

 

 

Unfortunately we have to "freeze" the terms with derivatives by the construction ``(...), or in the process of summing elements of the list  L  Maple randomly rearranges the list of terms.


  

The simple procedure  Hist  builds a histogram for any lists  X  and  P  and the width  h . The options are:  C  is the color of filling (by default  blue) and  V is the view of the plot.

Hist := proc (X::list, P::list, h::numeric, C::{string, symbol} := blue, V::list := [X[1]-0.6*h .. X[-1]+0.6*h, 0 .. max(P)])

local n, S, A, B;

n := nops(X);

S := seq(piecewise(X[i]-(1/2)*h <= x and x <= X[i]+(1/2)*h, P[i]), i = 1 .. n);

A := plot([S], x = X[1]-(1/2)*h .. X[n]+(1/2)*h, color = C, filled);

B := plot([S], x = X[1]-0.51*h .. X[n]+0.51*h, tickmarks = [default, [seq(P[i] = P[i], i = 1 .. n)]], color = black, thickness = 2);

plots:-display(A, B, view = V);

end proc:

 

The initial example:

Hist([1, 3, 5, 7], [1/8, 1/4, 1/2, 1/8], 1.8);

                              

 

The second example with 2 used options:

Hist([1, 2, 3, 4], [1/8, 1/4, 1/2, 1/8], 0.8, cyan, [-0.5 .. 5.2, -0.05 .. 0.6]);

                               

 

 

 

In order that the surface was more like your picture I did:

1) Removed the plane  x=0.

2) Changed the sign in front of  z -term.

3) Changed the scaling along the  y-axis.

3) Added the plotting of the Bifurcation Set (op(eliminate({f, implicitdiff(f, y, x)}, x)[2]) = 0  is the projecting surface onto x=-7):

 

f := x^3-x*z+(1/3)*y:

A := plots[implicitplot3d](f, x = -7 .. 5, y = -50 .. 50, z = -5 .. 7, axes = boxed, grid = [60, 60, 60], style = surface, color = khaki, orientation = [175, -20, 15], lightmodel = light1):

B := plots[intersectplot](x+7 = 0, op(eliminate({f, implicitdiff(f, y, x)}, x)[2]) = 0, x = -7 .. 5, y = -50 .. 50, z = -5 .. 7, color = red, thickness = 4, linestyle = solid):  #  Bifurcation Set

C := plots[implicitplot3d](x = -7, x = -7 .. 5, y = -50 .. 50, z = -5 .. 7, style = surface, color = "LightGrey"):  # The plane  x=-7

plots[display](A, B, C); 

                              

 

 

 Edited.

 

 

Here's an example of another way to solve this problem. This universal method allows you  from a list of certain objects to select objects that satisfy certain properties. I believe that all beginners must master this method:

restart;

A:=[2,4,6,8,10,12,8,6]:

select(i->A[i]=6, [$ 1..nops(A)]);

                                   [3, 8]

Procedure  SM  solves your problem:

SM:=proc(n)

local L;

uses combinat;

L:=permute([(-1)$n,1$n],n);

interface(rtablesize=infinity);

Matrix(L);

end proc:

 

Example of use:

SM(4);

                                     

 

 

 

Period  procedure finds the least positive period for all expressions of the form a linear combination of  {sin(a*t+a0), cos(b*t+b0), exp((c*t+c0)*I)}  with rational coefficients  a, b, c  and  a0, b0, c0  are any real constants.

Period:=proc(Expr)

local Expr1, S, T, T1, d;

Expr1:=evalc(subs(op(indets(Expr,symbol))=t, Expr));

S:=indets(Expr1,'trig') minus indets(Expr1,'realcons');

T:=map(s->coeff(op(1,s),t), S);

T1:=map(t->2/t,T);

d:=ilcm(op(denom~(T1)));

ilcm(op(d*~(T1)))/d*Pi;

end proc:

 

Examples of use:

Period(sin(t/2+sqrt(2))-4*cos(2*t/3-5));

                            12*Pi

Period(2+sin(3*x)+cos(2*x)-sin(x/2)+exp(7/2*I*x));

                             4*Pi

 

Edited.

Estimation  N=62/eps  is universal, but very overpriced. A direct calculation gives us the exact value of  integer positive  N  for each epsilon.

restart;

x:=n->n^2/(n^2+31*n+228);

x0:=limit(x(n), n=infinity);

N:=epsilon->max(1, floor(op(1, solve(abs(x(n)-x0)<=epsilon, n)[-1]))+1):

 

Example:

N(10^(-3));

                                  30977

Check:

evalf(abs(x(30977)-x0));

evalf(abs(x(30976)-x0));

                       0.0009999791325

                        0.001000011390

Edited. 

To find stationary points use  fsolve  as in the simple example:

deriv:=x->fdiff(2*t-t^2, t=x);

fsolve('deriv'(x)=0);

                                  1.000000000

 

or the most simple

fsolve(deriv);

                                  1.000000000

Just write:

restart;

vec:=<a, b, c>:

a:=1:

vec;

                       

 

 Addition: If you don't know the symbol for  vec[1]  then you can write:

restart;

vec:=<a,b,c>:

assign(vec[1], 1);

vec;

a;

                        

 

 

 

Error reason is that you miss the multiplication sign between  b  and subsequent expression in parentheses. In this case, Maple treats  b  as the function name, and the expression in parentheses as the argument of this function. Here is another example where this situation is evident:

eval(sin(x), sin=1);

                                            1

If you put a multiplication sign, the result is true:

c:=1/(b*(1+x/l));

eval(c, [b=1,l=1]);

                               

 

 

Another method with similar idea but slightly shorter:

eq := (-Omega^2*a*A[2]-Omega^2*m*B[1]+Omega*A[1]*c[1]+B[1]*k[1])*cos(Omega*t)+(Omega^2*a*B[2]-Omega^2*m*A[1]-Omega*B[1]*c[1]+A[1]*k[1])*sin(Omega*t) = 0:

eq1:=subs({sin(Omega*t)=s, cos(Omega*t)=c}, lhs(eq));

coeff(eq1, s);

coeff(eq1, c);

                

 

 

 

plots[inequal]  command allows you to get a high-quality picture:

plots[inequal]({y>=0, x^0.5+y^0.5<=2}, x=0..1, y=0..4, optionsfeasible=[color=yellow], optionsclosed=[color=blue, thickness=4], optionsexcluded=[color="WhiteSmoke"]);

                           

 

 Edit. The above variant works in Maple 2015. For older versions Maple use  filledregions=true  option. The result is the same:

A:=plot([solve(x^0.5+y^0.5-2, y), 0], x=0..1, color=blue, thickness=4):

B:=plots[implicitplot](x^0.5+y^0.5-2, x=0..1, y=0..4, coloring=[yellow, "WhiteSmoke"], filledregions=true, gridrefine=3):

plots[display](A, B);

 

tickmarks  option solves your problem.

Example:

A:= LinearAlgebra[RandomMatrix](8, generator=5..15):

plots[matrixplot](A, axes=normal, tickmarks=[[seq(i=eq||i,i=1..8)], [seq(i=q||i,i=1..8)], default], view=[0..9, 0..9, 0..17], axesfont=[TIMES,ROMAN,10], orientation=[25,75]);

                             

 

 

 

 

 

The symbol  r  is your fraction.

 

Coefficients_of_Fractions1.mw

First 193 194 195 196 197 198 199 Last Page 195 of 289