Kitonum

21952 Reputation

26 Badges

17 years, 350 days

MaplePrimes Activity


These are answers submitted by Kitonum

Simple procedure  PartitionIntoPrimes  gives all possible partitions of a natural number  a  into  n  prime summands. By default, the procedure returns the list of lists of all partitions. If the third argument of the procedure is any symbol, then the procedure returns all of the corresponding sums. The procedure was written in Maple 12 classic.

PartitionIntoPrimes:=proc(a::posint, n::posint, s::symbol:=list)

local L, M, k, i, S, S1;

uses numtheory, combinat;

L:=[seq(ithprime(k)$n, k=1..pi(a))];

M:=choose(L, n); k:=0;

for i in M do

if `+`(op(i))=a then k:=k+1; S[k]:=i; fi;

od;

S:=convert(S, list):

if s=list then return S else S1:=map(t->`+`(op(map(x->``(x),t)))=a, S) fi;

for i in S1 do

print(i);

od;

end:

 

Examples of use:

PartitionIntoPrimes(30, 2);

PartitionIntoPrimes(30, 6);

PartitionIntoPrimes(30, 6, s);

 

 

 

f := simplify(evalc(int(cosh(a*x)*cos(b*x), x)));

 

 Addition:

simplify(convert(f, trig));

 

 

I made ​​some changes in your code. Write if you got what you wanted?

restart:

alias(C=binomial):

HybrFunc:=proc(N, M,tj)  # N=Number of subintervals,  M=Number of functions in subintervals

local B, i, kk, j1, w, aa, bb, OB;

global b; 

B:=(i,M,t) -> C(M,i)*(1-t)^(M-i)*t^i;

w[0]:=B(0,M,t);

for i from 0 to M

do

  kk:=0; 

  for j1 from 0 to i-1

  do

    aa[j1]:=int(B(i,M,t)*w[j1],t=0..1);

    bb[j1]:=int(w[j1]^2,t=0..1);

    kk:=kk+aa[j1]/bb[j1]*w[j1];

  od;

w[i]:=simplify(B(i,M,t)-kk);

w[i]/sqrt(int(w[i]^2,t=0..1));

OB[i]:=unapply(%,t);

od; 

b:=unapply(piecewise(t>=(n-1)*tj/N and t<n*tj/N, sqrt(N)*OB[m](N*t-(n-1)*tj), 0),n,m); 

simplify(Array(1..N, 0..M , b));

end proc:

 

Example: 

HybrFunc(2, 3, 1);

a:=sqrt(2)*T*I/sqrt(L*(k+2)*C):

simplify(exp(-a)*k^2+4*exp(-a)*k+exp(a)*k^2+4*exp(a)*k+4*exp(a)+4*exp(-a));

 

 

e^a  should be coded as  exp(a), because  in Maple  e  is just a symbol. 

C:=proc(x, E)

local i, n;

n:=nops(E);

if is(x<=E[1]) then return 1 else

for i from 1 to n do

if is(x<=E[i]) and is(x>E[i-1]) then return i  fi;

od; fi;

n+1;

end:

 

Examples of use:

E:=[0,2,7,15,26,40]:

C(-1, E),  C(3, E),  C(15, E),  C(41, E);

                      1, 3, 4, 7

 

Addition: another way

C1:=proc(x, E)

local F, y;

uses ListTools;

y:=evalf(x);

F:=sort([y, op(E)]);

Search(y, F);

end:

 

For any graph it is easy to check in Maple. The graph given by its adjacency matrix.

Example: 

A:=<0,1,1,1,1; 1,0,1,0,1; 1,1,0,1,1; 1,0,1,0,0; 1,1,1,0,0>;

d:=sort([seq(add(A[i,j], j=1..5), i=1..5)], `>`);

# Checking of all the conditions

type(add(d[i], i=1..5), even);

for k to 5 do

if add(d[i], i=1..k)<=k*(k-1)+add(min(d[i], k), i=k+1..5) then print(true); fi;

od;

 

 

a := [x+1, x+2, x+3, x+4]:

remove(i -> i=x+2, a);

               [x+1, x+3, x+4]

 

To generate a random number between -1 and 1, first you generate from 0 to 2, and then this number decreased by 1.

Example: the sequense 20 random numbers from -1 to 1:

seq(RandomTools[Generate](float(range=0..2, digits=5, method=uniform)) - 1, n=1..20);

    .2143, -.73336, -.50076, -.7856e-1, -.14992, -.46077, .5519, -.4999e-1, -.14926, -.57465, .8858, -.27223, -.4630e-1,    -.66349, .2290, .1925, .2208, .5704, .2130, -.15558

The penultimate line of code  

M[1..6,1..6]:=Matrix(3,3,shape=identity)

is not evaluated because it is written in text mode.

Yes, it's possible. Use the formula of differentiation of parametric function  Diff(y(x), z)=Diff(y(x), x)/Diff(z(x), x)

Example:

y:=x->sin(x): z:=x->x-y(x):

diff(y(x), x)/diff(z(x), x);

 

 

f:=x->piecewise(x>=2 and x<=6, sqrt(x), undefined);

D(f)(1);

plot(f, 0..7, 0..3, scaling=constrained);

 

 

restart;

Dist := proc (A::list, B::list)

sqrt((A[1]-B[1])^2+(A[2]-B[2])^2)

end proc:  # Procedure for calculation of the distance between two points defined by lists

A := [1, 1]: B := [x1, 2]: C := [x2, y2]:  # The centers of the circles

solve({Dist(A, B) = 3, Dist(A, C) = 1+y2, Dist(B, C) = 2+y2}, useassumptions) assuming x1 > 0, x2 > 0, y2 > 0;

assign(%);

Circle1 := (x-1)^2+(y-1)^2 = 1;

Circle2 := (x-x1)^2+(y-2)^2 = 4;

Circle3 := (x-x2)^2+(y-y2)^2 = expand(y2^2);

plots[implicitplot]([Circle1, Circle2, Circle3], x = -1 .. 6, y = -1 .. 5, thickness = 2, color = [blue, green, red], scaling = constrained, numpoints = 10000);

 

 

 

For older versions (at least for <=12)  ~  command doesn't work. The adjustment will be

seq( x^3-3*x^2-24*x+8, x=[-2,4,6,9]);

                             36, -72, -28, 278

 

In new versions this variant works also.

 

M:=3:  N:=3:

H:=1/N*Matrix(M,{seq((i,1)=t[f]^i/i, i=1..M)}):

E:=1/N*Matrix(M, {seq((i,i+1)=1/i, i=1..M-1)}):

P:=<seq(`<|>`(Matrix(M) $ M-1-k,E,H $ k),k=M-1..0,-1)>;

 

 

restart;

N := 8:

a := -Pi:

b := 3 * Pi:

data := []:

for n from 0 to N do

x[n] := a + n * (b - a)/N;

data := [op(data), [x[n], sin(x[n])]];

od:

data;

plot(data);

 

 

If the list is long better to write the following equivalent but more effective variant:

restart;

N := 1000:

a := -Pi:

b := 3 * Pi:

for n from 0 to N do

x[n] := a + n * (b - a)/N;

data[n] := [x[n], sin(x[n])];

od:

data := convert(data, list):

plot(data);

 

 Addition:  Instead a loop  shorter to use  seq  command:

restart;

a:=-Pi: b:=3*Pi:

N:=1000:

data := [seq([k, sin(k)], k=[a + n * (b - a)/N $ n=0..N])]:

plot(data);

First 234 235 236 237 238 239 240 Last Page 236 of 292