Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Is it possible to generate a XMLElement by using part of the code to be generated with a string, or are the only methods a strict use of AddAttribute and AddChild?

Hope the code below explains what I mean. The first line is a strict copy of a declaration in the help file.

The question is if I could use some part of the definition which is saved in the str variable and combine it into the first declaration?


 

with(XMLTools)

x := XMLElement("a", ["colour" = "red", "style" = "italic"], ["some content", XMLElement("b", ["colour" = "blue"], "more text"), "still more text"])

_XML_Element(_XML_ElementType("a"), [_XML_Attribute(_XML_AttrName("colour"), _XML_AttrValue("red")), _XML_Attribute(_XML_AttrName("style"), _XML_AttrValue("italic"))], [_XML_Text("some content"), _XML_Element(_XML_ElementType("b"), [_XML_Attribute(_XML_AttrName("colour"), _XML_AttrValue("blue"))], [_XML_Text("more text")]), _XML_Text("still more text")])

(1)

str := "["colour"="red","style"="italic"],["some content",XMLElement("b",["colour"="blue"],"more text"),"still more text"]"

"["colour"="red","style"="italic"],["some content",XMLElement("b",["colour"="blue"],"more text"),"still more text"]"

(2)

``


 

Download xml_string.mw

Is there a command that can show me all multipermutations?

If I have a set (1,2,3) I want an output of all the multipermutations of length n.

For example for n=2:
[1,1],[1,2],[1,3],[2,1],[2,2],[2,3],[3,1],[3,2],[3,3].

I suspect I have to use the Iteration command MultiPartition, but I don't understand the examples given on maplesoft:
https://www.maplesoft.com/support/help/Maple/view.aspx?path=Iterator%2FMultiPartition

Dear all,

In some step of my program, Maple cannot understand that the two following vectors are equal:

V1 := Vector[column](8, [1, 2, 2, 1, 3, A, B, 1/(A + B)^2]);

V2 := Vector[column](8, [1, 2, 2, 1, 3, A, B, 1/(A^2 + 2*A*B + B^2)]);

I tried to use the following two commands:

LinearAlgebra:-Equal(V1[6 .. 8], V2[6 .. 8]);

verify(V1, V2, 'Vector(expand)');

but Maple still returns 'false' instead of 'true'

Could somebody help me please ?
Best regards,

I'd like to define a proc, which takes first argument to be either an ode (i.e. type `=`) or set of ode's, or list of ode's.

However, I do not know how to tell Maple that the list or set, if that is the type, to be a list of `=` and no other type.

Here is what I tried to make it more clear

If I do this

restart;

interface(warnlevel=4);
kernelopts('assertlevel'=2): 


foo:=proc(ode::{`=`, set,list},func::`function`,$)
   print("ode=",ode);
   print("func=",func);
end proc:

Then Maple will check that the first argument is ANY one of `=`, set or list. 

But does not check if the list or set contains only equations of type `=`.  So I am able to call the above like this

ode1:=diff(y(x),x)=1:
ode2:=diff(y(x),x)=x:
foo(ode1,y(x));  #this is OK
foo([ode1,a],y(x))  #this is wrong

Which is wrong, since `a` is not of type `=`.

Next I tried this (I also wanted to check that if first argument is list or set, that it is not empty, so added extra check)

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

foo:=proc(ode::{`=`, 
                   And(set,satisfies(x-> (numelems(x)<>0 and type(x,`=`))  )),
                   And(list,satisfies(x-> (numelems(x)<>0 and type(x,`=`))  ))
                   },
                   func::`function`,$                                   
                   )

  print("ode=",ode);
  print("func=",func);
end proc;

But the above gives an error

ode1:=diff(y(x),x)=1:
ode2:=diff(y(x),x)=x:

foo([ode1,a],y(x))  

I also tried

foo:=proc(ode::{`=`, 
                   And(set,satisfies(x-> type(x,`=`)  )),
                   And(list,satisfies(x-> type(x,`=`) ))
                   },
                   func::`function`,$                                   
                   )

   print("ode=",ode);
   print("func=",func);

