Items tagged with coeff coeff Tagged Items Feed

Hi,

 

  Excuse me, I tried to substract in a series expansion. It works for Taylor-type expansion, but not Laurent-type ones

*********

ffff:=1/(t-3);
ggg:=taylor(ffff,t=infinity,3);
coeff(ggg,t,-1);


ffff:=exp(t);
ggg:=taylor(ffff,t=0,3);
coeff(ggg,t,1);

*********

Maple gives me


Error, unable to compute coeff


1

 

. My question is, why "coeff" does not work in the first case? how to make it work? Though I can copy the expansion part, assign it to another variable, and "coeff" will work

 

Hi,

 

I have a system of equations containing curls, divergence and gradients of variables. 

How can I extract the coefficients of the equations (i.e. coefficients of d/dt rho, d/dx p) and form a matrix?

thanks.   

EDIT 2: Ok, here is what I am trying to do with Maple.

I have the following expression:

with

 

and

 (j times)

Now the above expression should be zero. I get a set of equations in orders of lambda. The H matrices are known. I only need to find the S matrices.

Anyways, the HOffDiag is the sum above and the GetAdvCommutator0 is this nested commutator. And I need this sum evaluated up to order n (n is a given input-number) in lambda. The rest is really not that performance hungry.

 

 

EDIT: Ok, it realy seems that this sum of commutators is something that takes Maple forever. I have written a new MWE. Is it possible to speed things up? Maybe using assumptions or so?

 

restart;with(Physics):with(LinearAlgebra): Setup(mathematicalnotation=true):Setup(noncommutativeprefix={M,H,S});

[noncommutativeprefix = {H, M, S}]

(1)

GetAdvCommutator0:=proc(power::integer,order::integer,M)
    if power <= 0 then return M fi:
    if power = 1 then

        return mtaylor(Commutator(M,add(lambda^l*S[l],l=1..order)),lambda, order+1) fi:
    
    return mtaylor(Commutator(GetAdvCommutator0(power-1,order,M),add(lambda^l*S[l],l=1..order)),lambda,order+1):
end proc:

HOffDiag:=n->eval(add(1/((2*j+1)!)*'GetAdvCommutator0'(2*j+1,n,H[0]),j=0..iquo(n-1,2)+1)+add(1/((2*j+1)!)*'GetAdvCommutator0'(2*j+1,n,lambda*H[1]),j=0..iquo(n-2,2)+1)+add(1/((2*j)!)*'GetAdvCommutator0'(2*j,n,lambda*H[2]),j=0..iquo(n-1,2)+1)):

HOffDiag(3); # still fast

lambda^3*Physics:-Commutator(H[0], S[3])+lambda^2*Physics:-Commutator(H[0], S[2])+lambda*Physics:-Commutator(H[0], S[1])+(1/6)*lambda^3*Physics:-Commutator(Physics:-Commutator(Physics:-Commutator(H[0], S[1]), S[1]), S[1])+lambda^2*Physics:-Commutator(H[1], S[1])+lambda^3*Physics:-Commutator(H[1], S[2])+lambda*H[2]+(1/2)*lambda^3*Physics:-Commutator(Physics:-Commutator(H[2], S[1]), S[1])

(2)

HOffDiag(6); # takes a very long time, I didn't even try entering higher numbers

Warning,  computation interrupted

 

 

 

SumOfCommutators.mw

 

Hi,

I know this question is really unspecific. However, since I am still new to Maple, and since you don't program with Maple as you would do with c++, I would appreciate some advise. I have written a program in Maple and I don't know if it works correctly. All I know is, it is pretty slow :(.

So if anyone of you could just have a short look at my attached worksheet and could tell me, if I at some point used an obvious "don't", I would greatly appreciate it.

 

Cheers

NOh

 

 

A Maple worksheet

NULL

Setup Maple

 

NULL

restart;with(Physics):with(LinearAlgebra):Setup(mathematicalnotation=true):Setup(noncommutativeprefix={MA,MB,H,S});

[noncommutativeprefix = {H, MA, MB, S}]

(1.1)

NULL

NULL

Input parameter

 

NULL

H0:=Matrix([[ 0 , 0 , 0 , 0 ],
            [ 0 , 0 , 0 , 0 ],
            [ 0 , 0 , U , 0 ],
            [ 0 , 0 , 0 , U ]]);

H0 := Matrix(4, 4, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = U, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = U})

(2.1)

H1:=Matrix([[ 0 , 0 , 0 , 0 ],
            [ 0 , 0 , 0 , 0 ],
            [ 0 , 0 , 0 , 0 ],
            [ 0 , 0 , 0 , 0 ]]);

