Ternox

129 Reputation

3 Badges

15 years, 55 days

MaplePrimes Activity


These are answers submitted by Ternox

Hello Jakubi,

Thanks to give me some keywords for my research.

Ternox

Yes, it's excalty what I needed !!!

Many thanks Pagan for the quick answer !!!
Ternox

Hi Therock31,

I proposed a way  I used to solve and plot differential equations. If you don't have initial conditions you could use " dsolve(ODE)"  as told in the help. ( you should obtain an exact solution, I tryed in my code and it looks requiere boundary conditions...).

Unfortunatly my knowlegde about this subject is quite limited.
Maybe try to repost your code, simply because it will be really easier for everybody to work on. ( I advice you to copy from Maple to wordpad, then from wordpad to this forum).

Good luck , see you soon,
Ternox
 

Hello Scott

Thank you for the link to maplesoft applications.
But I don't have MapleSim. I hace only Maple 13, and the pendulum into doesn't seem work.


Well, I will keep on looking for.
Many thanks for the hint.

Ternox

Hello,

Yes both ways works very well !!!

Many thanks, it will be helpfull for me.

 

Ternox

 

Hello Alex and DJC,

Thank you for your advice. And you help. It works now.

Ternox

 

 

Hello,

I have some Ode's like this. I used the following code. I hope if you adapt it a little it will works.

 


with(plots);


# put here the constants.

ode[1]:= ....=0;
ode[2]:=....=0


E := seq(ode[i], i = 1 .. N);

# example of boundary conditions...
ic1 := Theta[1](0) = (1/6)*Pi, Theta[2](0) = 0;
ic2 := (D(Theta[1]))(0) = 0, (D(Theta[2]))(0) = 0;

bc := ic1, ic2;
sys := {E, bc};

sol := dsolve(sys, numeric, output = listprocedure);

# replace Theta[] by what you need
plots[odeplot](sol, [t, Theta[1](t)], 0 .. 5);
plots[odeplot](sol, [t, Theta[2](t)], 0 .. 5);


Regards Ternox

If you put " : " instead of  " ="  does it works ?

I must confess I never used this text sheet.

Good luck
Regards
Ternox

Hi Foo,

Joe is right, if it's a simple line, just put   ""   :  "" at the end,  If you use  " for ... " or "while ..."  ect don't forget to put " ;  " at each line and after the " od" or " fi" put "  :  "

If you have  a double for boucle   eg   "for i to N  for j to N ..... od; od; " Maple will don't show anything. Whatever the colomn or semi-colomn. To let it apear, you have to create a double for boucle using print( ... ) od; od;  Maple will show the result. Whatever the colomn or semi-colomn.
 

Regards,

Ternox

 

Hello every body,

Thank you very much for the two answer. It works well know !!! 
 

Many thanks
Ternox

 

Good morning Doug,

Thanks again for your help in my project. You are really involved to help others and it's really good, thank you !!!

After a few days breack I am back :) I looked carefully your idea and some parts are really interresting and helpful to save time. Particulary the construction of the matrix. However I must confess I tried to use the procedure, but it didn't worked as I wanted.

The following program is an improved version thanks to you.

 

 

 

restart;
N := 2:
j := 1: X[1] := 0: L[0] := 0: X[0] := 0: Y[0] := 0:
 
while j < N+1 do
X[j] := X[j-1]+L[j-1]*sin(Theta[j-1](t)):
Y[j] := Y[j-1]+L[j-1]*cos(Theta[j-1](t)):
j := j+1
end do:


for i to N do
X[i] := X[i]+S[i]*sin(Theta[i](t))-e[i]*cos(Theta[i](t)):
Y[i] := Y[i]+S[i]*cos(Theta[i](t))+e[i]*sin(Theta[i](t)): # coordonates created
Xp[i] := diff(X[i], t);
Yp[i] := diff(Y[i], t):                                         # deratives wrt time created
V[i] := factor(combine(Xp[i]^2+Yp[i]^2)): # please read V^2
T[i] := (1/2)*M[i]*V[i] :                                    # kinetic energy
end do:

for i to N do
for j to N do
TiDDThetaj[i, j] := frontend(diff, [T[i], diff(Theta[j](t), t)]): # creation of derivatives of T wrt diff(Theta[j](t))
end do: end do:

for j to N do
U[j] := add(TiDDThetaj[c, j], c = 1 .. N):  # sum of previous derivatives
SS[j] := diff(U[j], t):                                      # derivative of the sum wrt time
Z3[j] := seq(diff(Theta[j](t), t)-(diff(Theta[k](t), t)) = 0, k = 1 .. N): # creation of sequence to put egal 0 the difference of derivatives
end do:

C := seq(Z3[i], i = 1 .. N):

for j to N do
SS0[j] := subs(C, eval(SS[j], [sin = 0, cos = 1])): #Substitution  and approximation cos=1 and sin=0
ZZZ[j] := seq(diff(Theta[i](t), t, t) = `if`(i = j, 1, 0), i = 1 .. N):
end do:

