Items tagged with subs


I have a list of functions which looks like this:

RR:={F[l, m-2, n-1], F[l, m+2, n], F[l, m+2, n-1], F[l-1, m+1, n-2], ...}

I wish to remove the first and second arguments from the functions, so only leaving the third argument containing the n's. I then wish to group these remaining terms together to shorten the list. i.e.

RR:={F[n-1], F[n], F[n-2]}

I have used the 'subsop' command with 1 and 2 specified as NULL in a loop, but I was wondering if there is a better way to do it? I like to avoid loops where possible and use some inbuilt Maple magic to make it tidier and (usually) more efficient.



I'm trying to use subs to substitute an unknown variable with a number in a Matrix

My Matrix is called values and I have the following

change := f2:

subs(change = 5, values):

This does nothing but when I have the following, it works as expected (All f2 in the Matrix values are replaced with 5)


I'm wondering if its trying to find and replace 'change'. If this is the case how can I get it to use whats assigned to the variable. (I've tried eval(change) but that doesn't work either)

Many thanks

Hello, I have a function defined as

                                                   g :=  (x, y)->diff(u1(x, y), x, x)+diff(u2(x, y), x, y). 

I want to define another function as follows

                                                           f :=  (y) ->subs(x = 0, g(x, y)) ,

Now, when I want to calculate numerical values for the new function f(0), f(0.1), f(0.2),..... and so on. The following massage appear

Error, (in f) invalid input: diff received 0, which is not valid for its 2nd argument.

What is the problem here.





I have a Pde solution in from of the sum.

pde := diff(u(x, t), t) = diff(u(x, t), x$2)

symbolic := pdsolve([pde, u(x, 0) = 1, u(0, t) = 0, u(1, t) = 0])

symbolic := u(x, t) = Sum(-(2*((-1)^_Z9-1))*sin(_Z9*Pi*x)*exp(-Pi^2*_Z9^2*t)/(Pi*_Z9), _Z9 = 1 .. infinity)


I tried a subs or eval command dosen't work.




pde := diff(u(x, t), t) = diff(u(x, t), `$`(x, 2)):

ics := [u(x, 0) = 1, u(0, t) = 0, u(1, t) = 0]:

pds := pdsolve(pde, ics, numeric, time = t, range = 0 .. 1, spacestep = 1/4024, timestep = 1/4024):

symbolic := pdsolve([pde, u(x, 0) = 1, u(0, t) = 0, u(1, t) = 0])

u(x, t) = Sum(-2*((-1)^_Z9-1)*sin(_Z9*Pi*x)*exp(-Pi^2*_Z9^2*t)/(Pi*_Z9), _Z9 = 1 .. infinity)


eval(rhs(symbolic), `~`[_Z9] = n)

Sum(-2*((-1)^_Z9-1)*sin(_Z9*Pi*x)*exp(-Pi^2*_Z9^2*t)/(Pi*_Z9), _Z9 = 1 .. infinity)


subs(`~`[_Z9] = n, rhs(symbolic))

Sum(-2*((-1)^_Z9-1)*sin(_Z9*Pi*x)*exp(-Pi^2*_Z9^2*t)/(Pi*_Z9), _Z9 = 1 .. infinity)


subs[eval](`~`[_Z9] = n, rhs(symbolic))

Sum(-2*((-1)^_Z9-1)*sin(_Z9*Pi*x)*exp(-Pi^2*_Z9^2*t)/(Pi*_Z9), _Z9 = 1 .. infinity)







I am trying to substitute an general function pde expression I have derived in maple into another general function pde expression but cannot seem to find a method that works. 

Attached is an example worksheet - any help offered would be much appreciated.


Hello people in maple primes

I have a question, which is about the matrix shown in

Why can't C below be shown with beta?

A := Matrix(3, 3, [[-a, a, 0], [0, 0, -sqrt(l*b*c*(j+k))/(j+k)], [2*j*sqrt(l*b*c*(j+k))/((j+k)*l), 2*k*sqrt(l*b*c*(j+k))/((j+k)*l), -c]]);
C:=subs(j*alpha^(1/2) = beta,B);
e:=subs(alpha^(1/2) = gamma,B);

Best wishes.




Hello people in mapleprime,

Though I wrote the title as Fundamental theorem of calculus,

what I am considering is just how to continue the chain of codes in calculation.


#I defined F__0 as


#Then, the difference between a primitive function of f(x), F(x), and F__0 is no more than a constant C, so I write.


#Then, substituting "a" into equation "bb", I obtain the value of F(a)


#Then, I substituted the value of C in "bb1" into "bb,"  obtaining the following "cc1."


#And, then, I isolated the term of Int(f(t),t=a..x)  in cc1,

dd:=isolate(cc1,Int(f(t), t = a .. x));

#And, then, I substitute x=b into the outcome of dd, and obtain the final equation.



Surely, with the above code, I could get the fundamental theorem. But, it looks in a little roundabout way.

