Kitonum

21840 Reputation

26 Badges

17 years, 225 days

MaplePrimes Activity


These are answers submitted by Kitonum

In this example, we generated an arbitrary polynomial of the third degree in 5 variables. But the method itself is of a general nature and it can be used to generate a polynomial of any degree and any number of variables.


 

restart;

var:=[x,y,z,t,s]: n:=nops(var): m:=3:

L:=ListTools:-Reverse(convert(map(t->(t)-~1,`union`(seq(combinat:-composition(n+i,n), i=0..m))),list));

[[3, 0, 0, 0, 0], [2, 1, 0, 0, 0], [2, 0, 1, 0, 0], [2, 0, 0, 1, 0], [2, 0, 0, 0, 1], [2, 0, 0, 0, 0], [1, 2, 0, 0, 0], [1, 1, 1, 0, 0], [1, 1, 0, 1, 0], [1, 1, 0, 0, 1], [1, 1, 0, 0, 0], [1, 0, 2, 0, 0], [1, 0, 1, 1, 0], [1, 0, 1, 0, 1], [1, 0, 1, 0, 0], [1, 0, 0, 2, 0], [1, 0, 0, 1, 1], [1, 0, 0, 1, 0], [1, 0, 0, 0, 2], [1, 0, 0, 0, 1], [1, 0, 0, 0, 0], [0, 3, 0, 0, 0], [0, 2, 1, 0, 0], [0, 2, 0, 1, 0], [0, 2, 0, 0, 1], [0, 2, 0, 0, 0], [0, 1, 2, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 0, 1], [0, 1, 1, 0, 0], [0, 1, 0, 2, 0], [0, 1, 0, 1, 1], [0, 1, 0, 1, 0], [0, 1, 0, 0, 2], [0, 1, 0, 0, 1], [0, 1, 0, 0, 0], [0, 0, 3, 0, 0], [0, 0, 2, 1, 0], [0, 0, 2, 0, 1], [0, 0, 2, 0, 0], [0, 0, 1, 2, 0], [0, 0, 1, 1, 1], [0, 0, 1, 1, 0], [0, 0, 1, 0, 2], [0, 0, 1, 0, 1], [0, 0, 1, 0, 0], [0, 0, 0, 3, 0], [0, 0, 0, 2, 1], [0, 0, 0, 2, 0], [0, 0, 0, 1, 2], [0, 0, 0, 1, 1], [0, 0, 0, 1, 0], [0, 0, 0, 0, 3], [0, 0, 0, 0, 2],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 1, 0, 1, 0]*y*t+a[0, 1, 0, 0, 1]*y*s+a[0, 0, 2, 0, 0]*z^2+a[0, 0, 1, 1, 0]*z*t+a[0, 0, 1, 0, 1]*z*s+a[0, 0, 0, 2, 0]*t^2+a[0, 0, 0, 1, 1]*t*s+a[0, 0, 0, 0, 2]*s^2+a[1, 0, 0, 0, 0]*x+a[0, 1, 0, 0, 0]*y+a[0, 0, 1, 0, 0]*z+a[0, 0, 0, 1, 0]*t+a[0, 0, 0, 0, 1]*s+a[0, 0, 0, 0, 0]

(2)

 


 

polynom.mw


Edit.

 

Here is a simple procedure that solves the problem for not too large  d  and  K :

Pell:=proc(d::posint,K::posint)
local k, y, x, L;
k:=0; L:=table();
for y from 1 to K do
x:=isqrt(d*y^2+1);
if x^2-d*y^2=1 then k:=k+1; L[k]:=[x,y] fi;
od;
convert(L,list);
end proc:


Example of use:

Pell(27,1000000);

Output:
                  [[26, 5], [1351, 260], [70226, 13515], [3650401, 702520]]


Addition. Of course, much more efficient code can be written if we use  isolve  command, but I think that for a beginner the above will be enough.


Edit.

Specify the range for  x  variable explicitly:

with(DocumentTools):
A := [plot(sin(x)/x, x = -2*Pi .. 2*Pi, legend = sinc(x)), Sum(f(i), i = 1 .. N), plot3d(y^2*sin(x), x = -Pi .. Pi, y = -2 .. 2)]:
Tabulate(A, width = 60):


 

Download Tab.mw

Maximize (or Minimize) command only guarantees a local extremum, not a global one (see help for details). To get a global maximum, first plot a graph, and then narrow the range for the variable  x , that contains the maximum:


 

