acer

32385 Reputation

29 Badges

19 years, 334 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

I'm not sure whether any of this might be useful to you.

restart:

`diff/E`:=proc(t) K(t); end proc:

diff(E(y),y);

                                    K(y)

`D/E`:=t->K:

D(E);

                                      K

D[1](E)(y);

                                    K(y)

(D@@2)(E);

                                    D(K)

(D@@2)(E)(y);

                                   D(K)(y)

acer

This looks like a regression bug to me. I've submitted a bug report (SCR).

I'm guessing that you already know that you can use the strings ["1,"10","100"] and parse, to get it to work in both versions. But that's just a workaround; it should still work with numeric values.

acer

As Carl mentions, you are being bitten by premature evaluation. Note that sum and Sum adhere to Maple's usual evaluation rules for procedure calls: first the supplied arguments are evaluated, and only after that are they passed to the called procedure.

You can search this site, or the web, and find lots of similar examples.

The problem is one of usage -- that the new user has not yet learned how the system normally works.

And it comes up for lots of other commands too (again, especially for new users, until they learn how Maple works). You can find examples for plot, fsolve, Optimization:-Minimize, and so on.

Carl mentions two ways to make things work, but in fact there are sometimes more than just those two. Some commands like plot, fsolve, and Minimize also accept a so-called operator form for the first argument. For example plot(f,0..1) instead of plot(f(x),x=0..1), where there is no dummy variable and hence no function call to be accidentally prematurely evaluated.

And for some other commands, such as sum and product there are related commands add and mul with special evaluation rules. The basic idea is that add follows a special rule: it receives its first argument without that having being evaluated. For this and a few other reasons using add is often suggested for finite summation, over using sum.

If you want to see what the call sum(pdf4(i),i=3..3) is actually sending to the sum procedure then call pdf4(i) alone, outside of a call to sum or anything else, and see what result is returned.

I won't repeat the two ways that Carl mentioned in his good Answer. Both those approaches often suffice with both the commands like plot as mentioned above, and also with the commands like sum as mentioned above. However I often prefer using the approaches I've mentioned above, if possible, rather than having to rewrite my custom procs to return unevaluated on nonnumeric input.

What you've shown is a (mostly new user related) usage problem. But there are indeed flaws. 2D Math Input allows for the typeset summation (Sigma) symbol only for sum and Sum. There is no good hook between the typeset summation symbol and add, unless you make your code convoluted by utilizing special exports of the Physics package. Yet add would often serve better than sum. And 2D Math Input is the default for new users. And the documentation pushes palette use big time. And combined that is all quite unfortunate because it make this issue arise far more than ought to be necessary.

Note that new users to Mathematica often have equivalent or similar problems, until they learn to use NumericQ.

acer

Matrix(5,5,(i,j)->i+j)