So, I thought I would ask here about whether there aren't any better ways to do the fundamentally the same thing or

hints to improve the above code.

Please teach me about this.


Thanks in advance.



The first example is very slow compared to the second.  The difference is in the definition of f().

y := int(1/(-0.4016e-1*m^(2/3)-0.211e-3*m^(5/3)), m);
f:= unapply(abs(y), m):
n := 500: ## sample size
M := <seq(2*idx/n,idx=1..n)>; ## m
Y := f~(M)+~Statistics:-Sample(Normal(0,3), n)^+; ## signal + noise

y := int(1/(-0.4016e-1*m^(2/3)-0.211e-3*m^(5/3)), m);
f:= (x) -> abs(subs(m=x,y));
n := 500: ## sample size
M := <seq(2*idx/n,idx=1..n)>; ## m
Y := f~(M)+~Statistics:-Sample(Normal(0,3), n)^+; ## signal + noise



I am unable to use subs() command when using subscript : I'd like to replace YP__1 with dGx in the equation :

"Eq:= YP__1 = Y__2" (Eq:= YP1=Y2)


 so I have tried : subs({YP__1=dGx},Eq)


But it doesn't work... It give me : YP__1 = Y__2 and I would like to have dGx = Y__2


I have tried also with subs({YP[1]=dGx},Eq) but doesn't work too.


If I am not using subscript, for exemple : Eq:= YP1 = Y2


And do : subs({YP1=dGx},Eq)


That works great...


But I must use subscript __ because Eq is a result from ODEtools (convertsys).


Can you help me please ?


Thanks you very much.




I look for a maple function / or a piece of code which enable to do repeated substitutions. In other words, repeat substitutions until there is no more possible substitution.

How can I do to make repeated substitutions ?

Here a example I would like to solve with maple

Equation on which I would like to conduct variables changements: 

eq := sin(psi[1](t)+gamma0(t))*cf+sin(gamma0(t)+theta[1](t)+psi[1](t))*mf-sin(gamma0(t))*hf-cos(gamma0(t))*lf+xp[1](t) = sin(psi[2](t)+gamma0(t))*cf+sin(gamma0(t)+theta[2](t)+psi[2](t))*mf-sin(gamma0(t))*hf-cos(gamma0(t))*lf+xp[2](t)

Definition of variables changement :

ChgtVariables:=psi[1](t)=Psi[1](t) - theta[1](t) + gamma[1](t),psi[2](t)=Psi[2](t) - theta[2](t) + gamma[2](t);psi[3](t)=Psi[3](t) - theta[3](t) + gamma[3](t),psi[4](t)=Psi[4](t) - theta[4](t) + gamma[4](t),theta[1](t)=Theta[1](t)+gamma[1](t),theta[2](t)=Theta[2](t)+gamma[2](t),theta[3](t)=Theta[3](t)+gamma[3](t),theta[4](t)=Theta[4](t)+gamma[4](t);

Application of subs function:


The problem is that only one step of substitutions is conducted.

Here the expected result :