restart;
with(Optimization):
app := x->0.14546e-1*sin(3.141592654*x)+(-1)*0.50512e-2*sin(6.283185308*x)+0.19918e-2*sin(9.424777962*x);
ex :=x->-AiryAi(2^(2/3)*x)*(5*3^(5/6)-9*AiryBi(2^(2/3))*GAMMA(2/3))/(8*AiryAi(2^(2/3))*3^(5/6)-8*AiryBi(2^(2/3))*3^(1/3))-AiryBi(2^(2/3)*x)*(9*AiryAi(2^(2/3))*GAMMA(2/3)-5*3^(1/3))/(8*AiryAi(2^(2/3))*3^(5/6)-8*AiryBi(2^(2/3))*3^(1/3))+(1/4)*x^3+3/8;
plot(100*abs(app(x)-ex(x)), x = 0 .. 1);
Maximize(100*abs(app(x)-ex(x)), x=0.8..1);

proc (x) options operator, arrow; 0.14546e-1*sin(3.141592654*x)-0.50512e-2*sin(6.283185308*x)+0.19918e-2*sin(9.424777962*x) end proc

 

proc (x) options operator, arrow; -AiryAi(2^(2/3)*x)*(5*3^(5/6)-9*AiryBi(2^(2/3))*GAMMA(2/3))/(8*AiryAi(2^(2/3))*3^(5/6)-8*AiryBi(2^(2/3))*3^(1/3))-AiryBi(2^(2/3)*x)*(9*AiryAi(2^(2/3))*GAMMA(2/3)-5*3^(1/3))/(8*AiryAi(2^(2/3))*3^(5/6)-8*AiryBi(2^(2/3))*3^(1/3))+(1/4)*x^3+3/8 end proc

 

 

[HFloat(0.1838471711423484), [x = HFloat(0.9230341609253242)]]

(1)

 


 

Addition. In order to immediately get the global extremum, you can use DirectSearch  package, which should be downloaded from the Maple Application Center and installed on your computer

https://www.maplesoft.com/applications/view.aspx?sid=101333

 

Download Max.mw

First you need to open your file, then  ctrl+ p

Another way: menu file -> print  or  print preview

Probably a double for loop is meant for summing such terms, if  i  runs from  0  to  m  and  runs from  0  to  n . A simple procedure named  Bxy  solves the problem:

Bxy:=proc(m::nonnegint,n::nonnegint)
local S, i, j;
S:=0;
for i from 0 to m do
for j from 0 to n do
S:=S+binomial(m,j)*binomial(n,i)*x^i*(1-x)^(m-i)*y^j*(1-y)^(n-j);
od; od;
S;
end proc:

Example of use:

Bxy(3,2);

                  

 

Here is the numerical solution:

restart;
pde:=diff(u(x,t), t$2)+diff(u(x,t), x$4)=0;
bc:=u(0,t)=-12*t^2, u(1,t)=1-12*t^2, D[1,1](u)(0,t)=0, D[1,1](u)(1,t)=12;
ic:=u(x,0)=x^4, D[2](u)(x,0)=0;
sol:=pdsolve(pde, {ic,bc}, u(x,t), numeric);
sol:-plot3d(t = 0 .. 1, x = 0 .. 1, axes = boxed);

 

Use  %.  or  %*  instead of  :

sum(i %. a, i=1..3);
                                               


Another option is to use  ``(...)  construction to avoid the summation of similar terms. Then all the individual terms of the series are enclosed in parentheses, and it is convenient to compare:

sum(``(i*a), i=1..3);
                                               

 This construction is often useful in other cases. For example, if you need to clearly show the definition of the number  10!  then it can be done in 3 ways:

``(10)!=product(``(k), k=1..10);
# or
``(10)!=`%.`(seq(k, k=1..10));
# or
``(10)!=`%*`(seq(k, k=1..10));
                                          

 

Edit.                                   

Try this:

simplify(-sqrt((r-2*M)*(-r/(-r+2*M))^eta/r)*X*sqrt(-((r-2*M)/r)^eta*r/(-r+2*M))/f) assuming r>0, r-2*M>0, eta::real;


Edit.

 

In fact, Maple knows this, but this syntax  convert(sin(alpha), radical)  is required for output. Maple can express in real radicals trigonometric functions of any angle multiple of 3 degrees:


 

for k from 3 to 87 by 3 do
%sin(k*Pi/180)=convert(sin(k*Pi/180), radical);
od;

