Kitonum

21530 Reputation

26 Badges

17 years, 85 days

MaplePrimes Activity


These are answers submitted by Kitonum

a:=Matrix([[1,2],[3,4]]):

add(add(a[i,j]*f[parse(cat(i,j))], j=1..2), i=1..2);

                    

 

 

@vv

you are right. My approach above works only if the sets of actual  variables of the polynomials are the same. The following procedure  EquateCoeffs  solves the problem - it equates the coefficients of any two multivariate polynomials. The procedure includes the sub-procedure  coefff  that is useful in itself.

EquateCoeffs:=proc(L1::list,L2::list)

local coefff, s;

coefff:=proc(P,T,t)   # Returns the coefficient of the monomial t in the polynomial P (T - the set of polynomial's variables)

local L,H,i,k:

L:=[coeffs(P,T,'h')]: H:=[h]: k:=0:

for i from 1 to nops(H) do

if H[i]=t then k:=L[i] fi:

od:

k;

end proc:

coeffs(op(L1),'s1');

coeffs(op(L2),'s2');

s:=`union`({s1},{s2});

seq(coefff(op(L1),t)=coefff(op(L2),t), t=s);

end proc:

 

Example of use:

EquateCoeffs([a*x^2+b*y^2+c*x*y+f, [x,y]], [d*x^2+e, [x]]);

                              f = e, a = d, b = 0, c = 0

 

 

restart;

P1:=(1/2*(p*a*b+(g-p)*b-g))*b*v*a*ln(E)^2-(-1+b)*v*(g-p+a*p)*b*a*ln(E)*ln(K)-b*p*(a-1)*v*a*ln(E)*ln(L)+v*a*b*ln(E)+(1/2*(p*(-1+b)*a+(g-p)*b+p))*(-1+b)*v*a*ln(K)^2+(-1+b)*v*p*(a-1)*a*ln(K)*ln(L)-v*a*(-1+b)*ln(K)+(1/2)*a*p*v*(a-1)*ln(L)^2-v*(a-1)*ln(L):

P2:=x_1*ln(E)+x_11*ln(E)^2+x_12*ln(E)*ln(K)+x_13*ln(E)*ln(L)+x_2*ln(K)+x_22*ln(K)^2+x_23*ln(K)*ln(L)+x_3*ln(L)+x_33*ln(L)^2:

coeffs(P1, [ln(E),ln(K),ln(L)])=~coeffs(P2, [ln(E),ln(K),ln(L)]);

 

 

 

In your example, it is more convenient to work with sets than with lists:

A:={x, y, x^2*y, x*y^2, y^2}:   B:={x^2, y^3}:

C:=A:

for a in A do

if convert([seq(degree(a/b, x)>=0 and degree(a/b, y)>=0, b=B)],`or`) then C:=C minus {a} fi;

od:

C;

                                        {x, y, y^2, x*y^2}

 

Of course, it's easy to rewrite this code as a procedure with any number of variables.

restart;

f, g:=2, convert(series(1/sqrt(1-x^2),x=0),polynom):

plots:-shadebetween(f, g, x=0..sqrt(3)/2);

There is software that makes it. See here

Use  side relations  option in  simplify  command.

Example:

simplify((x^2+y^2+z^2+w^2)^10, {x^2+y^2+z^2+w^2=1});

                                                 1

Example:

Matrix([[x+y,x-y], [z,w]]):

eval(%, {x=-x, y=-y, z=-z, w=-w});

For plotting a single plot of multiple objects use  plots[display] .

Example:

with(DynamicSystems):

T:= Vector(20, t->0.1*(t)):

x1:= Vector(20, t->sin(0.1*t)):

x2:= Vector(20, t->cos(0.1*t)):

A:=DiscretePlot(T, x1, style=stair):

B:=DiscretePlot(T, x2, style=stair):

plots[display](A, B);

For fixed parameters  a, b, c, omega  when changing  t  the end of your variable vector  r(t) describes  a spiral:

a := 2: b := 1: c := 1: omega := 2:

r := t-><a*cos(omega*t), b*sin(omega*t), c*t>:

with(plots):

A := animate(arrow, [r(t), color = blue], t = 0 .. 2*Pi, frames = 100):

B := animate(spacecurve, [[a*cos(omega*s), b*sin(omega*s), c*s], s = 0 .. t, color = red, thickness = 3, linestyle = solid], t = 0 .. 2*Pi, frames = 100):

display(A, B, axes = normal, scaling = constrained);

                                            

 

Another way - the direct plotting of required objects without  plottools:-transform .

Here are 3 examples:

F:=(x,y)->(1/2*x^2-3/2*y^3,-1/2*x^3+1/3*y^2):  # Nonlinear mapping R^2->R^2

X:=t->(1/2*t+1,t-1):  # Mapping R->R^2 (for specification of a segment)

plot([[X(t),t=0..1],[F(X(t)), t=0..1]], color=[red,blue], thickness=3, scaling=constrained);  # The first example

plot([[X(t),t=0..1],[(F@@2)(X(t)), t=0..1]], color=[red,blue], thickness=3, scaling=constrained);  # The second example

X1:=t->(t,0): X2:=t->(0,t): X3:=t->(t,1): X4:=t->(1,t):  # Specifying edges of the unit square

plot([[X1(t),t=0..1], [X2(t),t=0..1], [X3(t),t=0..1], [X4(t),t=0..1], [F(X1(t)), t=0..1], [F(X2(t)), t=0..1], [F(X3(t)), t=0..1], [F(X4(t)), t=0..1]], color=[red$4,blue$4], thickness=3, scaling=constrained);   # The third example - the image of the unit square under the mapping  F

The simple procedure  ListOfTerms  solves the problem:

ListOfTerms:=proc(p)

if nops([coeffs(p)]) >1 then [op(p)] else [p]  fi;

end proc:

 

Examples:

ListOfTerms(x^2*y + x*y + x);

ListOfTerms(x^2);

               [x^2*y, x*y, x]

                     [x^2]

jheath4  Here is the procedure which finds all combinations of a binary list of any length  N

BinaryList:=proc(N::posint)

local OneStep;

OneStep:=proc(L::listlist)

local n;

n:=nops(L);

[seq(op([[op(L[i]),0],[op(L[i]),1]]), i=1..n)];

end proc;

(OneStep@@N)([[]]);

end proc:

 

Your example:

BinaryList(3);

          [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]

 

This procedure works a bit faster than  combinat:-permute :

ts:=time():

combinat:-permute( [0$15,1$15], 15):

time()-ts;

                            0.188

 

ts:=time():

BinaryList(15):

time()-ts;

                            0.109

 

 

Assuming that your function is smooth enough, you can interpolate the integrand by a spline (by default of 3 degree), and then integrate:

flist := [0.1, 0.2, 2, 3, 3.5, 6]:

xlist := [1, 2, 3, 4, 5, 6]:

glist := flist*~(xlist^~2-~1);  # The list of the integrand's values

F:=CurveFitting[Spline](xlist,glist, x);  

int(F, x=1..6);

 

 

By nested loop:

restart;

n:=0:

for i from 0 to 1 do

for j from 0 to 1 do

for k from 0 to 1 do

n:=n+1;  s[n]:=cat(i,j,k);

od: od: od:

convert(s,list)[];

 

By Carl's approach:

(cat@op)~(combinat:-permute([0$3,1$3], 3))[];

 

By nested seq:

seq(seq(seq(cat(i,j,k),k=0..1),j=0..1),i=0..1);

 

 First variant was edited.

First 204 205 206 207 208 209 210 Last Page 206 of 290