(sin(theta[1](t))-theta[2](t))*cf - (sin(gamma[1](t)-sin(gamma[2](t)))*mf  + xp[2](t) - xp[1](t) = 0

Thanks a lot for your hemp

A wealth of knowledge is on display in MaplePrimes as our contributors share their expertise and step up to answer others’ queries. This post picks out one such response and further elucidates the answers to the posted question. I hope these explanations appeal to those of our readers who might not be familiar with the techniques embedded in the original responses.

The Question: How to sketch a line in space?

vahid65 wanted to know how to sketch the line with equation (x-2)/3 = (y-1)/4 = (z-3)/3 in a three-dimensional space.

This question was answered using two different approaches that we will discuss.

The first approach, given by Preben Alsholm, suggested using these commands: solve, subs, and plots:-spacecurve.

Preben provided the following lines of code:

  1. {(x-2)/3 , (y-1)/4 , (z-3)/3} =~t;
  2. solve(%,{x,y,z});
  3. L:=subs(%,[x,y,z]);
  4. plots:-spacecurve(L,t=-5..5,thickness=3,color=red);

The first line sets the three expressions equal to t using the element wise operator =~.  This distributes the operation of equality over the elements of the set of expressions, forming a set of equations.

Result-1: {(x-2)/3=t, (y-1)/4=t, (z-3)/3=t}

The second line invokes the solve command. The solve command, solve(equations, variables), solves one or more equations or inequalities for their unknowns. So in this line, this command was used to solve each expression for its corresponding unknown.

Result-2: {(x= 2+3t, y=1+4t, z= 3+3t}

You may have noticed that the % symbol is used within the command. This symbol is referring to the equation label that was created chronologically last. 

The third line uses the subs command. The subs command, subs(x=a,expr), substitutes “a” for “x” in the expression expr. In this case, “a” is the reference to the equation label referenced by (%) and expr is the sequence of variables x,y,z. The square brackets around expr forms a list, and the replacement imposed by the subs command replaces each of the three names x, y, and z with their equivalents in the set of equations returned by the solve command.

Result-3: [2+3t,1+4t, 3+3t ]

Finally the last line uses the plots:-spacecurve function.  This function, spacecurve(sc,r,opts),  graphs a parametrically defined curve in three-dimensional Cartesian space. 

In this example the first parameter, sc, is replaced by L since L has the properties of a list. The parameter  r is an equation containing the parameter name and the parameter range; here it is the equation t=-5..5. Last but not least, the opts parameter (which is optional) gives the user the opportunity to specify the optional properties of the graph, properties such as thickness and color of the space curve. 

Result 4: 


Another contributer, Carl Love, suggested that these commands could be combined using the zip function, zip( f, u, v), which is an unusual application of it. The zip command applies elementwise to corresponding members of the two lists u and v, the binary function f, creating a new list r, whose members are f(uk,vk).

Carl provided the following code:

plots:-spacecurve(  zip(solve, [(x-2)/3 , (y-1)/4 , (z-3)/3] =~ t, [x,y,z]),  t= -5..5, thickness= 3, color= red, axes= normal);


In this case zip is applying solve to u, a list of equations, and v, a list of variables. The equations in u are those in Result-1. The zip function returns the solution of each equation for the indicated variable, that is, the new list r is the list in Result-3. This list is the first argument of plots:-spacecurve. Finally, the parameter range and opts are up to the user’s preferences.

A second approach was suggested by Kitonum. The difference between this approach and the first one is that here we are not using the solve command. Instead, we are treating the line as an intersection of two planes.

Kitonum's code is as follows:

  1. L := [(x-2)*(1/3), (y-1)*(1/4), (z-3)*(1/3)]:
  2. plots[intersectplot](L[1]-L[2], L[2]-L[3], x = -4 .. 4, y = -4 .. 4, z = -4 .. 4, linestyle = 1, thickness = 3, axes = normal, orientation = [60, 75], view = [-1 .. 3, -4 .. 2, -1 .. 4]);

The first statement initializes a list L that contains all the desired expressions in the given symmetric form of the line.

In the second statement Kionum used the plots[intersectplot] command. This command graphs, in three-dimensional Cartesian space, the intersection of a pair of surfaces. This example uses the calling sequence: intersectplot(expr1, expr2, x=a..b, y=c..d, z= e..f, options)

What are expr1 and expr2 used in Kitonum’s solution? The pairwise differences of L[1] and L[2], and L[2] and L[3] are planes, the intersection of which is the desired line in space.

expr1 = L[1] – L[2] = (x-2)*(1/3)- (y-1)*(1/4)

expr2= L[2] - L[3] = (y-1)*(1/4)-(z-3)*(1/3)

The variables x,y, and z are the coordinate names and define the axes, whereas a, b, c, d, e, f define the ranges. In this case they were taken as -4 or 4.

In the options parameter Kitonum used linestyle, thickness, axes, orientation, and  view. The help page “plot3d,option” details these and other options that apply.


This blog was written by our intern Pia under the supervision of Dr. Robert Lopez. We both hope that you find this useful. If there is a particular question on MaplePrimes that you would like further explained, please let us know. 

question1 := b(t)*(diff(c(t), t))*(diff(a(t), t))+a(t)*(diff(b(t), t))

how to subs(b(t)=0, question1) result in a(t)*(diff(b(t), t)) ?

in fact b(t) = 0 but diff(b(t), t) != 0 

f=x^2.  It's easy to compute the fouier transform. F(y)=fourier(f,x,y).

However, I want to do more. replace the variable y with a new formula g(z)=z^2.

I tried  "subs(y=g,F)". But failed. Need your help.


f := x^2



F := fourier(f, x, y)

-2*Pi*Dirac(2, y)


g := z^2



subs(y = g, F)

-2*Pi*Dirac(2, y) = z^2







I have an expression like this:

a:= b(t)+diff(b(t),t)+diff(b(t),t$2)+diff(b(t),t$3)+...:


I want to substitute diff(b(t),t) with b_symbol_diff. I dont know how many more differentials are in the expression.

If I use subs(diff(b(t),t)=b_symbolic_diff,a)

maple also substitutes in diff(b(t),t$2). Because b_symbol_diff is not a function of t the higher order differentials are zero.

Is there a way to tell maple not to substitute those expressions that are enclosed in diff()?

I need this because I want to calculate the Jacobian of a vector and VectorCalculus[Jacobian]() does not accept functions.

Thanks in advance!

a1:= f(x) :
> T1 :=simplify((taylor(a1,x=alpha,N+3))):
> E1:=subs([seq(((D@@i)(f))(alpha) = 0,i=1..m-1),f(alpha)=0,x=e[n]+alpha],T1):
> g1 :=(convert(simplify(series((E1,e[n]=0,N))),polynom));


1 2 3 4 5 6 7 Page 1 of 7