%sin((1/60)*Pi) = (-(1/16)*2^(1/2)-(1/8)*(5+5^(1/2))^(1/2)+(1/16)*2^(1/2)*5^(1/2))*3^(1/2)-(1/16)*2^(1/2)+(1/8)*(5+5^(1/2))^(1/2)+(1/16)*2^(1/2)*5^(1/2)

 

%sin((1/30)*Pi) = (1/8)*2^(1/2)*3^(1/2)*(5-5^(1/2))^(1/2)-1/8-(1/8)*5^(1/2)

 

%sin((1/20)*Pi) = -(1/4)*(5-5^(1/2))^(1/2)+(1/8)*2^(1/2)*(5^(1/2)+1)

 

%sin((1/15)*Pi) = (1/8-(1/8)*5^(1/2))*3^(1/2)+(1/8)*2^(1/2)*(5+5^(1/2))^(1/2)

 

%sin((1/12)*Pi) = (1/4)*2^(1/2)*(3^(1/2)-1)

 

%sin((1/10)*Pi) = -1/4+(1/4)*5^(1/2)

 

%sin((7/60)*Pi) = ((1/8)*3^(1/2)+1/8)*(5-5^(1/2))^(1/2)-(1/16)*2^(1/2)*(5^(1/2)+1)*3^(1/2)+(1/16)*2^(1/2)*(5^(1/2)+1)

 

%sin((2/15)*Pi) = -(1/8)*2^(1/2)*(5-5^(1/2))^(1/2)+(1/8+(1/8)*5^(1/2))*3^(1/2)

 

%sin((3/20)*Pi) = (1/8)*2^(1/2)+(1/4)*(5+5^(1/2))^(1/2)-(1/8)*2^(1/2)*5^(1/2)

 

%sin((1/6)*Pi) = 1/2

 

%sin((11/60)*Pi) = (-(1/16)*2^(1/2)+(1/8)*(5+5^(1/2))^(1/2)+(1/16)*2^(1/2)*5^(1/2))*3^(1/2)-(1/16)*2^(1/2)-(1/8)*(5+5^(1/2))^(1/2)+(1/16)*2^(1/2)*5^(1/2)

 

%sin((1/5)*Pi) = (1/4)*2^(1/2)*(5-5^(1/2))^(1/2)

 

%sin((13/60)*Pi) = (-(1/8)*3^(1/2)+1/8)*(5-5^(1/2))^(1/2)+(1/16)*2^(1/2)*(5^(1/2)+1)*3^(1/2)+(1/16)*2^(1/2)*(5^(1/2)+1)

 

%sin((7/30)*Pi) = (1/8)*2^(1/2)*3^(1/2)*(5+5^(1/2))^(1/2)+1/8-(1/8)*5^(1/2)

 

%sin((1/4)*Pi) = (1/2)*2^(1/2)

 

%sin((4/15)*Pi) = ((1/8)*5^(1/2)-1/8)*3^(1/2)+(1/8)*2^(1/2)*(5+5^(1/2))^(1/2)

 

%sin((17/60)*Pi) = ((1/8)*3^(1/2)+1/8)*(5-5^(1/2))^(1/2)+(1/16)*2^(1/2)*(5^(1/2)+1)*3^(1/2)-(1/16)*2^(1/2)*(5^(1/2)+1)

 

%sin((3/10)*Pi) = 1/4+(1/4)*5^(1/2)

 

%sin((19/60)*Pi) = ((1/8)*(5+5^(1/2))^(1/2)+(1/16)*2^(1/2)-(1/16)*2^(1/2)*5^(1/2))*3^(1/2)+(1/16)*2^(1/2)*5^(1/2)-(1/16)*2^(1/2)+(1/8)*(5+5^(1/2))^(1/2)

 

%sin((1/3)*Pi) = (1/2)*3^(1/2)

 

%sin((7/20)*Pi) = -(1/8)*2^(1/2)+(1/4)*(5+5^(1/2))^(1/2)+(1/8)*2^(1/2)*5^(1/2)

 

%sin((11/30)*Pi) = (1/8)*2^(1/2)*3^(1/2)*(5-5^(1/2))^(1/2)+1/8+(1/8)*5^(1/2)

 

%sin((23/60)*Pi) = (-1/8+(1/8)*3^(1/2))*(5-5^(1/2))^(1/2)+(1/16)*2^(1/2)*(5^(1/2)+1)*3^(1/2)+(1/16)*2^(1/2)*(5^(1/2)+1)

 

%sin((2/5)*Pi) = (1/4)*2^(1/2)*(5+5^(1/2))^(1/2)

 