end proc;

Also gives erorr when called 

foo([ode1,ode2],y(x))

Ofcourse, I can just leave the check as in first case above, and in the proc itself, do the check myself manually by going over each entry in the list or set to make sure each entry is of type `=`. 

But I wanted Maple to do this work for me, if possible.

What is the correct syntax for doing so?

Maple 2020.2

 

[Perhaps this should be a Post rather than a Question.]

As far as I can tell, RootOf is the only Maple command that takes a bound variable on input and returns an unevaluated form with the bound variable renamed (to _Z). Why is that? Either all should do it (definite integrals, limit, sum, etc.) or none should. 

Pros:

Making a substitution for a variable that occurs both free and bound in the same expression is a major source of programming error. Renaming bound variables helps to ameliorate that. 

Cons:

The unexpected appearance of _Z in their results seems to be a great source of confusion to new users. However, if more commands did this, perhaps it would be more expected.

Feel free to start a brainstorming discussion on this, as if it were a Post, even if you don't have a direct Answer for the Question. If that's the way that the thread heads, I'll change it to a Post.

Hi,

I'm experiencing something quite annoying.

When copying Maple input code from an executable block into a document block, just after a line of text was written.

So for example <CTRL+T><write some text><CLICK ENTER FOR \newline><CTRL+M><PASTE MAPLE INPUT 1D CODE><CLICK ENTER>

The block doesn't get executed. I don't see the blue Maple output. Why is that? Is this a bug or I'm I doing something wrong. Normally logic would dictate after pressing enter it would execute the 1D code and simply show the blue output just below the 1D one-liner?

Another question:

I want to write the values of function g(x,t) as scientific notation.  I mean I want to write 1.95*10^(-3)  instead of 0.001953125 etc.


Yes, by clicking right-click and clicking the numeric formatting, I can transform all columns of Array A, but I want to transform just the last column g(x,t) in Array A.

 

restart:
  f:=(x,t)->x*t;
  g:=(x,t)->x^2*t;interface(rtablesize=20):
  A:=Array( [ [`x`,`t`,`f(x,t)`, `g(x,t)`],
              seq
              ( seq
                ( [i, j, f(i,j), g(i,j)],
                  j=0.125..0.875, 0.25
                ),
                i=0.125..0.875, 0.25
              )
            ]
          );  

 

lambda:=0.1:N:=5:M:=sqrt(N(N+1)):omegap:=10:phi:=0:

var:={n(t),u(t)}:
dsys:={diff(n(t),t)=-2*(n(t)-N)+(u(t)-abs(M)*exp(I*phi))*exp(-2*I*omegap*t/lambda)+conjugate((u(t)-abs(M)*exp(I*phi))*exp(-2*I*omegap*t/lambda)),diff(u(t),t)=-2*(1-I*delta)*u(t)+2*(n(t)-N)*exp(-2*I*omegap*t/lambda)+2*abs(M)*exp(I*phi)}:
res1:=dsolve(dsys union {n(0)=0,u(0)=0},numeric,output=listprocedure):

# (this command need to be changed) P1:=plots[odeplot3](res1,[[t,(n(t))]],0..10,axes=boxed,tickmarks = [3, 2], color = black, thickness = 4, linestyle = solid, titlefont = [Helvetica, roman, 18], labeldirections = [horizontal, vertical], labelfont = [Helvetica, roman, 24]);

The member command allows testing, if a value is in a table.

But is it possible to check if the index is used, not the value?

L["hello"] := "funny"

"funny"

(1)

member("hello", L)

false

(2)

member("funny", L)

true

(3)

``

Download list.mw

I am trying to plot generator reactive output (Q) over a range of generator power output (P) with field current (Ifldc) and terminal voltage (Et) constant using “solve”. The system of equations includes an interpolating fiction Ifld(el).

I’m looking for some help as to how to configure a solution. Attached are a few of my failed attempts.

The upload of my file deleats the "solve" fo my first try it is:

     


 

