Kitonum

21435 Reputation

26 Badges

17 years, 25 days

MaplePrimes Activity


These are answers submitted by Kitonum

Use  Physics:-diff  command for this:

restart;
alias(q = q(x, t), p = p(x, t));                             
H := lambda*p*q+conjugate(lambda)*conjugate(p)*conjugate(q)+(1/2*(p^2+conjugate(q)^2))*(conjugate(p)^2+q^2);                                   
Physics:-diff(H, q);

                   

If you use the kernel  diff command, then the second argument in it should be a name and not a function, for example  should be  diff(sin(x^2), x)  rather than  diff(sin(x^2), x^2)

In my opinion, a more expressive result is obtained by a significantly simpler and shorter code. Why to color the lines if the surface is painted and why to rename the imaginary unit?

restart:
f:= (x,y)-> Re(sqrt(x+I*y)):
A:=plot3d([x, y, f(x,y)],x= -1..1, y= -1..1,grid= [25$2], color=f(x,y), labels= ['x', 'y',  Re(sqrt(x+I*y))], labelfont=[times,14]):
B:=plottools:-reflect(A,[[0,0,0],[1,0,0],[0,1,0]]):
 plots:-display(A,B, axes=frame, orientation=[40,80], lightmodel=light1);

                 

   
 Such coloring emphasizes the mutual opposite of these surfaces to regard to the plane z=0.      

Here is a simple solution without DEtools package. Since you did not specify specific initial conditions, I took arbitrary  x1(0) = x10, x2(0) = x20

restart;
x:=t-><x1(t),x2(t)>;
A:=<1,-2; 4,-5>;
b:=<3,7>;
eq:=diff(x(t),t)=A.x(t)+b;
S:=Equate(op(eq));
ics:=<x10,x20>;
seq(x(0)=~ics);
Sol:=dsolve({S[],seq(x(0)=~ics)}, {seq(x(t))});



Edit. The following extra code converts the Sol (see the code above) into matrix/vector form:

Y1:=coeff(rhs(Sol[1]),exp(-t)); Y2:=coeff(rhs(Sol[1]),exp(-3*t));
Sol1:=simplify(Sol,{Y1=X1,Y2=X2});
Sol2:=(rhs=lhs)~(Sol1);
LinearAlgebra:-GenerateMatrix(Sol2,[X1,X2]);
A1,B:=%[1], x(t)-%[2];
x(t)=A1%.<Y1,Y2>+B;  # The final result

is(convert(Equate(op(value(%))),set)=Sol);  # Check

The final result (although it’s certainly easier to get it out of  Sol  manually):


DE.mw

de:=diff(y(x),x,x) - y(x) = -4*sin(x)^3 + 9*sin(x);
dsolve({de, y(0)=y(2*Pi)}, y(x));  

                  

We see that the solution depends on one arbitrary constant  _C1 .

Here is another way to solve the original problem. We do not add a specific extra condition, but  remove the condition  y(L)=0 , leaving one condition  y(0)=0 . We get a general solution with one arbitrary constant  _С1  (then we re-designate it  as  C ). Then we impose the condition  y(L)=0  and thus get the general solution to the original problem. As an example, we find the first particular solution obtained by Rouben Rostamian, imposing additional conditions  n=10, D(y)(0)=1 :

restart; 	
de := diff(y(x),x,x) + a*y(x) = 0;
Sol:=dsolve({de,y(0)=0}, y(x));
y:=unapply(eval(eval(y(x),Sol),_C1=C), x);
a:=solve(y(L)=0,a, allsolutions);
about(_Z1);
a:=eval(a,_Z1=n);
y(x);
y:=unapply(simplify(%), x) assuming L>0,n::posint; # This is the general solution to de
eval(de,x=0), eval(de,x=L);  # Check

n:=10: # Example of  Rouben Rostamian
C0:=solve(D(y)(0)=1, C);
eval(y(x),C=C0);

  

 
df.mw

If you mean polynomial interpolation, then use  CurveFitting:-PolynomialInterpolation  command. Before this, replace each curly brace with a square one, because in Maple braces creates a set, and we need lists.

data := [[13, -2], [12, -1], [11, 0.0], [10, 1], [9, 2], [8, 3], [7, 
   4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]]:
CurveFitting:-PolynomialInterpolation(data, x);

Output:                         11.-1.*x


We see that all these points lie on one straight line  y = 11 - x . Visualization confirms the result:

with(plots):
display(pointplot(data), plot(11-x, x=1..13), view=[0..13,-2..10]);

                      

 

It is impossible to understand from OP's code whether he is trying to calculate the gradient of the function of two variables (this is a vector) or the mixed partial derivative with respect to variables  x1  and   x2  (this is a scalar). In both cases there is no need to call any packages (it will be shorter and faster).

restart;
x:=<x1,x2>:
W:=<<w11, w12>|<w21, w22>>;
Cal:=(W.x)^%T.(W.x);
<seq(diff(Cal,t),t=x)>;  # Gradient
diff(Cal,x1,x2); # Partial derivative 

 

I propose a different approach to the solution. First we select  6  different integers (I chose numbers in the range  1 .. 10 ), and then we solve the corresponding system (here I took  t=1). as it was done in your previous post for numbers  1 .. 6 . Thus,  71  solutions have been found that satisfy all your conditions. Unfortunately, the code runs rather slowly (it took about 45 minutes), because Maple takes about 11 seconds to solve one system. As an example, the graph of  f(x)  is plotted for one solution.
 

restart;
t:=1:
f:=x->abs(a*x+b)+abs(c*x+d)-t*x^2+m*x-n:
P:=combinat:-choose(10,6):
k:=0:
for p in P do
X:=[solve({seq(f(x),x=p)})];
if andmap(t->type(rhs(t),integer),X[1]) then k:=k+1; L[k]:=[p,X[1]] fi;
od:
k;
L:=convert(L,list);
 

71

 