%sin((5/12)*Pi) = (1/4)*2^(1/2)*(1+3^(1/2))

 

%sin((13/30)*Pi) = (1/8)*2^(1/2)*3^(1/2)*(5+5^(1/2))^(1/2)+(1/8)*5^(1/2)-1/8

 

%sin((9/20)*Pi) = (1/4)*(5-5^(1/2))^(1/2)+(1/8)*2^(1/2)*(5^(1/2)+1)

 

%sin((7/15)*Pi) = (1/8)*2^(1/2)*(5-5^(1/2))^(1/2)+(1/8+(1/8)*5^(1/2))*3^(1/2)

 

%sin((29/60)*Pi) = (-(1/16)*2^(1/2)+(1/8)*(5+5^(1/2))^(1/2)+(1/16)*2^(1/2)*5^(1/2))*3^(1/2)+(1/8)*(5+5^(1/2))^(1/2)+(1/16)*2^(1/2)-(1/16)*2^(1/2)*5^(1/2)

(1)

 


 

Download sine.mw

You can do this using  plots:-textplot  and  plot  commands as follows:

The code:

restart;
with(plots):
T:=[[0,0.9, "2*5+8 = 2*5+8"], font=[times,20]]:
T1:=textplot(op(T)):
Line:=plot([[t,0.87,t=-0.56..-0.28],[t,0.87,t=0.1..0.38]], color=black):
display(T1, Line, size=[300,70], view=[-1..1,0.6..1.3], axes=none);

Output:
                                            


You can even make an animation of this. For the animation we used the technique from this post .

The code:

A:=animate(textplot,subsop(1=[T[1,1..2][],T[1,3][1..round(i)]],T), i=0..length(T[1,3]), frames=40, paraminfo=false, view=[-1..1,0.6..1.3], size=[300,70], axes=none):
B1:=animate(plot,[[t,0.87,t=-0.56..a], color=black], a=-0.56..-0.28, frames=10, paraminfo=false):
B2:=animate(plot,[[t,0.87,t=0.1..a], color=black], a=0.1..0.38, frames=10, paraminfo=false):
display([A, display(op([1,-1,1],A),B1), display(op([1,-1,1],A),op([1,-1,1],B1),B2)], insequence);

  Output: 

                       

Premature calculation occurs, before the substitution of values  i  into the series. This is easy to see if you write down it as an inert sum:

Sum(0^i/i!, i=0..infinity);
                                                      

 
For correct calculation use  eval  command:

eval(sum(x^i/i!, i=0..infinity), x=0);
                                                             
1
 

I also did not understand exactly what you want to plot. You have a system of 5 unknown functions of the variable  t . Below I showed how you can plot the graph  V  vs  t. For other functions, everything is the same.

DEplot({diff(C(t), t) = rho*lambda*S(t)+rho*epsilon*lambda*V(t)+(1-q)*eta*I(t)-(mu+beta+chi)*C(t), diff(I(t), t) = (1-rho)*lambda*S(t)+(1-rho)*epsilon*lambda*V(t)+chi*C(t)-(mu+alpha+eta)*I(t), diff(R(t), t) = beta*C(t)+q*eta*I(t)-(mu+delta)*R(t), diff(S(t), t) = (1-p)*pi+phi*V(t)+delta*R(t)-(mu+lambda+vartheta)*S(t), diff(V(t), t) = p*pi+vartheta*S(t)-(epsilon*lambda+mu+phi)*V(t)}, {C(t), I(t), R(t), S(t), V(t)}, t = 0 .. 300, number = 5, stepsize = .1, [[S(0) = 8200, V(0) = 2800, C(0) = 200, I(0) = 210, R(0) = 200]], linecolour = t, axes = BOXED, scene = [t, V(t)]);

 

In fact, you study the monotonicity of the function  x-> (3*x-1)/(x^3+2*x+1)  in some intervals (for example for  x>0). For this instead  is  and  assume  command, I would just have used a plot, and to refine the intervals of increase and decrease, I would use the derivative:

restart;
f := x-> (3*x-1)/(x^3+2*x+1):
plot(f, 0..10, size=[700,300]);
R1:=solve({diff(f(x), x)>0, x>0});
R2:=solve({diff(f(x), x)<0, x>0});
evalf([R1, R2]);

 

I successfully restarted your worksheet and saved it again. Probably the cause of the problem was in the absence of any delimiters between the individual lines of your code (I had put them).

Plot_Diff_Temperature_new.mw

First 127 128 129 130 131 132 133 Last Page 129 of 292