H1 := Matrix(4, 4, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 0})

(2.2)

H2:=Matrix([[  0 , 0 , -t , -t ],
            [  0 , 0 ,  t ,  t ],
            [ -t , t ,  0 ,  0 ],
            [ -t , t ,  0 ,  0 ]]);

H2 := Matrix(4, 4, {(1, 1) = 0, (1, 2) = 0, (1, 3) = -t, (1, 4) = -t, (2, 1) = 0, (2, 2) = 0, (2, 3) = t, (2, 4) = t, (3, 1) = -t, (3, 2) = t, (3, 3) = 0, (3, 4) = 0, (4, 1) = -t, (4, 2) = t, (4, 3) = 0, (4, 4) = 0})

(2.3)

orderNumber:= 4 ;

4

(2.4)

NULL

 

 

 

Define all necessary functions

 

 

 

GetAdvCommutator0:=proc(power::integer,order::integer)
    local Comm:
    if power <= 0 then return H[0] fi:
    if power = 1 then return add(coeff(Commutator(H[0],add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order) fi:
    
    return add(coeff(Commutator(GetAdvCommutator0(power-1,order),add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order):
end proc:

GetAdvCommutator1:=proc(power::integer,order::integer)
    local Comm:
    if power <= 0 then return lambda*H[1] fi:
    if power = 1 then return add(coeff(Commutator(lambda*H[1],add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order) fi:
    
    return add(coeff(Commutator(GetAdvCommutator1(power-1,order),add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order):
end proc:

GetAdvCommutator2:=proc(power::integer,order::integer)
    local Comm:
    if power <= 0 then return lambda*H[2] fi:
    if power = 1 then return add(coeff(Commutator(lambda*H[2],add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order) fi:
    
    return add(coeff(Commutator(GetAdvCommutator2(power-1,order),add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order):
end proc:

 

HOffDiag:=n->eval(add(1/((2*j+1)!)*'GetAdvCommutator0'(2*j+1,n),j=0..iquo(n-1,2)+1)+add(1/((2*j+1)!)*'GetAdvCommutator1'(2*j+1,n),j=0..iquo(n-2,2)+1)+add(1/((2*j)!)*'GetAdvCommutator2'(2*j,n),j=0..iquo(n-1,2)+1)):

 

 

 

HOnDiag:=n->eval(add(1/((2*j)!)*'GetAdvCommutator0'(2*j,n),j=0..iquo(n,2)+1)+add(1/((2*j)!)*'GetAdvCommutator1'(2*j,n),j=0..iquo(n-1,2)+1)+add(1/((2*j+1)!)*'GetAdvCommutator2'(2*j+1,n),j=0..iquo(n-2,2)+1)):

 

computeHBlockDiag:=proc( n::posint,firstBlockWidth::posint, H0::Matrix, H1::Matrix, H2::Matrix )
    local expr, Orders, i, eq, j, eq2, orders,smatrices,rows::posint,evallist,m,l,cols,Hdiag,ff;
    
    
    expr:=HOffDiag(n);       # !!!!! this one is one of the slowest parts I think                                     
    Orders:=[$1..n];                                              
    for i from 1 to n do                                          
        eq:=add(coeff(expr,lambda,l)*lambda^l,l=0..i)=0;       
        for j from 1 to i-1 do
            eq:=eval(eq,Commutator(H[0],S[j])=Orders[j]);
        od;
        eq:=subs(Commutator(H[0],S[i])=MX,eq);
        eq2:=solve(eq,MX);
        Orders[i]:=eq2;
    od;

    
    rows,cols:=Dimension(H0);                                    
    smatrices:=[seq(H0,i=1..n)];
    for i from 1 to n do
        evallist:=[`*`=`.`,H[1]=H1,H[2]=H2];
        for j from 1 to i-1 do
            evallist:=[op(evallist),S[j]=smatrices[j]];        
        od;
        smatrices[i]:=eval(Orders[i],evallist);
        for m from 1 to firstBlockWidth do
            for l from firstBlockWidth+1 to rows do
                smatrices[i][m,l]:=smatrices[i][m,l]*1/(H0[m][m]-H0[l][l]);
                smatrices[i][l,m]:=smatrices[i][l,m]*1/(H0[m][m]-H0[l][l]);
            od;
        od;
    od;


    expr:=HOnDiag(n);            # !!!!! and this one of course (almost identical to the one above)                                       
    Hdiag:=eval(add(coeff(expr,lambda,l)*lambda^l,l=0..n),lambda=1);
    evallist:= [op(evallist), H[0]=H0,S[n]=smatrices[n]];
    Hdiag:=eval(Hdiag,evallist);


    
    return Hdiag;
end proc:

 

 

NULL

computeHBlockDiag(2,2,H0,H1,H2);

Matrix(4, 4, {(1, 1) = -2*t^2/U, (1, 2) = 2*t^2/U, (1, 3) = 0, (1, 4) = 0, (2, 1) = 2*t^2/U, (2, 2) = -2*t^2/U, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = U+2*t^2/U, (3, 4) = 2*t^2/U, (4, 1) = 0, (4, 2) = 0, (4, 3) = 2*t^2/U, (4, 4) = U+2*t^2/U})

(1)

Eigenvalues(%);

Vector(4, {(1) = 0, (2) = U, (3) = -4*t^2/U, (4) = (U^2+4*t^2)/U})

(2)

 

Testing

 

``

#Fast

computeHBlockDiag(2,2,H0,H1,H2);

Matrix(4, 4, {(1, 1) = -2*t^2/U, (1, 2) = 2*t^2/U, (1, 3) = 0, (1, 4) = 0, (2, 1) = 2*t^2/U, (2, 2) = -2*t^2/U, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = U+2*t^2/U, (3, 4) = 2*t^2/U, (4, 1) = 0, (4, 2) = 0, (4, 3) = 2*t^2/U, (4, 4) = U+2*t^2/U})

(4.1)

#Not so fast

computeHBlockDiag(4,2,H0,H1,H2);

Matrix(4, 4, {(1, 1) = -2*t^2/U-(8/3)*t^4/U^3, (1, 2) = 2*t^2/U+(8/3)*t^4/U^3, (1, 3) = 0, (1, 4) = 0, (2, 1) = 2*t^2/U+(8/3)*t^4/U^3, (2, 2) = -2*t^2/U-(8/3)*t^4/U^3, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = U+2*t^2/U+(8/3)*t^4/U^3, (3, 4) = 2*t^2/U+(8/3)*t^4/U^3, (4, 1) = 0, (4, 2) = 0, (4, 3) = 2*t^2/U+(8/3)*t^4/U^3, (4, 4) = U+2*t^2/U+(8/3)*t^4/U^3})

(4.2)

#Already pretty slow :(

computeHBlockDiag(6,2,H0,H1,H2);

Warning,  computation interrupted

 

 

``

 

Download MapleWorksheet.mw

Hi all,

I have an expression of the form Sum(a[l]*x^l,l=0..n).

Is there a shorter way to obtain let's say the 5 lowest orders than add(coeff(expression,x,l)*x^l,l=0..4) ?

 

Cheers

NOh

How to find the coefficients of the terms diff(eta1(xi1),xi1)*diff(eta2(xi2),xi2)eta1(xi1)^2,...

I have an expression like this:
B0:=(phi(x))^2:
B1:=diff(phi(x),x):
B2:=diff(phi(x),x,x):
B3:=B2^2:
B4:=(phi(x))^2:
B5:=B1^2:

C0:=(psi(x))^2:
C1:=diff(psi(x),x):
C2:=:C1^2:
C3:=

D0:=(eta(x))^2:

F1:=phi(x)*psi(x):
F2:=phi(x)*eta(x):
F3:=psi(x)*eta(x):

g1:=B1*C1:
g2:=B2*phi(x):
g3:=B2*psi(x):
g4:=B2*eta(x):

T:=A0011*B0+A0022*C0+A0033*D0+A0012*F1+A0013*F2+A0023*F3+A1111*B5+A1122*C2+A1112*g1+A2011*g2+A2012*g3+A2013*g4+A2211*B5:

A0011 and A0022 and etc are constants and coefficients.

Now I want to extract some constants like A1112 or A2013 from T. Please write out an useful code for extract these coefficients!

Thanks

Hello.

I am trying to extract all the coefficients of a linear equation by calling coeffs function.

eq := 1.2*a[2]+1.3*a[3]+1.1*a[1]+1.0

1.2*a[2]+1.3*a[3]+1.1*a[1]+1.0

(1)

 

vars := [seq(a[i], i = 1 .. 3)]

[a[1], a[2], a[3]]

(2)

coeffs(eq, vars)

1.0, 1.2, 1.3, 1.1

(3)

``


I expected I receive the coefficients in the same order as in vars variable, but I was wrong. How to extract coefficients in the order I need?

Download test.mw

 

I want to extract all the coefficients of a polynomial. For example, let p:=x^5-8x^3+2, and the function coeffs(p) returns 1, -8, 2. In fact, I want to obtain 1, 0, -8, 0, 0, 2. Thanks to everyone.

Dear all, 

I'm trying to extract the coefficients from the equation below, the fat expressions in the equation. I don't have any trouble seperating the sine or cosine functions. But the constants are a problem. Since t is the only variable in the function i tried, coeff(R, t, 0). This does not work apparantly. Any suggestions? 

 

R:=(1/12)*C2^3*cos(2*t) - (1/48)*C2^3*cos(4*t) - C2^3*sin(t) + C2^3*sin(3*t)-C2^2*C4*cos(t) + C2^2*C4*cos(3*t) - (1/8)*C2^2*C4*sin(2*t) + (1/16)*C2^2*C4*sin(4*t) + (1/16)*C2*C4^2*cos(4*t) - C2*C4^2*sin(t) - C2*C4^2*sin(3*t) - C4^3*cos(t) - C4^3*cos(3*t) - (1/24)*C4^3*sin(2*t) - (1/48)*C4^3*sin(4*t) - (1/16)*C2^3 - (1/16)*C2*C4^2 - (1/2)*C2*cos(2*t) + C2*sin(t) + C4*cos(t) + (1/2)*C4*sin(2*t) + (1/2)*C2

Hi,

I have these lines in my code, the function alpha:=(m,n,1)->...... is defined in the last line of the code below, but when I want to calculate alpah(1,1,1), there is no numeric value. Why????  Many thinks

 

 restart:
with(LinearAlgebra):
with(plots):
with(PDEtools):
with(IntegrationTools):
interface(rtablesize=20):
d:=1: N:=2: a:=1: h:=a/N:
Kernel(x,y):=ln(abs(x-y)):

 eq2:=int(Kernel(x,y)*phi(y),y=-a..a)=sum(int(Kernel(x,y)*phi(y),y=n*h..(n+d)*h),n=-N..N-d):

Approximate the integral
eq3:=phi->int(Kernel(x,y)*phi(y),y=n*h..(n+d)*h)=add(beta[i,n]*phi((n+i-1)*h),i=1..d+1):
eq4:=int(Kernel(x,y)*phi(y),y=n*h..(n+d)*h)=add(alpha[m,n,i]*phi((n+i-1)*h),i=1..d+1):

Compute the coefficients  beta[i]

Vct_basis:=[seq(x^i,i=0..d+1)]:
fct:=[seq(unapply(Vct_basis[i],x),i=1..d+2)]:


sys:=[seq(eq3(fct[i]),i=1..d+1)]:
x:=m*h:
w := [seq(beta[i,n],i=1..d+1)]:
M,b := GenerateMatrix(sys,w):

M1:=-M: V:=-b:

Vect_beta:=(M1)^(-1).V:# Vect_beta is a vector.

beta[1]:=Vect_beta[1]:  
alpha1:=(n,m)->beta[1];
(n, m) -> beta[1]
alpaha(1,1);
                                alpaha(1, 1)  ??????????????????? No numeric result


 

Dear all

 

Please I need your help to simplify by the coefficient a in this Matrix

I have The matrix A defined by  A:=Matrix(2,2, [[a,a],[3*a,4*a]]);

I want with maple transform A to  A:=a*Matrix(2,2, [[1,1],[3,4]]);

Thanks for your Help.

 

In the following script, I am trying to understand why evala returns an error. It returns

                Error, (in evala/Reduce/nf/indep) invalid arguments to coeffs

in a couple of places. I tried, and I can get around the errors by doing it a complex way, but it seems like I'm just not using evala correctly. Perhaps someone can comment? I'd very much appreciate it.

 

Hey guys..

I need some help on determining the correlation coefficient between my data points for an Influenza epidemic and the SIR model, with my estimated parameters Beta and Alpha. The initial conditions for the equations are defined at the beginning of my worksheet:

SIR_model.mw

Hope someone can help me ;)

 

 

 

I have a multivariate polynomial equation, in that somehow I know the coeffcients, using this information, I want to extract the variables. This will be the opposite of coeffs function.

for e.g. I have 3*x3 + 5*x4

Given 3 and 5, I want to extract x3 and x4.

 

Thanks in advance.

 

Satya

 

Hello,

i want to solve the following for q[b], theta is a symbolic coefficient. When I use the solve command it produces a RootOf that i cannot handle by using either allvalues or evalf. I can't use fsolve since there is theta 

1 2 Page 1 of 2