[[[1, 2, 3, 4, 5, 6], {a = -2, b = 5, c = 2, d = -9, m = 7, n = 16}], [[1, 2, 3, 4, 5, 8], {a = -2, b = 5, c = 3, d = -14, m = 8, n = 21}], [[1, 2, 3, 4, 5, 10], {a = -2, b = 5, c = 4, d = -19, m = 9, n = 26}], [[1, 2, 3, 4, 6, 7], {a = -2, b = 5, c = 3, d = -15, m = 8, n = 22}], [[1, 2, 3, 4, 6, 9], {a = -2, b = 5, c = 4, d = -21, m = 9, n = 28}], [[1, 2, 3, 4, 7, 8], {a = -2, b = 5, c = 4, d = -22, m = 9, n = 29}], [[1, 2, 3, 4, 7, 10], {a = -2, b = 5, c = 5, d = -29, m = 10, n = 36}], [[1, 2, 3, 4, 8, 9], {a = -2, b = 5, c = 5, d = -30, m = 10, n = 37}], [[1, 2, 3, 4, 9, 10], {a = -2, b = 5, c = 6, d = -39, m = 11, n = 46}], [[1, 2, 3, 6, 7, 8], {a = -3, b = 8, c = 3, d = -19, m = 9, n = 29}], [[1, 2, 3, 6, 7, 10], {a = -3, b = 8, c = 4, d = -26, m = 10, n = 36}], [[1, 2, 3, 6, 8, 9], {a = -3, b = 8, c = 4, d = -27, m = 10, n = 37}], [[1, 2, 3, 6, 9, 10], {a = -3, b = 8, c = 5, d = -36, m = 11, n = 46}], [[1, 2, 3, 8, 9, 10], {a = -4, b = 11, c = 4, d = -33, m = 11, n = 46}], [[1, 2, 4, 5, 6, 7], {a = -3, b = 9, c = 2, d = -11, m = 8, n = 22}], [[1, 2, 4, 5, 6, 9], {a = -3, b = 9, c = 3, d = -17, m = 9, n = 28}], [[1, 2, 4, 5, 7, 8], {a = -3, b = 9, c = 3, d = -18, m = 9, n = 29}], [[1, 2, 4, 5, 7, 10], {a = -3, b = 9, c = 4, d = -25, m = 10, n = 36}], [[1, 2, 4, 5, 8, 9], {a = -3, b = 9, c = 4, d = -26, m = 10, n = 37}], [[1, 2, 4, 5, 9, 10], {a = -3, b = 9, c = 5, d = -35, m = 11, n = 46}], [[1, 2, 4, 7, 8, 9], {a = -4, b = 13, c = 3, d = -22, m = 10, n = 37}], [[1, 2, 4, 7, 9, 10], {a = -4, b = 13, c = 4, d = -31, m = 11, n = 46}], [[1, 2, 5, 6, 7, 8], {a = -4, b = 14, c = 2, d = -13, m = 9, n = 29}], [[1, 2, 5, 6, 7, 10], {a = -4, b = 14, c = 3, d = -20, m = 10, n = 36}], [[1, 2, 5, 6, 8, 9], {a = -4, b = 14, c = 3, d = -21, m = 10, n = 37}], [[1, 2, 5, 6, 9, 10], {a = -4, b = 14, c = 4, d = -30, m = 11, n = 46}], [[1, 2, 5, 8, 9, 10], {a = -5, b = 19, c = 3, d = -25, m = 11, n = 46}], [[1, 2, 6, 7, 8, 9], {a = -5, b = 20, c = 2, d = -15, m = 10, n = 37}], [[1, 2, 6, 7, 9, 10], {a = -5, b = 20, c = 3, d = -24, m = 11, n = 46}], [[1, 2, 7, 8, 9, 10], {a = -6, b = 27, c = 2, d = -17, m = 11, n = 46}], [[1, 4, 5, 6, 7, 8], {a = -3, b = 13, c = 2, d = -13, m = 10, n = 30}], [[1, 4, 5, 6, 7, 10], {a = -3, b = 13, c = 3, d = -20, m = 11, n = 37}], [[1, 4, 5, 6, 8, 9], {a = -3, b = 13, c = 3, d = -21, m = 11, n = 38}], [[1, 4, 5, 6, 9, 10], {a = -3, b = 13, c = 4, d = -30, m = 12, n = 47}], [[1, 4, 5, 8, 9, 10], {a = -4, b = 18, c = 3, d = -25, m = 12, n = 47}], [[1, 4, 6, 7, 8, 9], {a = -4, b = 19, c = 2, d = -15, m = 11, n = 38}], [[1, 4, 6, 7, 9, 10], {a = -4, b = 19, c = 3, d = -24, m = 12, n = 47}], [[1, 4, 7, 8, 9, 10], {a = -5, b = 26, c = 2, d = -17, m = 12, n = 47}], [[1, 6, 7, 8, 9, 10], {a = -4, b = 25, c = 2, d = -17, m = 13, n = 48}], [[2, 3, 4, 5, 6, 7], {a = -2, b = 7, c = -2, d = 11, m = 9, n = 24}], [[2, 3, 4, 5, 6, 9], {a = -2, b = 7, c = -3, d = 17, m = 10, n = 30}], [[2, 3, 4, 5, 7, 8], {a = -2, b = 7, c = -3, d = 18, m = 10, n = 31}], [[2, 3, 4, 5, 7, 10], {a = -2, b = 7, c = -4, d = 25, m = 11, n = 38}], [[2, 3, 4, 5, 8, 9], {a = -2, b = 7, c = -4, d = 26, m = 11, n = 39}], [[2, 3, 4, 5, 9, 10], {a = -2, b = 7, c = -5, d = 35, m = 12, n = 48}], [[2, 3, 4, 7, 8, 9], {a = -3, b = 11, c = -3, d = 22, m = 11, n = 39}], [[2, 3, 4, 7, 9, 10], {a = -3, b = 11, c = -4, d = 31, m = 12, n = 48}], [[2, 3, 5, 6, 7, 8], {a = -3, b = 12, c = -2, d = 13, m = 10, n = 31}], [[2, 3, 5, 6, 7, 10], {a = -3, b = 12, c = -3, d = 20, m = 11, n = 38}], [[2, 3, 5, 6, 8, 9], {a = -3, b = 12, c = -3, d = 21, m = 11, n = 39}], [[2, 3, 5, 6, 9, 10], {a = -3, b = 12, c = -4, d = 30, m = 12, n = 48}], [[2, 3, 5, 8, 9, 10], {a = -4, b = 17, c = -3, d = 25, m = 12, n = 48}], [[2, 3, 6, 7, 8, 9], {a = -4, b = 18, c = -2, d = 15, m = 11, n = 39}], [[2, 3, 6, 7, 9, 10], {a = -4, b = 18, c = -3, d = 24, m = 12, n = 48}], [[2, 3, 7, 8, 9, 10], {a = -5, b = 25, c = -2, d = 17, m = 12, n = 48}], [[2, 5, 6, 7, 8, 9], {a = -3, b = 16, c = -2, d = 15, m = 12, n = 41}], [[2, 5, 6, 7, 9, 10], {a = -3, b = 16, c = -3, d = 24, m = 13, n = 50}], [[2, 5, 7, 8, 9, 10], {a = -4, b = 23, c = -2, d = 17, m = 13, n = 50}], [[3, 4, 5, 6, 7, 8], {a = -2, b = 9, c = -2, d = 13, m = 11, n = 34}], [[3, 4, 5, 6, 7, 10], {a = -2, b = 9, c = -3, d = 20, m = 12, n = 41}], [[3, 4, 5, 6, 8, 9], {a = -2, b = 9, c = -3, d = 21, m = 12, n = 42}], [[3, 4, 5, 6, 9, 10], {a = -2, b = 9, c = -4, d = 30, m = 13, n = 51}], [[3, 4, 5, 8, 9, 10], {a = -3, b = 14, c = -3, d = 25, m = 13, n = 51}], [[3, 4, 6, 7, 8, 9], {a = -3, b = 15, c = -2, d = 15, m = 12, n = 42}], [[3, 4, 6, 7, 9, 10], {a = -3, b = 15, c = -3, d = 24, m = 13, n = 51}], [[3, 4, 7, 8, 9, 10], {a = -4, b = 22, c = -2, d = 17, m = 13, n = 51}], [[3, 6, 7, 8, 9, 10], {a = -3, b = 19, c = -2, d = 17, m = 14, n = 54}], [[4, 5, 6, 7, 8, 9], {a = -2, b = 11, c = -2, d = 15, m = 13, n = 46}], [[4, 5, 6, 7, 9, 10], {a = -2, b = 11, c = -3, d = 24, m = 14, n = 55}], [[4, 5, 7, 8, 9, 10], {a = -3, b = 18, c = -2, d = 17, m = 14, n = 55}], [[5, 6, 7, 8, 9, 10], {a = -2, b = 17, c = -2, d = 13, m = 15, n = 60}]]