Also if you intend on indexing into this Matrix (let's suppose you assigned it to the name A) later on then use the syntax such as A[i,j] and not A[i][j] which can be quite inefficient.

In this particular case that you've asked about you can also do simply Matrix(5,5,`+`) , but the way above shows how you can construct more generally.

acer

I use Maple 18.02 below, as this Question is marked as related to Maple 18.

Here are a few ways that work with your approach of using double pairs of unevaluation quotes around each of the plot calls.

restart;
with(plots):
with(plottools):
Parab1 := ''plot(a*x^2, x = -1 .. 1, y = -3 .. 3)'':
Parab2 := ''plot(a*x^2+1, x = -1 .. 1, y = -3 .. 3)'':
L:=Array(1..2):
L[1]:=Parab1:
L[2]:=Parab2:

Explore((unapply('display'(L),a))(A), parameters = [[A = -1.0 .. 1.0, label=a]]);

And here is another way that also works with that approach,

restart;
Parab1 := ''plot(a*x^2, x = -1 .. 1, y = -3 .. 3)'':
Parab2 := ''plot(a*x^2+1, x = -1 .. 1, y = -3 .. 3)'':
L:=Array(1..2):
L[1]:=Parab1:
L[2]:=Parab2:

F:=proc(A)
     plots:-display(eval(L,a=A));
end proc:
Explore(F(a), parameters=[a=-1.0 .. 1.0]);

And here is another way that also works with that approach,

restart;
with(plots):
with(plottools):
Parab1 := ''plot(a*x^2, x = -1 .. 1, y = -3 .. 3)'':
Parab2 := ''plot(a*x^2+1, x = -1 .. 1, y = -3 .. 3)'':
L:=Array(1..2):
L[1]:=Parab1:
L[2]:=Parab2:

eval('Explore'('display'(L), parameters = [[a = -1.0 .. 1.0]]));

Here is a way which doesn't use unevaluation quotes.

restart:
H:=proc(a)
     plots:-display(Array([plot(a*x^2, x = -1 .. 1, y = -3 .. 3),
                           plot(a*x^2+1, x = -1 .. 1, y = -3 .. 3)]));
end proc:  
Explore(H(a), parameters=[a=-1.0 .. 1.0]);

acer

[This answer has been edited: see comments below for modifications, obtaining 16 solutions with all of t,t1,t2,t3 between 0 and 2*Pi]

Here I'm getting 128 solutions with all of t,t1,t2,t3 between -2*Pi and 2*Pi.

(I used Maple 18.02 on 64bit Linux.)

restart:
f1 := -8100+(-30+70*cos(t1)-40*cos(t2))^2
      +(-70*sin(t1)+40*sin(t2))^2:
f2 := (-20-80*cos(t3))^2+(-15+70*cos(t1)+10*cos(t1+t))^2
      +(-70*sin(t1)-10*sin(t1+t)+80*sin(t3))^2-5625:
f3 := (-20-80*cos(t3))^2+(15+40*cos(t2)+10*cos(t1+t))^2
      +(-40*sin(t2)-10*sin(t1+t)+80*sin(t3))^2-5625:
f4 := 10*cos(t1+t)*(30-70*cos(t1)+40*cos(t2))
      -10*sin(t1+t)*(70*sin(t1)-40*sin(t2)):
origsys := {f1,f2,f3,f4}:
sys := map(expand,origsys):
T := [indets(sys,function)[]]:
Tsub := [seq(x=freeze(x),x=T)]:
extra := {seq(sin(r)^2+cos(r)^2-1,r=[t,t1,t2,t3])}:
Digits,oldDigits := 20*Digits,Digits:
raw := thaw(RootFinding:-Isolate(eval(sys union extra,Tsub),eval(T,Tsub))):
Digits := oldDigits:
gen := proc(cand)
  local c, v;
  c[t]:=select(has,cand,t);
  c[t1]:=select(has,cand,t1);
  c[t2]:=select(has,cand,t2);
  c[t3]:=select(has,cand,t3);
  [seq(seq(seq(seq([e,f,g,h],e=c[t3]),f=c[t2]),g=c[t1]),h=c[t])];
end proc:
sols := {seq(seq(
      `if`(evalf[2*Digits](max(map(abs,eval(origsys,eq))))<10^(-Digits+1),
           eq, NULL),
      eq=evalf[2*Digits](gen(
map(eq->select(u->is(abs(rhs(u))<=2*Pi),
    [seq(lhs(eq)=rhs(eq)+k*Pi,k=-4..4)])[],
    (map(eq->fsolve(eq,indets(eq,name))[],raw[i])))
))),
    i=1..nops(raw))}:

sols := evalf[15](sols):
nops(sols);
                                     128

max(seq(max(map(abs,evalf[2*Digits](eval(origsys,s)))), s in sols));
                                          -11
                                6.02316 10   

#seq(print(evalf[10](s)), s=sort(sols));

@Petra Heijnen Yes, in Maple 18 you can insert a PlotComponent from the palette, and then in your looping code update that component by using SetProperty to give it a new value.

For example, insert a PlotComponent from the palette. Right-click on it and discover that its name/identity is, say, PlotComponent0. Then, in your looping code, whenever you wish to update the component to show a new plot you can use the SetProperty command. Your code might look something like this,

for i from something to whatever do

  if some_condition_of_yours then
    P := plot(...);
    DocumentTools:-SetProperty("PlotComponent0", ':-value', P, ':-refresh'=true);
  end if;

end do:

Now, it's up to you where you insert the component. You might want it close to the place from which you execute your code, but that's up to you.

Apply the evalf command to obtain floating-point approximations.

Eg,

evalf( ln(3) )

evalf( exp(5) )

acer

I'm supposing that this is homework of some sort, and that the goal is for you to figure out how and why (and whether) it can be done.

Create column Vectors of the coefficients in g1 and g2, both with respect to all of the terms present, ie., [x,x^2,y,y^2]. Concatenate those as columns of a Matrix M. Create a similar Vector V, for f. Then call LinearSolve(M,V) and the result if it exists will be a 2-element Vector whose entries are the coefficients of the linear combination.

If you have any constant terms then make the Vectors one row taller, and use them in the extra row. 

acer

Here is a hack for 2D display. I expect that someone could also do similarly for 3D.

Of course, it's not ideal to try and turn boxes into disks. The ideal would be support for customized appearance in the GraphTheory package itself.

Improvements welcome, but please remember that it was just written as a quick hack. I used a disk, as it was simplest to code. It could look better with an ellipse, depending on the length/height ratio of a vertex label.

 

restart:

quad2disk := proc(P::specfunc(anything,:-PLOT))
  subsindets(P,
             And(specfunc(':-POLYGONS'),
                 satisfies(p->nops(p)>0
                           and op(1,p)::[[numeric,numeric],[numeric,numeric],
                                         [numeric,numeric],[numeric,numeric]])),
             proc(p) local t,r;
               (t,r):=selectremove(type,[op(p)],list(list(numeric)));
               ':-POLYGONS'(seq(op(plottools:-disk([(op([1,1],pp)+op([3,1],pp))/2,
                                    (op([1,2],pp)+op([2,2],pp))/2],
                                   (op([1,1],pp)-op([3,1],pp))/2)),
                                pp in t), op(r)); end proc);
end proc:

with(GraphTheory):
W := Graph(undirected, {{0, 1}, {0, 2}, {0, 3}}):
HighlightEdges(W, W, black):
HighlightVertex(W, [1, 2, 3, 0], gray):
DrawGraph(W);

quad2disk(DrawGraph(W));

with(SpecialGraphs):
G := SoccerBallGraph():
HighlightVertex(G, Vertices(G), cyan):
HighlightEdges(G, G, gray):

DrawGraph(G);

quad2disk(DrawGraph(G));

with(RandomGraphs):
T := RandomTree(10):
HighlightVertex(T, Vertices(T), gold):
HighlightEdges(T, T, COLOR(RGB,0.2,0.2,0.7)):
DrawGraph(T);

quad2disk(DrawGraph(T));

with(GraphTheory):
G := Graph({{1,2},{2,3},{3,1},{3,4},{4,5},{5,6},{6,4}}):
A := ArticulationPoints(G):
HighlightVertex(G,A,magenta):
DrawGraph(G);

quad2disk(DrawGraph(G));

acer

Sorry this took a while. Hopefully it is still of some use to you.

I was able to compute smaller/shorter/simplified results for your problematic expressions, for which simplify(...) and simplify(...,size) was failing you. And using the same technique I was also able to compute smaller/shorter results for your earlier expressions which had previously been simplified. See the attached worksheet. I get similar results in Maple 18.02 and Maple 2015.1, but notice that timings are higher in 64bit Windows than 64bit Linux on comparable hardware.

The problems seem to boil down to a few things. Don't evaluate some of the unknowns to floating-point values before simplifying, if you can avoid it. It can lead to a variety of severe problems. Also, simplification of huge expressions containing trig function calls is tricky. In this case it seems that restraining the combining of trig terms to just a few of the relevant unknowns may be key.

I also tried to avoid final results with this kind of ugly and suspicious form, which you might normally hope would produce saner coefficients but which in fact gets returned by some simplification call:

(1.2349876*10^(-9)) * ( ...+ (5.6781234*10^11)*subexpr ... + anotherexpr/(3.4568762*10^(-8)) ... )

This particular run was in 64bit Maple 18.02 on Windows 7.


restart:

with(LinearAlgebra):
with(Physics[Vectors]):
with(ArrayTools):
with(DEtools):
with(inttrans):
Setup(mathematicalnotation=true):
#with(CodeGeneration):
#with(StringTools):


# Three different commands to measure the "size" of an expression.
# Using `length` to measure simplification is not so sensible.
# The command `simplify/size/length` is what simplify(...,size) uses.

:-Length:=u->[length(u), `simplify/size/length`(u),
              MmaTranslator:-Mma:-LeafCount(u)]:

e_x:=_i:
e_y:=_j:
e_z:=_k:

e_x_I :=  e_x:
e_y_I :=  cos(alpha(t))*e_y + sin(alpha(t))*e_z:
e_z_I := -sin(alpha(t))*e_y + cos(alpha(t))*e_z:

e_x_II := cos(beta(t))*e_x_I - sin(beta(t))*e_z_I:
e_y_II := e_y_I:
e_z_II := sin(beta(t))*e_x_I + cos(beta(t))*e_z_I:

e_x_L :=  cos(eta(t))*e_x_II + sin(eta(t))*e_y_II:
e_y_L := -sin(eta(t))*e_x_II + cos(eta(t))*e_y_II:
e_z_L :=  e_z_II:

e_x_R :=  -cos(delta(t))*e_x_L + sin(delta(t))*e_z_L:
e_y_R :=  -e_y_L:
e_z_R :=  sin(delta(t))*e_x_L + cos(delta(t))*e_z_L:

r_L := x(t)*e_x + y(t)*e_y + z(t)*e_z:

r_Schnitt := r_L + Lsy*e_y_L + Lsz*e_z_L:

r_R := r_Schnitt - Lsz*e_z_R - Lsy*e_y_R:

omega_L_in_I:=diff(alpha(t),t)*e_x + diff(beta(t),t)*e_y_I + diff(eta(t),t)*e_z_II:

omega_R_in_I:=omega_L_in_I + diff(delta(t),t)*e_y_L:

F_T_L := -m*diff(r_L,t,t):
F_T_R := -m*diff(r_R,t,t):

J := Matrix([[19670, 0, 0], [0, 19390, 757], [0, 757, 750]]):
omega_L_in_I_v:=Vector([omega_L_in_I.e_x,omega_L_in_I.e_y,omega_L_in_I.e_z]):
omega_R_in_I_v:=Vector([omega_R_in_I.e_x,omega_R_in_I.e_y,omega_R_in_I.e_z]):
H_L_v:= MatrixVectorMultiply(J,omega_L_in_I_v):
H_R_v:= MatrixVectorMultiply(J,omega_R_in_I_v):
H_L:=H_L_v(1)*e_x+H_L_v(2)*e_y+H_L_v(3)*e_z:
H_R:=H_R_v(1)*e_x+H_R_v(2)*e_y+H_R_v(3)*e_z:

M_T_L:=-diff(H_L,t):
M_T_R:=-diff(H_R,t):

G_L:=-m*g*e_z*evalf(cos(w_phi)):
G_R:=-m*g*e_z*evalf(cos(w_phi)):

F_S_L:=Fsx*e_x + Fsy*e_y + Fsz*e_z:
F_S_R:=-F_S_L:

M_S_L:=Msx*e_x_L + Msz*e_z_L:
M_S_R:=-M_S_L:

M_F_L:=-c_d*delta(t)*e_y_L:
M_F_R:=-M_F_L:

F_R_L:=Frlx*e_x+Frly*e_y+Frlz*e_z:
F_R_R:=Frrx*e_x+Frry*e_y+Frrz*e_z:
M_R_L:=Mrlx*e_x+Mrly*e_y+Mrlz*e_z:
M_R_R:=Mrrx*e_x+Mrry*e_y+Mrrz*e_z:

ForBil_L:=F_T_L+G_L+F_S_L+F_R_L=0:
ForBil_R:=F_T_R+G_R+F_S_R+F_R_R=0:

MomBil_L:=M_T_L+M_S_L+M_F_L+M_R_L=0:
MomBil_R:=M_T_R+M_S_R+M_F_R+M_R_R=0:

NeuBasisFR:=[e_x = e_x_neuFR, e_y = e_y_neuFR, e_z = e_z_neuFR]:

BaseFR:= [e_x_2FR=subs(NeuBasisFR,e_x_II),e_y_2FR=subs(NeuBasisFR,e_y_II), e_z_2FR=subs(NeuBasisFR,e_z_II)]:

solFR:=solve(BaseFR,{e_x_neuFR,e_y_neuFR,e_z_neuFR}):

Neu_ForBil_R:=collect(collect(collect(simplify(subs(solFR,subs(NeuBasisFR,ForBil_R))),e_x_2FR),e_y_2FR),e_z_2FR):

NeuBasisM:=[e_x = e_x_neuM, e_y = e_y_neuM, e_z = e_z_neuM]:

BaseM:= [e_x_2M=subs(NeuBasisM,e_x_L),e_y_2M=subs(NeuBasisM,e_y_L), e_z_2M=subs(NeuBasisM,e_z_L)]:

solM:=solve(BaseM,{e_x_neuM,e_y_neuM,e_z_neuM}):

Neu_MomBil_L:=collect(collect(collect(simplify(subs(solM,subs(NeuBasisM,MomBil_L))),e_x_2M),e_y_2M),e_z_2M):

 

Neu_ForBil_L:=ForBil_L:
Neu_MomBil_R:=collect(collect(collect(simplify(MomBil_R),e_x),e_y),e_z):

ForX_L:=coeff(lhs(Neu_ForBil_L),e_x)=0:
ForX_R:=coeff(lhs(Neu_ForBil_R),e_x_2FR)=0:
ForY_L:=coeff(lhs(Neu_ForBil_L),e_y)=0:
ForY_R:=coeff(lhs(Neu_ForBil_R),e_y_2FR)=0:
ForZ_L:=coeff(lhs(Neu_ForBil_L),e_z)=0:
ForZ_R:=coeff(lhs(Neu_ForBil_R),e_z_2FR)=0:
TorX_L:=coeff(lhs(Neu_MomBil_L),e_x_2M)=0:
TorX_R:=coeff(lhs(Neu_MomBil_R),e_x)=0:
TorY_L:=coeff(lhs(Neu_MomBil_L),e_y_2M)=0:
TorY_R:=coeff(lhs(Neu_MomBil_R),e_y)=0:
TorZ_L:=coeff(lhs(Neu_MomBil_L),e_z_2M)=0:
TorZ_R:=coeff(lhs(Neu_MomBil_R),e_z)=0:

Fsx:=solve(ForX_L,Fsx):
Fsy:=solve(ForY_L,Fsy):
Fsz:=solve(ForZ_L,Fsz):
Msx:=solve(TorX_L,Msx):
Msz:=solve(TorZ_L,Msz):

Sys:=[ForX_R,ForY_R,ForZ_R,TorX_R,TorY_L,TorY_R,TorZ_R]:

GenKo:={x(t),y(t),z(t),alpha(t),beta(t),eta(t),delta(t)}:

res:=solve(Sys,diff(GenKo,t,t)):

FirstOrderSys := convertsys(res, [], GenKo, t, y, dy ):
Length(FirstOrderSys);
Length(FirstOrderSys[1]);

[17369013, 10628827, 3022100]

[17368631, 10628589, 3022026]

# Don't assign floating-point values before simplification.
# It can lead to several problems, including:
#   - prohibitively high time resources trying to simplify
#   - results with uncancelled float coefficients with both very large
#     and very small exponents
#   - failure to simplify productively

#Lsy:=0.04685:
#Lsz:=0.02108:
#:-R:=0.122:
#ra:=0.376:
#m:=1.269:
#g:=9.81:
#w_phi:=Pi/180:
#c:=10000:
#d:=1000:
#c_d:=10001:
#mu:=0.2:

# Instead of assigning float values up front, create a list of
# equations at which the purely exact & symbolic simplification
# results can be evaluated. In other words, when possible instantiate
# at floats after simplification, rather than before.

vals:=[Lsy=0.04685,Lsz=0.02108,:-R=0.122,ra=0.376,m=1.269,
       g=9.81,w_phi=Pi/180,c=10000,d=1000,c_d=10001,mu=0.2]:

Length(FirstOrderSys);

[17369013, 10628827, 3022100]


# The expressions assigned to attempt[i] are like your original results.

Length(FirstOrderSys[1][2]);
attempt[2]:=CodeTools:-Usage( eval(simplify(combine(FirstOrderSys[1][2]),size),vals) ):
Length(attempt[2]);

[348758, 211475, 59706]

memory used=1.35GiB, alloc change=0 bytes, cpu time=32.93s, real time=32.91s, gc time=1.65s

[23064, 15987, 4230]

# Actually your original instantiated at floats first, before simplifying.
# But for the earlier terms like FirstOrderSys[1][2] it doesn't seem to make
# such a difference.
Length( simplify(combine(eval(FirstOrderSys[1][2],vals)),size) );

[23064, 15987, 4230]

Length(FirstOrderSys[1][4]);
attempt[4]:=CodeTools:-Usage( eval(simplify(combine(FirstOrderSys[1][4]),size),vals) ):
Length(attempt[4]);

[320581, 190662, 55457]

memory used=0.85GiB, alloc change=0 bytes, cpu time=21.65s, real time=21.21s, gc time=1.72s

[15652, 10059, 3115]

Length(FirstOrderSys[1][6]);
attempt[6]:=CodeTools:-Usage( eval(simplify(combine(FirstOrderSys[1][6]),size),vals) ):
Length(attempt[6]);

[283665, 169216, 48990]

memory used=478.32MiB, alloc change=1.08MiB, cpu time=11.23s, real time=11.16s, gc time=780.00ms

[4482, 2545, 1043]

Length(FirstOrderSys[1][8]);
attempt[8]:=CodeTools:-Usage( eval(simplify(combine(FirstOrderSys[1][8]),size),vals) ):
Length(attempt[8]);

[282660, 168429, 49389]

memory used=0.87GiB, alloc change=-1.08MiB, cpu time=23.37s, real time=23.03s, gc time=1.70s

[17310, 11123, 3442]

Length(FirstOrderSys[1][10]);
#simplify(combine(FirstOrderSys[1][10])):
#simplify(combine(FirstOrderSys[1][10]),size):

[2860090, 1731310, 499444]

Length(FirstOrderSys[1][12]);
#simplify(combine(FirstOrderSys[1][12])):
#simplify(combine(FirstOrderSys[1][14]),size):

[6579073, 4041715, 1144160]

Length(FirstOrderSys[1][14]);
#simplify(combine(FirstOrderSys[1][14])):
#simplify(combine(FirstOrderSys[1][14]),size):

[6693656, 4115730, 1164858]

S:=proc(ee, valeqns::list(`=`), unkns::set)
  local t1,t2,t3,t4,ft4;
  # Basic preliminary simplification.
  t1:=simplify(ee,':-size');
  # This step seems to improve the step that follows it.
  t2:=simplify(t1,':-trig');
  # Only combine a subset of the trig function calls.
  t3:=frontend(combine,[t2],[{`+`,`*`,`^`,
                              specfunc(identical(unkns[]),
                                       {':-sin',':-cos'})},{}]);
  t4:=simplify(t3,size);
  # Evaluate at the float values you had for some of the unknowns.
  ft4:=eval(t4,valeqns);
  # Turn rational coefficients into floats, to get cancellation
  # with floats in `valeqns`. But leave alone integer coefficient
  # inside trig function calls.
  simplify(frontend(expand,[frontend(evalf,[ft4])]),':-size');
end proc:

Length(FirstOrderSys[1][10]);
smaller[10]:=CodeTools:-Usage( S(FirstOrderSys[1][10], vals, {y[1],y[7]}) ):
Length(smaller[10]);

[2860090, 1731310, 499444]

memory used=8.26GiB, alloc change=1.61MiB, cpu time=3.40m, real time=3.32m, gc time=16.22s

[37250, 26612, 5085]

Length(FirstOrderSys[1][12]);
smaller[12]:=CodeTools:-Usage( S(FirstOrderSys[1][12], vals, {y[1],y[7]}) ):
Length(smaller[12]);

[6579073, 4041715, 1144160]

memory used=19.34GiB, alloc change=0 bytes, cpu time=8.24m, real time=7.92m, gc time=50.25s

[59613, 42377, 8229]

Length(FirstOrderSys[1][14]);
smaller[14]:=CodeTools:-Usage( S(FirstOrderSys[1][14], vals, {y[1],y[7]}) ):
Length(smaller[14]);

[6693656, 4115730, 1164858]

memory used=21.55GiB, alloc change=0 bytes, cpu time=8.76m, real time=8.34m, gc time=57.28s

[58252, 41483, 7994]

Length(FirstOrderSys[1][2]);
Length(attempt[2]);
smaller[2]:=CodeTools:-Usage( S(FirstOrderSys[1][2], vals, {y[1],y[7]}) ):
Length(smaller[2]);

[348758, 211475, 59706]

[23064, 15987, 4230]

memory used=392.70MiB, alloc change=0 bytes, cpu time=10.56s, real time=10.30s, gc time=889.21ms

[8479, 5978, 1191]

Length(FirstOrderSys[1][6]);
Length(attempt[6]);
smaller[6]:=CodeTools:-Usage( S(FirstOrderSys[1][6], vals, {y[1],y[7]}) ):
Length(smaller[6]);

[283665, 169216, 48990]

[4482, 2545, 1043]

memory used=332.69MiB, alloc change=0 bytes, cpu time=9.52s, real time=9.23s, gc time=951.61ms

[2792, 1723, 441]

Length(FirstOrderSys[1][8]);
Length(attempt[8]);
smaller[8]:=CodeTools:-Usage( S(FirstOrderSys[1][8], vals, {y[1],y[7]}) ):
Length(smaller[8]);

[282660, 168429, 49389]

[17310, 11123, 3442]

memory used=245.90MiB, alloc change=0 bytes, cpu time=7.58s, real time=7.43s, gc time=858.01ms

[6469, 4396, 954]

# additional numeric values for sanity check
othernames:=indets(FirstOrderSys,name) minus {constants} minus {undefined}
                           minus {dy[1],dy[2],dy[3],dy[4],dy[5],dy[6],dy[7],dy[8],
                                  dy[9],dy[10],dy[11],dy[12],dy[13],dy[14]}:
othervals:=Equate([othernames[]],[seq(0.5+0.01*i,i=0..nops(othernames)-1)]):

evalf[500](eval([eval(FirstOrderSys[1][2],vals), smaller[2]], othervals)): evalf(%);

[dy[2] = 1.324343197, dy[2] = 1.324343197]

evalf[500](eval([eval(FirstOrderSys[1][8],vals), smaller[8]], othervals)): evalf(%);

[dy[8] = -1.570269543, dy[8] = -1.570269543]

evalf[500](eval([eval(FirstOrderSys[1][10],vals), smaller[10]], othervals)): evalf(%);

[dy[10] = .3065316635, dy[10] = .3065316633]

evalf[500](eval([eval(FirstOrderSys[1][12],vals), smaller[12]], othervals)): evalf(%);

[dy[12] = .4532824238, dy[12] = .4532824238]

evalf[500](eval([eval(FirstOrderSys[1][14],vals), smaller[14]], othervals)): evalf(%);

[dy[14] = -9.305591553, dy[14] = -9.305591553]

 


Download Example_modif2_1802.mw

If you want to see the module definition "shell" then you can still get that printed by querying for the 2nd operand of the module.

op(2,eval(sqrt));

      module() local ModuleApply, Nested, Product, Primes; end module

The above was done in Maple 2015.1, and is also what Maple 18.02's Standard GUI prints when eval(sqrt) is called.

acer

You seem to have used "basis" in two ways. At the end you mention a basis {C}, apparently in the mathematic sense. At the beginning you mentioned the A,B,C,D for a "basis" for your computations, apparently using the term in a non-technical sense. The inconsistency may confuse some people.

I'll use DD rather than D which is a protect Maple name with special meaning as the differential operator.

If you want to express the Matrix A+B in terms of the "basis" of Matrices {C,DD} then you can turn everything into column Vectors, concatenate the new column-Vector elements of your "basis" into a Matrix, and use LinearSolve.

Note that {C} or {C,DD} aren't enough to form a basis for the 4-dimensional space that spans the space. So for some candidate Matrix other that the Matrix A+B your set {C,DD} might not suffice.

Taking your trivial example,

restart:                                                       

DD:=Matrix(2,symbol=d):                                        
C:=Matrix([[i,i],[-i,i]]):                                     

A:=Matrix([[1,0],[0,1]]):                                      
B:=Matrix([[0,1],[-1,0]]):                                     

with(LinearAlgebra):                                           

f:=m->convert(m,Vector[column]):                               

sol:=LinearSolve(<f(C)|f(DD)>,f(A+B)):                         

A+B=add(`if`(sol[j]=0, 0, sol[j].[C,DD][j]), j=1..Dimension(sol));

                         [ 1    1]           [i     i]
                         [       ] = (1/i) . [       ]
                         [-1    1]           [-i    i]

In other words the problem solved above is to express A+B as a linear combination of the entries of {C,DD}. (...and the solution of that might be done using 4x1 column vectors rather than 2x2 Matrices.) Is that close to what you want? For other examples you might need to use values rather than just symbols for the entries of Matrix DD. In your trivial example is turns out not to have mattered...

You can change the above example to have C = Matrix([[0,i],[-i,0]]) instead, and then use f(A.B) instead of f(A+B) in the call to LinearSolve. The result of coefficients, sol, would happen to be the same.

acer

Fun := Diff(f(x), x):           

int(Fun, x = 2 .. 7, continuous);

                                 -f(2) + f(7)

acer

If you assign that expression to a name, say ee, then try,

simplify(ee, size)

acer

First 224 225 226 227 228 229 230 Last Page 226 of 336