``

``

MvaGen := 1354; PfGen := .935; KvGen := 24

                   

           Xd__u := 1.89 - Synchronous reactance of d-axis, Unsatuarted

              Xq__u := 1.80 - Synchronous reactance of q-axis, Unsatuarted

              X__l := .26   - leakage reactance d or q-axis``

``

            Ifld__base := 3114

``

Open Ckt Sat Curve DS807-1a

     First col=Ifld amps   

     Second col= el voltage behind leakage reactance

 

OC_SatDat := Matrix(16, 2, {(1, 1) = 0, (1, 2) = 0., (2, 1) = 655.6456, (2, 2) = .3422578, (3, 1) = 1009.961, (3, 2) = .5331404, (4, 1) = 1253.12, (4, 2) = .6492209, (5, 1) = 1562.724, (5, 2) = .8014143, (6, 1) = 1893.545, (6, 2) = .9329786, (7, 1) = 2201.68, (7, 2) = 1.033593, (8, 1) = 2487.276, (8, 2) = 1.108416, (9, 1) = 2793.943, (9, 2) = 1.157452, (10, 1) = 3122.338, (10, 2) = 1.203911, (11, 1) = 3690.959, (11, 2) = 1.263294, (12, 1) = 4259.141, (12, 2) = 1.307202, (13, 1) = 4827.028, (13, 2) = 1.340795, (14, 1) = 5351.085, (14, 2) = 1.366646, (15, 1) = 5787.775, (15, 2) = 1.387329, (16, 1) = 6224.391, (16, 2) = 1.405433})

  ido := It*sin(theta+delta)

Plot OC saturation with field current in pu

 

with(LinearAlgebra)

with(ArrayTools)

with(plots)

      OC_Sat_Ifld_pu := Column(OC_SatDat, [1])/Ifld__base

         OC_Sat := Concatenate(2, Column(OC_SatDat, [2]), OC_Sat_Ifld_pu) 

````

iterpolate values of field current vs el from OC sat curve

 

                                    pts_el := Column(OC_Sat, [1]); pts_Ifldpu := Column(OC_Sat, [2])

 

 

                         Ifield as a function of el  ->  Ifld := LinearInterpolation(pts_el, pts_Ifldpu)

``

 

Solve for Q with

    

P = .935; Iflc := 1.88; Et := 1.0

 

NULL

TRY1

``

 Eq1 := Ir = P/Et; Eq2 := Ix = Q/Et    Eq3 := It*sqrt(Ir^2+Ix^2)     Eq4:=theta = arctan(Q, P)

``

    Eq5 := el = abs(Et+X__l*(Ix+I*Ir))      Eq6 := `&Psi;AG__d` = Xad__u*Ifld(el)   Eq7:=K__ds = el/`&Psi;AG__d`

     NULL 

NULL Eq8 := Xd__s = K__ds*Xad__u+X__l   Eq9 := `&Psi;AG__q` = Xaq__u*Ifld(el)    Eq10 := K__qs = el/`&Psi;AG__q`

 

   Eq11 := Xq__s = X__l+K__qs(el)*Xaq__u      Eq12 := Eq = Et+Xq__s(el)*(Q/Et+I*P/Et)

NULLNULL

    

Eq13 := delta = argument(Eq)        Eq14 := eqo = Et*cos(delta)    Eq15 := ido = It*sin(theta+delta)

``

Eq16 := EI = Xd__s*Iflec; Eq17 := EI = Ido*Xd__s+eqo

``

 
syst := {E15, Eq1, Eq10, Eq11, Eq12, Eq13, Eq14, Eq16, Eq17, Eq2, Eq3, Eq4, Eq5, Eq6, Eq7, Eq8, Eq9}

 

   

NULL

solve(sys, {Eq, Ir, It, Ix, K__ds, K__qs, Q, Xd__s, Xq__s, el, eqo, ido, theta, `&Psi;AG__d`, `&Psi;AG__q`})

Warning, solving for expressions other than names or functions is not recommended.

 

 

NULL         

