Kitonum

21595 Reputation

26 Badges

17 years, 163 days

MaplePrimes Activity


These are answers submitted by Kitonum

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

          

                   

             

I assumed that interest is charged at the beginning of each month, as well as at the moment (n-th day of the month) when an additional payment  R  is made. If  n = 1 , then we get the initial result.

 
 

restart;
param:=[P=10000, R=100, i=0.025/12, n=20]:

rsolve({f(t) =( f(t-1)*(1+(n-1)*i/30) + R)*(1+(30-(n-1))/30*i), f(0)=P}, {f});

{f(t) = P*(1+i-(1/900)*i^2*n^2+(8/225)*i^2*n-(31/900)*i^2)^t+30*R*(i*n-31*i-30)*(1+i-(1/900)*i^2*n^2+(8/225)*i^2*n-(31/900)*i^2)^t/(i*(i*n^2-32*i*n+31*i-900))-30*R*(i*n-31*i-30)/(i*(i*n^2-32*i*n+31*i-900))}

(1)

eval(rhs(%[1]),param);

58013.43793*1.002084341^t-48013.43793

(2)

P:=unapply(%,t);

proc (t) options operator, arrow; 58013.43793*1.002084341^t-48013.43793 end proc

(3)

check

seq(P(i),i=0.. 2);

10000.00000, 10120.91979, 10242.09158

(4)

 


 

Download Recurring_new.mw

 

restart;
F(x,y):=ln((1+x)*y) + exp(x^(2)*y^(2)) = x + cos(x):
L:=[1, seq(eval(implicitdiff(F(x,y), y, x$n), [x=0,y=1]), n=1..6)];
add(L[i]/(i-1)!*x^(i-1), i=1..7);

                 

 

 

y:= x-> ((1 + a*x + b*x^2)/(1 + c*x + d*x^2))*(ln(sinh(x)^2 + cosh(x)^2));
Sys:={seq(coeff(series(y(x), x=0, 7), x^n)=0, n=3..6)};
solve(Sys);

                         {a = 0, b = 16/15, c = 0, d = 2/5}

plot([seq([PP[n], QQ[n]], n = 1 .. numelems(PP))], style = pointline, labels = ["PP", "QQ"]);

                   

 

 
Edit.               

In addition to the unknown variables  {C, I, R, S, V} , your nonlinear system contains three more parameters (k , tau, Upsilon). If you want to get all the solutions expressed through these parameters, then use the options parametric=full  and  allsolutions. If you specify the values of these parameters, you can easily get all the solutions:

Sys := {eqn1 = 0, eqn2 = 0, eqn3 = 0, eqn4 = 0, eqn5 = 0};
Equilibria1 := solve(Sys, {C, I, R, S, V}, parametric=full, allsolutions);  # 
All the solutions expressed through 3 parameters
Equilibria2 := solve(eval(Sys, [k = 1, tau = 2, Upsilon = 3]), {C, I, R, S, V});  # All the solutions for specific parameters

If I correctly understood the problem, then the following code solves it. You can yourself specify the number of steps and the reduction factor of the height at each step (parameters  N  and  k):

restart;
L1:=s->[[0,0],[5,0],[2.5,s],[0,0]]:
L2:=s->[[2,0],[7,0],[4.5,s],[2,0]]:
L3:=s->[[4,0],[9,0],[6.5,s],[4,0]]:
A:=s->plot([L1(s),L2(s),L3(s)], color=red, scaling=constrained):
N:=15:  k:=0.8:
for n from 0 to N do
S[n]:=plots:-display([A(4), A(4*k^n)]):
od:
plots:-display(seq(S[n]$5, n=0..N), insequence);

               


 

Did you mean this formula  V=int(S(x), x=a..b) ?  If so, then look at this popular article and my example in Maple below applying this formula.


The problem: find the volume of the body bounded downwards by the plane  z=0 , on the sides by the cylinder  x^2+y^2=R^2 , and the top plane  z=-tan(alpha)*y .


Visualization and calculation (for plotting I took  R=1  and  alpha=Pi/4 ):

A:=plot3d(-y, x=-sqrt(1-y^2)..sqrt(1-y^2), y=-1..0,style=surface, color="LightBlue",  scaling=constrained, axes=normal, filled, transparency=0.3, tickmarks=[[-1=-R,0=0,0.45=x,1=R], 0, 0], axesfont=[times,18]):
B:=plottools:-polygon([[0.45,0,0],[0.45,-sqrt(1-0.45^2),0],[0.45,-sqrt(1-0.45^2),sqrt(1-0.45^2)]], color=blue):
plots:-display(A,B); 
# Visualization

S(x):=1/2*sqrt(R^2-x^2)*sqrt(R^2-x^2)*tan(alpha):
V=int(S(x), x=-R..R); 
# Calculation

                    

 

 

 


 

It often happens that a symbolic result is not expressed in terms of real radicals (for example, the irreducible case when solving a cubic equation, when all the roots of the equation are actually real). An example below with the specified parameters  under of numerical calculation shows that the result is actually real:

fs := (1-1/sqrt((Uo+U*sin(x))^2+a^2))*(Uo+U*sin(x)): 
fss := `assuming`([2*(int(fs*sin(x), x = 0 .. Pi))/Pi], [U::positive, a::positive, Uo::positive]):
evalf[50](eval(fss, [Uo=1, U=2, a=3]));

                2.4545008734200178385686140997145766421739797191553-                    5.5000000000000000000000000000000000000000000000000*10^(-50)*I

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