AAA := Matrix(N, N, proc (i, j) options operator, arrow; collect(subs(ZZZ[j], SS0[i]), diff(Theta[j](t), t, t)) end proc); # matrix created !!! Thx

 

It is really shorter than the previous and more efficient.
Now I will improve the 3-dimension pendulum.

I will show it to you when it will be ready :)

Thousand Thanks !!!
Ternox


PS: Do you have an advice to name the variable. I gave some names as U, SS, SS0, ZZZ, Z, is there a sort of rule to be more clear about the name of  the variable?




 

Good afternoon Doug,

First, many thanks for you full response. I didn't try this way. However as you precised, this way simplified too many terms I need.

My problem consist to look for the equations of inverted pendulum in 2D and 3 D for N segments. The program below give us the full equation of the motion. I have good reasons to think this part is all right.

Simply, my problem consist now in approximations.
First I consider that cos ( theta[i] - theta[j])=1, sin ( theta[i] - theta[j])=0        # in 3D it's cos ( -/+theta[i] -/+ phi[i]  -/+ theta[j]-/+ phi[j])=1, sin ( -/+theta[i] -/+ phi[i]  -/+ theta[j]-/+ phi[j])=0#


Second consider that first derivative of angles ( and the cross derivatives) is =0.

I made sort or little fonctions to do it but it's really " made by hand" see below but it's not really rigourus. It work I think... but...

A way to do this approximations could be to use taylor series but the result given is a bit strange...

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
## the beggining of the program Inverted pendulum excentred mass Nsegments 2D
restart;
N := 2;
j :=1 : X[1] := 0: L[0] := 0: X[0] := 0: Y[0] := 0:

while j < N+1 do
X[j] := X[j-1]+L[j-1]*sin(Theta[j-1](t)):
Y[j] := Y[j-1]+L[j-1]*cos(Theta[j-1](t)):
j := j+1:
end do;:

for i to N do
X[i] := X[i]+S[i]*(sin(Theta[i]))(t)-e[i]*cos(Theta[i](t)):
Y[i] := Y[i]+S[i]*(cos(Theta[i]))(t)+e[i]*sin(Theta[i](t)):
Xp[i] := diff(X[i], t):
Yp[i] := diff(Y[i], t):
V[i] := factor(combine(Xp[i]^2+Yp[i]^2)):
T[i] := (1/2)*M[i]*V[i]
end do:

for i to N do
for j to N do
TiDDThetaj[i, j] := frontend(diff, [T[i], diff(Theta[j](t), t)]):
end do end do:

for j to N do
U[j] := sum(TiDDThetaj[c, j], c = 1 .. N):
DS[j] := diff(U[j], t)
end do;

## end

/////////////////////////////////////////////////Now here are my little programs to simplify (until the end of the program):

 


for i to N do  # creation of the approximations cos (a-b)=1, sin (a-b)=0, difference of partial derivatives = 0
Z1[i] := seq(cos(Theta[i](t)-Theta[j](t)) = 1, j = 1 .. N);
Z2[i] := seq(sin(Theta[i](t)-Theta[j](t)) = 0, j = 1 .. N);
Z3[i] := seq(diff(Theta[i](t), t)-(diff(Theta[j](t), t)) = 0, j = 1 .. N) end do;

A := seq(Z1[i], i = 1 .. N);
B := seq(Z2[i], i = 1 .. N);
C := seq(Z3[i], i = 1 .. N);

for i to N do #substitution of the approxmimation at the previous full equation
SSSimplified[i] := subs(A, B, C, SS[i]) end do;

for i to N do
for j to N do
M[i, j] := collect(SSSimplified[i], diff(Theta[j](t), t, t))
end do end do;

for j to N do  # creation of a sequences to exclude the number j in order to do some substitutions to clear components useless.
ZA[j] := seq(s, s = 1 .. j-1);
ZB[j] := seq(s, s = j+1 .. N);
ZZ[j] := ZA[j], ZB[j];
Z[j] := seq(diff(Theta[e](t), t, t) = 0, e = ZZ[j]);
II[j] := seq(diff(Theta[e](t), t, t) = 1, e = j);
ZZZ[j] := Z[j], II[j] end do;


for i to N do #Now we use the previous sequences to let appear only what we are interested
for j to N do
R[i, j] := subs(ZZZ[j], M[i, j]);
W[i, j] := R[i, j]
end do end do;

AZERTY := seq([seq(W[i, j], j = 1 .. N)], i = 1 .. N);
ResultKineticEnergyNSeg2DExcentred := Matrix([AZERTY]);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

You can try with n:=3;

I tryed to made a matrix to be more clean.

The next step will be to solve it, but each thing in each time.

 

The approximation question is still a probelm for me, so if you could help me doing it in a more simple and formal way, it could help me.

 Many thanks again,
Ternox




 

Hello Alec,