(1)

L1:=select(s->abs(eval([b,d,n],s[2])[1])+abs(eval([b,d,n],s[2])[2])<>eval([b,d,n],s[2])[3], L):
nops(L1);

71

(2)

 

plot(eval(f(x), L[37,2]), x=0..11);

  

 

 


 

Download intsol.mw

If you still want to use the standard notation  |v|  for the Euclidean length of the vector  v , then first run this code (VectorCalculus package is not needed). Using code in  2Dmath  only:

 

restart; _local(`LinearAlgebra:-Determinant`); alias(LinearAlgebra:-Determinant = (proc (v) options operator, arrow; sqrt(LinearAlgebra:-Determinant(Matrix([[v^%T.v]]))) end proc))

LinearAlgebra[Determinant](`<,>`(3, 0, 4)); LinearAlgebra[Determinant](`<,>`(3, 4)); LinearAlgebra[Determinant](`<,>`(1, 1, 1, 1))

5

 

5

 

2

(1)

 


 

Download v1.mw

 Pascal4QM  you wrote  "...difficult to generilize to an arbitrary number of nested sums."

Here are 2 procedures for working with nested sums of arbitrary nesting order. The first procedure allows you to automatically generate a nested sum of any nesting order. The second procedure changes the summation order for an existing nested sum.


 

restart;

Two procedures

NestedSum:=proc(Expr::uneval, L::list)
local S;
eval(subs(S=Sum, foldl(S, Expr, op(L))));
end proc:

ReverseSum:=proc(Expr)
local NestingOrder, n;
NestingOrder:=i->op(([1$i],Expr));
for n from 1 while has(NestingOrder(n),Sum) do
od:
eval(NestedSum(op([1$n],Expr),[seq(op([1$k,2],Expr),k=0..n-1)]));
end proc:

Examples of use

 

A:=NestedSum(f,[seq(x||i=1..10,i=1..5)]);
ReverseSum(A);

Sum(Sum(Sum(Sum(Sum(f, x1 = 1 .. 10), x2 = 1 .. 10), x3 = 1 .. 10), x4 = 1 .. 10), x5 = 1 .. 10)

 

Sum(Sum(Sum(Sum(Sum(f, x5 = 1 .. 10), x4 = 1 .. 10), x3 = 1 .. 10), x2 = 1 .. 10), x1 = 1 .. 10)

(1)

 


 

Download Nested_Sum1.mw

A:=Sum(Sum(f[n]*g[q-n]*exp(2*I*Pi*q*x),q = -infinity .. infinity),n = -infinity ..infinity);
Sum(Sum(op([1,1],A),op(2,A)),op([1,2],A));

                                     

The imaginary unit in Maple is coded as  I , not as i.

       

You have already been answered that  Optimization:-Minimize does not solve the problem. But if you are looking for software that does this, then try the  DirectSearch  package. It is not part of the Maple library and must be loaded from  Maple Application Center. See
https://www.maplesoft.com/applications/view.aspx?SID=101333

Example of work:
 

restart;
with(DirectSearch):

f:=sin(3*x)/x;
plot(f,x=0..10);
GlobalSearch(f,[x=0..10]); # All the minimum points
GlobalSearch(f,[x=0..10], maximize); # All the maximum points

f := sin(3*x)/x

 

 

_rtable[4637529922]

 

Array(%id = 4749824450)

(1)


 

Download DS.mw

for c from 1 to 10 do
p||c := plot( x^c, x= -1..1, title= typeset("The power is  ", c) )
end do:
p3;

                        


Edit. As acer showed your problem can be solved in many other ways. But if it is necessary to combine text and more complex math, then I do not know any other simple way than using  typeset . See the example:

f:=cos(3*x)/(x^2+1):
plot(f, x= -4..4, title= typeset("The plot of the function  ", y= f), titlefont=[times,bold,16], scaling=constrained, size=[800,300] );

     


See help for details  ?plot,typesetting

I think the problem with your calculation is that the function  cot(x)  is infinity  if  x=Pi*k , k is integer. But if the integration range does not contain these points, then the integral can be calculated as below:

restart;
U:=(x,z)->-1/(x^2+a^2)*cos(x)*(cos(sqrt(x^2*(x^2+1)/(x^2+2))*z)-cot(sqrt(x^2*(x^2+1)/(x^2+2))*L)*sin(sqrt(x^2*(x^2+1)/(x^2+2))*z));
L:=10: a:=1:
V:=(X,Z)->evalf(Int(U(x,z),[x=0.1..X,z=0.1..Z]));
plot3d(V,0.1..0.4, 0.1..0.4);

     

 


 

Download doubleint.mw

Maple has a huge number of specialized packages, and it is not always easy for a beginner (and often an experienced user) to find the right command and understand all of its options. Fortunately, the same problem can be solved by various methods. If we are talking about plotting some kind of graphic objects, then in addition to the commands of the kernal (plot  and  plot3d), it is very important to master the main commands from the packages  plots  and  plottools . When working with lists, the  ListTools  package is very often used. Below your problem is solved using these packages without the  Statistics  package. This should work on any version of Maple.

L := [1,2,2,2,3,3,4,4,5,5,6,6]:
n:=nops(L);
L1:=ListTools:-Collect(L); m:=nops(L1);
S:=seq(plottools:-rectangle([i-1/2,L1[i,2]/n],[i+1/2,0],color="LightBlue"),i=1..m):
plots:-display(S, view=[0..m+1,0..0.3]);

            


This method allows you to easily diversify the shape of graphic objects. For example, instead of rectangles, it is easy to plot triangles or other shapes.

 

S1:=seq(plottools:-polygon([[i-1/2,0],[i,L1[i,2]/n],[i+1/2,0]],color="LightBlue"),i=1..m):
plots:-display(S1, view=[0..m+1,0..0.3]);

                   

 
Histograms.mw          

 

First 69 70 71 72 73 74 75 Last Page 71 of 289