TRY 2

              NULL

`` Ix := proc (Q) options operator, arrow; Q/Et end proc   It := proc (Q) options operator, arrow; sqrt(Ir^2+Ix^2) end proc     theta := proc (Q) options operator, arrow; arctan(Q, P) end proc

``

 el := proc (Q) options operator, arrow; abs(Et+X__l*(Ix(Q)+I*Ir)) end proc      `&Psi;AG__d` := proc (Q) options operator, arrow; Xad__u*Ifld(el(Q)) end proc   K__ds := proc (Q) options operator, arrow; el(Q)/`&Psi;AG__d`(el(Q)) end proc``

NULL Xd__s := proc (Q) options operator, arrow; X__l+K__ds(el(Q))*Xad__u end proc   `&Psi;AG__q` := proc (Q) options operator, arrow; Xaq__u*Ifld(el(Q)) end proc    K__qs := proc (Q) options operator, arrow; el(Q)/`&Psi;AG__q`(el(Q)) end proc

Xq__s := proc (Q) options operator, arrow; X__l+K__qs(Q)*Xaq__u end proc      Eq := proc (Q) options operator, arrow; Et+Xq__s(Q)*(Q/Et+I*P/Et) end proc

``

delta := proc (Q) options operator, arrow; argument(Eq(Q)) end proc        eqo := proc (Q) options operator, arrow; Et*cos(delta(Q)) end proc    ido := proc (Q) options operator, arrow; It*sin(theta(Q)+delta(Q)) end proc``

``

EI := proc (Q) options operator, arrow; Xd__s(Q)*Iflec end proc    EI := proc (Q) options operator, arrow; eqo(Q)+Xd__s(Q)*Ido(Q) end proc

``

NULL

solve(EI(Q) = eqo(Q)+Xd__s(Q)*Ido(Q), {Eq, Ir, It, Ix, K__ds, K__qs, Q, Xd__s, Xq__s, el, eqo, ido, theta, `&Psi;AG__d`, `&Psi;AG__q`})

{Eq = Eq, Ir = Ir, It = It, Ix = Ix, K__ds = K__ds, K__qs = K__qs, Q = Q, Xd__s = Xd__s, Xq__s = Xq__s, el = el, eqo = eqo, ido = ido, theta = theta, `&Psi;AG__d` = `&Psi;AG__d`, `&Psi;AG__q` = `&Psi;AG__q`}

(1)

NULL

TRY3

 

     "Eq20:=Ir=P/(Et):     Eq21:=Ix=Q->Q/(Et):"

Error, invalid operator parameter name

"Eq20:=Ir=P/Et: Eq21:=Ix=Q->Q/Et:"

 

``

``

``

``


 

Download Qcalc1.mw

 

I have two functions, f(x) and g(x).

Based the plot, I can see that they intersect around x equals 0, 1, around 4.5 and 10.

So I tried to find the numerical solution by solving f(x) -  g(x) for x assuming x is real.

I'm stuck here because the aswer involves RootOf and _Z and I don't know what to do next.

This is what I've tried so far:
 

``

``

"f(x):=18*log10(x)"

proc (x) options operator, arrow; 18*log10(x) end proc

(1)

"g(x):=1/(2) x^(3)-8*x^(2)+(69/(2))^()*x-27"

proc (x) options operator, arrow; (1/2)*x^3-8*x^2+(69/2)*x-27 end proc

(2)

plot([f(x), g(x)], x = -1 .. 11)

 

``

`assuming`([solve(f(x)-g(x), x)], [x::real])

exp(RootOf(-(exp(_Z))^3*ln(10)+16*(exp(_Z))^2*ln(10)-69*exp(_Z)*ln(10)+54*ln(10)+36*_Z))

(3)

allvalues(exp(RootOf(-(exp(_Z))^3*ln(10)+16*(exp(_Z))^2*ln(10)-69*exp(_Z)*ln(10)+54*ln(10)+36*_Z)))

