## Problem with instruction subs of Maple...

Hi, i have a problem with subs instruction. I'd like to change a function D(s) with symbol d/ds d(t), but i won't to calculate derivate, I want only change symbol. Thanks a lot.

## How to substitute algebraic variables and function...

I have a set of 15 equations in state space form, and I'm just trying to program a way to substitute all variables representing the time derivates as for example x__s_dot (t) as diff(x__s (t), t)  and diff( x__s_dot (t),t) as diff(x__s (t), t,t) so I can manipulate my equations easier.

The last half of the list xx has the variables that I want to substitute, the x,y and u (with respective diff(x__s (t), t) ) variables are always constant, but in the case of zeta, eta and u I might have indexes from 1 to n , in this case just 1 and 2.

I tried a bunch of methods including creating vectors with the seq, op commands and substituting them into my original equations with subs, algsubs but none of the things I programmed worked the way I wanted, I ended up with a very inefficient way , doing it manually, but the point is that I wanted to automate this bit. I've been doing maple for about 2 weeks and I still struggle a lot with it, I would greatly appreciate any guidence/advice.

My original equations are actually much bigger and my original code too, I tried to shorten it a bit just for making my problem simpler to understand but the equations still look really big here, If there is another way to format this question please do advice so.

EDIT : I think my last code was hard to understand because my equations were too big and it looked all messy and horrible, I edited to show just one vector of variables, I think that if it works here, it should work on the rest of my code:

 > interface(rtablesize=50):
 >
 > nq := 15;             xxUNDOT := [ seq ( xx[i], i = 1..nq),              seq ( diff(xx[i],t), i = 1..nq)];
 (1)
 > DOTL := [ seq ( xx[i], i = 1..nops(xx)) ]: DOTR := [ seq ( xxUNDOT[i], i = 1..nops(xx))]: Vector[column](DOTL),Vector[column](DOTR); for i from nq+1 to nops(xx) do newxx    := subs[inplace][eval](   op(i,DOTL) = op(i,DOTR) ,xx): end do:
 (2)
 > Vector[column](newxx);
 (3)

I tried to make a for loop that substitutes each variable one by one, but it only seems to work for the last term, I don't know why, please help or suggest another method? I also have diff(x__s,t,t) terms in my equations, not just diff(x__s,t), but I guess only by specifying the first derivate it should work?

Thanks.

## why algsubs fails here but subs work?...

Maple newbie here.

I do not understand why algsubs do not replace the symbol in the denominator in the following example, but does replace it in the numerator. This is on Maple 2017 on windows 7

Here is the expression

sol := u(x, t) = Sum((2*cos((1/2)*Pi*_Z1)+
2+4*(-1)^(1+_Z1))*sin(Pi*_Z1*x/L)*
exp(-k*Pi^2*_Z1^2*t/L^2)/(Pi*_Z1),
_Z1 = 1 .. infinity);

I wanted to replace _Z1  with n

But algsubs will not replace _Z1 in the denominator as seen in this screen shot but subs does:

From help, my impression is that algsubs is superset of subs. Only case where algsubs will not do what subs does is, according to help:

 The algsubs command goes recursively through the expression . Unlike the subs command it does not substitute inside indexed names, and function calls are applied to the result of a substitution

But There is no indexed names here?

Can someone please explain why algsubs fails to do the substitution in the denominator in this example?

## Manipulation of derivative symbolically ...

Dear friend,

please suggest a way for manipulation of derivative of a function symbolically. Assume

Typesetting[Suppress]([f(x)]);
Ex1 :=expand(diff(f(x+y)+x*f(x-y), x)^2)+expand(diff(f(x-y)-y*f(x+y), x)^2);

Result is as needed:

Ex1 := (D(f))(x+y)^2+2*(D(f))(x+y)*f(x-y)+2*(D(f))(x+y)*x*(D(f))(x-y)+f(x-y)^2+2*f(x-y)*x*(D(f))(x-y)+x^2*(D(f))(x-y)^2+(D(f))(x-y)^2-2*(D(f))(x-y)*y*(D(f))(x+y)+y^2*(D(f))(x+y)^2

But later I cannot use D(f) as a function. Expressions

subs((D(f)) = (t -> 1-t), Ex1);
subs(diff(f(x),x) = (t -> 1-t), Ex1);

do not handle it as a function.

## Remove subscripts from functions in list and group...

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.

-Yeti

## subs based on a variable...

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)

subs(f2,values):

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

## an error occurred, diff received 0...

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.

Amr

## How to change summation index of Sum from PDE sol...

Hello.

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.

Thanks.

 >
 >
 >
 >
 >
 (1)
 >
 (2)
 >
 (3)
 >
 (4)
 >

## How to substitute one predefined PDE equation into...

Hi,

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.

Thanks

## Why wouldn't subs work?...

Hello people in maple primes

I have a question, which is about the matrix shown in http://www.mapleprimes.com/questions/217852-HOW-I-Convert-Root-Of-In-To-Another-Common-Form

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]]);
B:=subs(l*b*c*(j+k)=alpha,A);
C:=subs(j*alpha^(1/2) = beta,B);
e:=subs(alpha^(1/2) = gamma,B);

Best wishes.

taro

## Fundamental theorem of calculus...

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.

restart;

#I defined F__0 as

F__0:=x->Int(f(t),t=a..x);

#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.

bb:=F(x)-F__0(x)=C;

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

bb1:=subs(x=a,bb):cc:=simplify(%);

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

cc1:=subs(isolate(cc,C),bb);

#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.

subs(x=b,dd);

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.

taro

## Why difference in speed?...

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

restart;
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

restart;
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

## Problem with subs command ...

Hello,

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.

Regards.

## Function "subs repeated"...

Hello,

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:

 Code: 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 :

 Code: 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:

 Code: subs(ChgtVariables,eq);

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

## How to sketch a straight line in three-dimensional...

by: Maple

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.

 1 2 3 4 5 6 Page 1 of 6
﻿