Thank you for your short-time answer.
When I use "series(A,t,2)" Maple doesn't develop:  sin(Theta[1](0)-Theta[2](0)) or  (cos(Theta[2]))(0)*e[2]*sin(Theta[2](0))

honnestly I  just would like to appromimate Cos( ...) =1, Sin(...)=0 and diff(theta...)=0 to obtain only 2nd order PDE terms.

Many thanks,

Ternox

 

hello again,

 

I have just had an awakening

for i to N do

for j to N do

TiDDThetaj[i, j] := frontend(diff, [T[i], diff(Theta[j](t), t)])

end do end do;

 

 

I seem to works - really really - much better !!!

 

Many thanks every body !!!

Ternox

Hello, every body and many thanks for your answers!!!

It allow me to search in several ways I didn't know.

The " difff " fonction doesn't exist in Maple 13, unfortunatly. This solution could have been the most efficient I think.

As I am not used to practice function like " thaw ,value ,subs  ,x=freeze(x),...  " it request a little time of research for me but it looks interesting.

 

Well, I dislike to put such equations coming from nowhere for you but it should be helpful to see how I tried to solve my problem.

Well... this is the velocity of the second element of an inverted pendulum (excentred mass) composed by N elements
V[2] := L[1]^2*(diff(Theta[1](t), t))^2+2*L[1]*(diff(Theta[1](t), t))*S[2]*(diff(Theta[2](t), t))*cos(Theta[1](t)-Theta[2](t))-2*L[1]*(diff(Theta[1](t), t))*e[2]*(diff(Theta[2](t), t))*sin(Theta[1](t)-Theta[2](t))+S[2]^2*(diff(Theta[2](t), t))^2+e[2]^2*(diff(Theta[2](t), t))^2

then I multiply by M2 a half to obtain the kinetic energy

T[2] := (1/2)*M[2]*(L[1]^2*(diff(Theta[1](t), t))^2+2*L[1]*(diff(Theta[1](t), t))*S[2]*(diff(Theta[2](t), t))*cos(Theta[1](t)-Theta[2](t))-2*L[1]*(diff(Theta[1](t), t))*e[2]*(diff(Theta[2](t), t))*sin(Theta[1](t)-Theta[2](t))+S[2]^2*(diff(Theta[2](t), t))^2+e[2]^2*(diff(Theta[2](t), t))^2)
 

until know I don't have any problem to create a program to give me it. but know, As I was unable to dérivate. I decided to make a " for bouble" to substitute all the diff(theta[1,2 ... N]) by K[1,2...N] However, I was not able to create a for function into the subs() function, so I did it " brute force" until 11 @_@ ...

for i to N do T[i] := subs(diff(Theta[1](t), t) = K[1], diff(Theta[2](t), t) = K[2], diff(Theta[3](t), t) = K[3], diff(Theta[4](t), t) = K[4], diff(Theta[5](t), t) = K[5], diff(Theta[6](t), t) = K[6], diff(Theta[7](t), t) = K[7], diff(Theta[8](t), t) = K[8], diff(Theta[9](t), t) = K[9], diff(Theta[10](t), t) = K[10], diff(Theta[11](t), t) = K[11], T[i]) end do;
 

then I derivate # The reason because I made this variable changing

for j to N do for i to N do TT[i, j] := diff(T[j], K[i]) end do end do; # The reason because I made this variable changing

 

then I changed again, in the other way
## TiDDThetaj[i, j] means partial derevatif of T[i] wrt theta[j]

for j to N do for i to N do TiDDThetaj[i, j] := subs(K[1] = diff(Theta[1](t), t), K[2] = diff(Theta[2](t), t), K[3] = diff(Theta[3](t), t), K[4] = diff(Theta[4](t), t), K[5] = diff(Theta[5](t), t), K[6] = diff(Theta[6](t), t), K[7] = diff(Theta[7](t), t), K[8] = diff(Theta[8](t), t), K[9] = diff(Theta[9](t), t), K[10] = diff(Theta[10](t), t), K[11] = diff(Theta[11](t), t), TT[i, j]) end do end do

 

It's look working because I obtain some think like this:

>TiDDThetaj[1, 3];
       (1/2)*M[3]*(2*L[1]^2*(diff(Theta[1](t), t))+2*L[1]*L[2]*(diff(Theta[2](t), t))*cos(Theta[1](t)-Theta[2](t))+2*L[1]*S[3]*(diff(Theta[3](t), t))*cos(Theta[1](t)-Theta[3](t))-2*L[1]*e[3]*(diff(Theta[3](t), t))*sin(Theta[1](t)-Theta[3](t)))

But really this way requests so long. In addition, later I will be oblige to approximate sin( theta([i]-theta[i+1])=1,cos( theta([i]-theta[i+1])=0 but for all the combination possible with N numbers. :p



That's why I should understand how to derivate directly without variable changing to save time.

Thank you for your help!!! I keep on searching.

Ternox


 

 

 

 

 

Page 1 of 1