exp(RootOf(-(exp(_Z))^3*ln(10)+16*(exp(_Z))^2*ln(10)-69*exp(_Z)*ln(10)+54*ln(10)+36*_Z, 1.505446443)), exp(RootOf(-(exp(_Z))^3*ln(10)+16*(exp(_Z))^2*ln(10)-69*exp(_Z)*ln(10)+54*ln(10)+36*_Z, -3.291052648)), exp(RootOf(-(exp(_Z))^3*ln(10)+16*(exp(_Z))^2*ln(10)-69*exp(_Z)*ln(10)+54*ln(10)+36*_Z, 2.302585093)), 1

(4)

``

``


 

Download intersect_curve.mw

 

I know there's an answer to this because I can get the expected answer from Wolfram Alpha (see here).

How can I accomplish this in Maple? 

Hello everyone,

 

I would like to know if it is possible to directly enter LateX expressions into the plot command. My goal is to be able to create a plot where the font style (in for example the title) can switch between LateX math and LateX regular. See the following example.

The LateX input used for the tilte was <Verl{\"a}ufe von $e(t)$ und $\dot{\varepsilon}_\mathrm{p}(t)$>

In Matlab one can use the command <"interpreter","Latex"> which allows direct LateX input. I am basically looking for an equvialent Maple command.


If no such command exists, I would be grateful for any idea on how to create a title like the one above with other methods.

 

Thanks to everyone in advance.

What is your choice for creating a good table?

For example;

 

f:=(x,t)->x*t;
g:=(x,t)->x^2*t;

How to create a table as follows? (Appearance similar to the following is not required. I am open to all options)

Hi, I am doing a project about three body problem. I am solving a DE system with 12 DEs and plotting it with phase portrait. It is all good if I am only using vars in scene. like this:

pp1 := phaseportrait([eq1(t), eq2(t), eq3(t), eq4(t), eq5(t), eq6(t), eq7(t), eq8(t), eq9(t), eq10(t), eq11(t), eq12(t)], [x1(t), y1(t), vx1(t), vy1(t), x2(t), y2(t), vx2(t), vy2(t), x3(t), y3(t), vx3(t), vy3(t)], t = 0 .. 8.75*10^7, [[x1(0) = X1, y1(0) = Y1, vx1(0) = VX1, vy1(0) = VY1, x2(0) = X2, y2(0) = Y2, vx2(0) = VX2, vy2(0) = VY2, x3(0) = X3, y3(0) = Y3, vx3(0) = VX3, vy3(0) = VY3]], scene = [x1(t), y1(t)], stepsize = 1000, x1 = 0 .. 10^6, y1 = 0 .. 6*10^6, color = [red], scaling = constrained):

But I cannot plot any combinations of my variables. I have orthogonalized all the velocity, and I can plot [t,vx(t)] or [t, vy(t)]. But I cannot plot [t, (vx(t)^2+vy(t)^2)^1/2]:

vel1 := phaseportrait([eq1(t), eq2(t), eq3(t), eq4(t), eq5(t), eq6(t), eq7(t), eq8(t), eq9(t), eq10(t), eq11(t), eq12(t)], [x1(t), y1(t), vx1(t), vy1(t), x2(t), y2(t), vx2(t), vy2(t), x3(t), y3(t), vx3(t), vy3(t)], t = 0 .. 3.5*10^7, [[x1(0) = X1, y1(0) = Y1, vx1(0) = VX1, vy1(0) = VY1, x2(0) = X2, y2(0) = Y2, vx2(0) = VX2, vy2(0) = VY2, x3(0) = X3, y3(0) = Y3, vx3(0) = VX3, vy3(0) = VY3]], scene = [t, (vx3(t)^2 + vy3(t)^2)^(1/2)], stepsize = 1000, linecolor = [purple], scaling = constrained);
Error, (in DEtools/phaseportrait) Invalid scene; must be list of vars: scene = [t, (vx3(t)^2+vy3(t)^2)^(1/2)]
 

Is there a way to let me plot the v(t) ?

First 21 22 23 24 25 26 27 Last Page 23 of 1777