acer

32405 Reputation

29 Badges

19 years, 350 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

In the Maple programming language (1D plaintext, also known as Maple Notation) the word for infinity is:

   infinity

That entry box in the popup is a Maplets TextField, and it expects plaintext Maple Notation.

This seems to be a consequence of the result from DiagonalMatrix having shape=diagonal and storage=diagonal.

A workaround is to force off the compact shape/storage (see two ways, below).

I will submit a bug report.

restart

with(LinearAlgebra); alias(`⨂` = LinearAlgebra:-KroneckerProduct); interface(rtablesize = 16); kernelopts(version)

`⨂`

[10, 10]

`Maple 2021.2, X86 64 LINUX, Nov 23 2021, Build ID 1576349`

Matrices nonconformable, Maple should give error message:

`⨂`(Matrix(1, 4, 1), IdentityMatrix(4)); Dimension(%); M := Matrix(4, 4, shape = symmetric, symbol = m); Dimension(%)

Matrix([[1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]])

4, 16

M := Matrix(4, 4, {(1, 1) = m[1, 1], (1, 2) = m[1, 2], (1, 3) = m[1, 3], (1, 4) = m[1, 4], (2, 2) = m[2, 2], (2, 3) = m[2, 3], (2, 4) = m[2, 4], (3, 3) = m[3, 3], (3, 4) = m[3, 4], (4, 4) = m[4, 4]}, storage = triangular[upper], shape = [symmetric])

4, 4

MatrixMatrixMultiply(`⨂`(Matrix(1, 4, 1), IdentityMatrix(4)), DiagonalMatrix(Diagonal(M), shape = []))

Error, (in LinearAlgebra:-Multiply) first matrix column dimension (16) <> second matrix row dimension (4)

NULLMatrixMatrixMultiply(`&bigotimes;`(Matrix(1, 4, 1), IdentityMatrix(4)), DiagonalMatrix(Diagonal(M), storage = rectangular))

Error, (in LinearAlgebra:-Multiply) first matrix column dimension (16) <> second matrix row dimension (4)

`&bigotimes;`(Matrix(1, 4, 1), IdentityMatrix(4)).DiagonalMatrix(Diagonal(M))

Matrix([[m[1, 1], 0, 0, 0], [0, m[2, 2], 0, 0], [0, 0, m[3, 3], 0], [0, 0, 0, m[4, 4]]])

Download Starnge_ac.mw

Is you lprint the SearchSet you can see that its float values are not what appears in the 2D Input.

I don't know how you managed to get that effect (cut&paste, something with numeric formatting?).

You could re-enter it manually.

But you may still be faced by discrepencies if you expect floats to be matched in the case that they have differing numbers of trailing zeroes.

It might be better if you described precisely what kind of matching you are after, ie. float comparisons to a fixed precision, etc. It may be that verify it a more suitable tool for the comparison, but that depends on what comparison you are after.

Also, you asked about why some sorting occurs. That's how Maple acts with sets of floats. If you don't want them sorted then you could use lists of Vectors instead.

restart; with(ListTools)

Pent := [Vector(3, {(1) = 2.0646, (2) = -1.5000, (3) = 3.3405}), Vector(3, {(1) = -.78860, (2) = -2.4271, (3) = 3.3405}), Vector(3, {(1) = -2.5520, (2) = 0.8100500000e-10, (3) = 3.3405}), Vector(3, {(1) = -.78860, (2) = 2.4271, (3) = 3.3405}), Vector(3, {(1) = 2.0646, (2) = 1.5000, (3) = 3.3405})]

[Vector[column](%id = 36893628814707266132), Vector[column](%id = 36893628814707266252), Vector[column](%id = 36893628814707266372), Vector[column](%id = 36893628814707266492), Vector[column](%id = 36893628814707266612)]

PentSet := ([seq])(convert(Pent[i], set), i = 1 .. 5)

[{-1.5000, 2.0646, 3.3405}, {-2.4271, -.78860, 3.3405}, {-2.5520, 0.8100500000e-10, 3.3405}, {-.78860, 2.4271, 3.3405}, {1.5000, 2.0646, 3.3405}]

PentSetSort := ([seq])(sort(PentSet[i]), i = 1 .. 5)

[{-1.5000, 2.0646, 3.3405}, {-2.4271, -.78860, 3.3405}, {-2.5520, 0.8100500000e-10, 3.3405}, {-.78860, 2.4271, 3.3405}, {1.5000, 2.0646, 3.3405}]

SearchSet := {-2.427050982, -.7885966699, 3.340549093}; BinarySearch(PentSetSort, SearchSet, `subset`); BinarySearch([{-1.500000000, 2.064572880, 3.340549093}, {-2.427050982, -.7885966699, 3.340549093}, {-2.551952424, 3.340549093, 8.100498050*10^(-11)}, {-.7885966673, 2.427050983, 3.340549093}, {1.500000001, 2.064572880, 3.340549093}], {-2.427050982, -.7885966699, 3.340549093}, `subset`)

0

2

lprint(SearchSet)

{-2.427050982, -.7885966699, 3.340549093}

SearchSet := {-2.4271, -.7886, 3.3405}

{-2.4271, -.7886, 3.3405}

BinarySearch(PentSetSort, SearchSet, `subset`)

0

SearchSet := {-2.4271, -.78860, 3.3405}

{-2.4271, -.78860, 3.3405}

BinarySearch(PentSetSort, SearchSet, `subset`)

2

lprint(PentSetSort)

[{-1.5000, 2.0646, 3.3405}, {-2.4271, -.78860, 3.3405}, {-2.5520, .8100500000e-\
10, 3.3405}, {-.78860, 2.4271, 3.3405}, {1.5000, 2.0646, 3.3405}]

([seq])(convert(Pent[i], set), i = 1 .. 5)

[{-1.5000, 2.0646, 3.3405}, {-2.4271, -.78860, 3.3405}, {-2.5520, 0.8100500000e-10, 3.3405}, {-.78860, 2.4271, 3.3405}, {1.5000, 2.0646, 3.3405}]

([seq])(convert(Pent[i], list), i = 1 .. 5)

[[2.0646, -1.5000, 3.3405], [-.78860, -2.4271, 3.3405], [-2.5520, 0.8100500000e-10, 3.3405], [-.78860, 2.4271, 3.3405], [2.0646, 1.5000, 3.3405]]

 

Download Binary_search_ac.mw

An explicitl description of what you're actually trying to accomplish would be a good start to getting best advice.

It would be more helpful and direct if you were to supply the complete example when first submitting the Question.

Hopefully this uses the dsolve solution to produce your line animation in a satisfactory manner.

restart

q1 := 5b1 := 18l1 := 16r1 := .35ms := 626g1 := -9.807
u0 := -19.4

v0 := -17.7x0 := 0z0 := 15xa := 0za := z0+1mu1 := .35omega0 := -24

mn := b1*g1*q1*za+g1*mpfz := mn/zaJs := (2/5)*ms*r1^2

"Lp(t):=sqrt((xn(t)-xa)^(2)+(zn(t)-za)^(2)) :"

"Lr(t):=piecewise((za-Lp(t))>0,za-Lp(t),0) :"

"A1(t):=piecewise((xa-xn(t))>0,xa-xn(t),0) :"

"sinalpha1(t):=piecewise((xa-xn(t))>0,(xa-xn(t))/(Lp(t)),0) :"

"cosalpha1(t):=piecewise((xa-xn(t))>0,((za-zn(t)))/(Lp(t)),1) :"

"alpha2(t):=arccos(cosalpha1(t))+phi(t) :"

``

"S1(t):=piecewise(zn(t)>=0 and xn(t)<=xa,fz*Lr(t),0):"

"S1z(t):=S1(t)*cos(phi(t)):"

"S1x(t):=S1(t)*sin(-phi(t)):"

"S2(t):=piecewise(xn(t)<=xa and zn(t)>0, (-1) S1(t)*exp(mu1*alpha2(t)),0):"

"S2x(t):=S2(t)*sinalpha1(t):"

"S2z(t):=S2(t)*cosalpha1(t):"

"Sx(t):=S2x(t)+S1x(t):"

"Sz(t):=S1z(t)+S2z(t)+ms*g1:"

shape_factor := 0

"Fr(t):=S2(t)+S1(t)+shape_factor:"

NULL

"m(t):=Lr(t)q1*b1:"

mp := 300

"Jp(t):=1/(3)*m(t)*Lr(t)^(2)+mp*Lr(t)^(2) :"

"M(t):=g1*m(t)*(Lr(t))/(2)*sin(phi(t))+g1*mp*sin(phi(t)):"

k := 800*ms

NULL

"Es(t):=(ms*g1*(z0-zn(t)))+1/(2)*ms*(vn(t)^(2)+un(t)^(2))+1/(2)*Js*omega(t)^(2):"

"En(t):=(1)/(2)*Jp(t)*((&DifferentialD;)/(&DifferentialD; t)phi(t))^(2)+-(m(t)+mp)*g1*(Lr(t)-cos(phi(t))*Lr(t)):"

eqx1 := ms*(diff(u(t), t)) = 0.; eqz1 := ms*(diff(v(t), t)) = ms*g1

eqx0 := diff(x(t), t) = u(t); eqz0 := diff(z(t), t) = v(t)

``

eqx1n := ms*(diff(un(t), t)) = Sx(t); eqz1n := ms*(diff(vn(t), t)) = ms*g1+S1z(t)+S2z(t)

eqx0n := diff(xn(t), t) = un(t); eqz0n := diff(zn(t), t) = vn(t)

eqr1 := Js*(diff(omega(t), t)) = (S2(t)+S1(t)+shape_factor)*r1

``

u0n := u0*ms/(ms+(1/3)*m(t)+mp)

NULL

u0n1 := u0*ms/(ms+mn)

phid00 := u0n1/(l1-z0)

phid0 := .7*eval[recurse](-u0n(t)/(l1-z0), [t = 0, xn(0) = x0, zn(0) = z0])

simplify(phid0)

"znb(t):=(Lr(t)-(sin((Pi)/(2)- phi(t))*Lr(t))):"

"xnb(t):=Lr(t)*cos(Pi/(2)-phi(t)):"

eqp := (diff(phi(t), t, t))*Jp(t) = M(t)-k*(diff(phi(t), t))

with(plots)

ini := x(0) = x0, u(0) = u0, z(0) = z0, v(0) = v0, xn(0) = x0, un(0) = u0, zn(0) = z0, vn(0) = v0, omega(0) = omega0, phi(0) = 0, (D(phi))(0) = phid0

sol1 := dsolve({eqp, eqr1, eqx0, eqx0n, eqx1, eqx1n, eqz0, eqz0n, eqz1, eqz1n, ini}, {omega(t), phi(t), u(t), un(t), v(t), vn(t), x(t), xn(t), z(t), zn(t)}, type = numeric, output = listprocedure)

XNB := unapply(subs(xn = XN, zn = ZN, phi = PHI, xnb(t)), t)

ZNB := unapply(subs(xn = XN, zn = ZN, phi = PHI, znb(t)), t)

XN := eval(xn(t), sol1)

ZN := eval(zn(t), sol1)

PHI := eval(phi(t), sol1)

NULL

NULL

NULL

NULL

plots:-animate(plots:-display, [plottools:-line([xa, za], [XN(t), ZN(t)], color = red, thickness = 3), plottools:-line([XN(t), ZN(t)], [XNB(t), ZNB(t)], color = blue, thickness = 3), plot([[XN(t), ZN(t)]], style = point, symbol = solidcircle, symbolsize = 15, color = red), plot([[XNB(t), ZNB(t)]], style = point, symbol = solidcircle, symbolsize = 15, color = blue)], t = 0 .. .7, background = plots:-pointplot([[xa, za]], symbol = solidcircle, symbolsize = 15, color = green))

 

Download anim_ac.mw

You have b assigned as a Matrix. That's your basic mistake, since you were only indexing into it as b[i], as if it had just one dimension.

Try making it b as a Vector instead, ie,

   b := Vector(3, [-1, 7, -7]);

Below, I have removed also the loading of the VectorCalculus package since that rebinds the Vector command which is hardly useful here. I changed the call of Norm to be explicitly a call to LinearAlgebra:-Norm.

I suggest that you check that it works as you intended.

restart

with(plots):

``

SOR := proc (n, A, b, x, w, max_iter, tol) local i, j, k, xGS, err, x1; err := 1; while tol < err do x1 := x; for k to max_iter do for i to n do xGS := (b[i]-add(Typesetting:-delayDotProduct(A[i, j], x[j]), j = 1 .. i-1)-add(Typesetting:-delayDotProduct(A[i, j], x[j]), j = i+1 .. n))/A[i, i]; x[i] := (1-w)*x[i]+w*xGS end do end do; err := LinearAlgebra:-Norm(x-x1); x1 := x end do end proc:

``

A := Matrix(3, 3, [[3, -1, 1], [-1, 3, -1], [1, -1, 3]])

A := Matrix(3, 3, {(1, 1) = 3, (1, 2) = -1, (1, 3) = 1, (2, 1) = -1, (2, 2) = 3, (2, 3) = -1, (3, 1) = 1, (3, 2) = -1, (3, 3) = 3})

(1)

b := Vector(3, [-1, 7, -7]); x := `<,>`(1, 1, 1); x := convert(x, Vector)

b := Vector(3, {(1) = -1, (2) = 7, (3) = -7})

 

x := Vector(3, {(1) = 1, (2) = 1, (3) = 1})

(2)

n := 3;

3

 

.9

 

7

 

0.1e-3

(3)

ans := SOR(3, A, b, x, .9, 15, 0.1e-3)

ans := Vector(3, {(1) = .9999999896, (2) = 1.999999980, (3) = -2.000000006})

(4)

A.ans-b

Vector(3, {(1) = -0.1719999987e-7, (2) = -0.4360000005e-7, (3) = -0.8399999807e-8})

(5)

NULL

Download code_zeineb_ac.mw

It is not necessary to write M:-Pn instead of just Pn (for each n), in the situation you describe.

In my experience is far more common to write the references as just Pn in equivalent situations.

You wrote that using the form M:-Pn somestimes "...saved me a lot of trouble". What trouble was that?

If you store them properly (in a .mla Maple Library Archive file) then you wouldn't need to read any of them in each session you want to access them, and they could all get seen as easily as each other.

To access any of them you'd simply need libname to be augmented with the location of the new personal .mla Library file.

- You could augment libname in a worksheet's Startup code, which would affect just that worksheet.
- Or you could augment libname in a personal initialization file.
- Alternatively you could put the .mla Library file under a new folder with a name like whatever the following returns, and have Maple automatically augment libname upon relaunch:
    cat(kernelopts(':-homedir'),"/maple/toolbox/mypackage/lib")

Personally, I think that reading in the plaintext source files each time you want to run a session or worksheet is an unnecessary, overly complicated burden.

But if for some strange reason I was unable to use an .mla file, then I'd probably just create a single .mpl text file that contained the means to input all the individual procedures. That could contain various (say, five) read calls for each of the individual source files, or it could contain the definition of a package module that accessed the individual sources with, say, the $include directive. In this scenario I could subsequently issue one read call of that master (build) file, and all would be avaliable.

[edit] There is an example of writing a module using the $include directive (and the preprocessor) for its member procedures in Section 11.4 of the Programming Guide.

You may well be satisfied with the right-click context-menu approach.

By the way, there is a Help page for that (it takes a little while to fully load and focus on the approriate section in my webbrowser).

Using the result in the left-hand side of an assignment requires mouse actions to copy&paste, so using the mouse to convert to Atomic Variable may be fine.

If you're interested, your expression can also be converted programmatically:

restart;

kernelopts(version);

`Maple 2022.1, X86 64 LINUX, May 26 2022, Build ID 1619613`

 

`convert/identifier`:=proc(x)
   cat(`#`,convert(:-Typesetting:-Typeset(x),
                   ':-compose',`global`,name));
end proc:

 

 

expr := abs(A[0])^2;

abs(A[0])^2

convert(expr, identifier);

`#msup(mfenced(msub(mi("A"),mn("0")),open = "&verbar;",close = "&verbar;",msemantics = "abs"),mn("2"))`

lprint(%);

`#msup(mfenced(msub(mi("A"),mn("0")),open = "&verbar;",close = "&verbar;",msema\
ntics = "abs"),mn("2"))`

 

I'll use the right-click context menu conversion (explained by Robert)
on the next 2D Input

 

`#msup(mrow(mo("&verbar;"),msub(mi("A"),mn("0")),mo("&verbar;")),mn("2"))`

`#msup(mrow(mo("&verbar;"),msub(mi("A"),mn("0")),mo("&verbar;")),mn("2"))`

lprint(%);

`#msup(mrow(mo("&verbar;"),msub(mi("A"),mn("0")),mo("&verbar;")),mn("2"))`

 

Both of these results are Maple names, to which you can assign values.

 

You should be able to copy&paste their pretty-printed output and use
that as the left-hand side of an assignment.

 

Download atomicvar_constr.mw

ps. In versions before Maple 2017 an Atomic Variable was called an Atomic Identifier.

Try

   ':-b' = b

using single right-ticks (a.k.a. uneval quotes).

The LHS of that equation is an unevaluated reference to the global name b (and not the procedure test1's parameter by a similar name). The RHS evaluates to the value you want to pass along.

test1:=proc(a::posint, {b::posint:=1})::posint:
	return a + b:
end proc:

test2:=proc(a::posint, {b::posint:=1} )::posint:
	return a*test1(a, ':-b' = b);
end proc:

test2(2, b=3);
             10

[edit] I much prefer this approach over using _options['b'], which Joe has suggested.

I would not use remove(has, ..., unit) since that would act quite differently on expressions other than a product. (Your expression assigned to a is of type `*`, but it's unclear that is all you want to be able to handle robustly.)

I would suggest these preliminary steps be part of the process:
1) combine addends into common units
2) optionally convert to a preferred unit (or accept the base unit for the current system, default=SI)
3) use convert(...,unit_free) to strip off the remaning units, as suitable

For example, quoting unprotected global versions of option names for robustness,

restart;

kernelopts(version);

`Maple 2015.2, X86 64 LINUX, Dec 20 2015, Build ID 1097895`

a := 3*Unit(m);

3*Units:-Unit('m')

convert(combine(a, ':-units'), ':-unit_free');

3

b := 7*Unit(mm)+3*Unit(m);

7*Units:-Unit('mm')+3*Units:-Unit('m')

convert(combine(b, ':-units'), ':-unit_free');

3007/1000

Download remove_units.mw

Maple was originally designed for efficient symbolic computation, as opposed to pretty mathematical typesetting.

A key aspect of that original design was the storing in a session (by the Maple engine, a.k.a. "kernel") of only one representation of any sum or product of terms (commuting under usual addition and multiplication). Any other input of an equivalent form of an expression -- with terms commuted -- gets uniquified to the stored form.

Hence, if the form
   -b + a
is first formed in a session then construction/entry of the alternate form,
  a - b
gets automatically recognized as the earlier, stored form.

However, for this kind of expression the terms can be reordered by the sort command. For example,

restart;

expr := -b + a;

-b+a

The order in which I type the entries does not matter.
What matters is that the originally existing form -b+a
is already stored in Maple's internal memory (ie. in its
unquification table of expressions).

a - b;

-b+a

It is possible to resort the items in this sum, forcing a
particular ordering of names. This causes the stored
(uniquified) expression to be replaced in internal memory.

sort(expr, order=plex(a,b));

a-b

a - b;

a-b

-b + a;

a-b

restart;


We can also go the other way...

alt := a - b;

a-b

-b + a;

a-b

sort(alt, order=plex(b,a));

-b+a

-b + a;

-b+a

a - b;

-b+a

Download simpl_examp.mw

As far as mathematical typesetting goes, one could also display the expression (in marked up "2D" math), without the above issues interfering. Here I use so-called inert operators, so avoid those uniquification issues,

restart;

-b + a;

-b+a

a - b;

-b+a

Here I use prefix syntax for the inert operator,

foo := `%+`(a, -b);

`%+`(a, -b)

InertForm:-Display(foo);

0, "%1 is not a command in the %2 package", _Hold, Typesetting

I can also use this infix syntax,

bar := a %+ (-b);

`%+`(a, -b)

InertForm:-Display(bar);

0, "%1 is not a command in the %2 package", _Hold, Typesetting

Download inert_add_ex.mw

If you have other, particular usage scenarios then you should describe them precisely, as a best bet on getting adequate assistance.

You asked about plotting the elements of a sequence, so I'll address that aspect.

You can use the plot command to show a discrete collection of x-y points.

The data can be formed in a list of lists, or a Matrix. (I'll do it as a list of lists, below.)

You can adjust other qualities, such as the symbol, the style, the color, etc. See the Help page plot,coptions for more details.

restart;

L := [seq([n,(-2)^n], n=-2..2)];

[[-2, 1/4], [-1, -1/2], [0, 1], [1, -2], [2, 4]]

plot(L, style=point, symbolsize=15,
        symbol=solidcircle, color=red);

plot(L, style=pointline, symbolsize=15,
        symbol=solidcircle, color=red);

Download point_plot_ex.mw

The plot shows that the local maximum is the global maximum over that range t=0..2.

So you can use the Optimization:-Maximize command.

In my opinion this is more straightforward, flexible, and likely more accurate in general than either examining the discrete data points from a plot structure, or using an interpolated spline.

I use the output=listprocedure option for dsolve, as a convenient way to get at procedures for xn(t) and zn(t), similarly to what I showed in your previous Question.

restart

q1 := 3b1 := 20l1 := 22r1 := .5m1 := 900g1 := -11
u0 := -10

v0 := -10x0 := 0z0 := 20xa := 0za := z0+5mu1 := .1omega0 := -24

mn := q1*g1*b1*za

fz := mn/za

TM1 := (2/5)*m1*r1^2

``

"Lp(t):=sqrt((xn(t)-xa)^(2)+(zn(t)-za)^(2)) :"

"Lr(t):=piecewise(sqrt(zn(t)^(2)+A1(t)^(2))>0,sqrt(zn(t)^(2)+A1(t)^(2)),0)  :"

"A1(t):=piecewise((xa-xn(t))>0,xa-xn(t),0):"

"sinalpha1(t):=piecewise((xa-xn(t))>0,(xa-xn(t))/(Lp(t)),0) :"

"cosalpha1(t):=piecewise((xa-xn(t))>0,((za-zn(t)))/(Lp(t)),1) :"

"alpha2(t):=arccos(cosalpha1(t))+phi(t) :"

NULL

"S1(t):=piecewise(zn(t)>=0 and xn(t)<=xa,fz*Lr(t),0):"

"S1z(t):=S1(t)*cos(phi(t)):"

"S1x(t):=S1(t)*sin(-phi(t)):"

"S2(t):=piecewise(xn(t)<=xa and zn(t)>0, (-1) S1(t)*exp(mu1*alpha2(t)),0) :"

"S2x(t):=S2(t)*sinalpha1(t):"

"S2z(t):=S2(t)*cosalpha1(t) :"

"Sx(t):=S2x(t)+S1x(t) :"

"Sz(t):=S1z(t)+S2z(t)+m1*g1:"

shape_factor := 10

"Fr(t):=S2(t)+S1(t)+shape_factor:"

NULL

NULL

"m(t):=Lr(t)q1*b1:"

NULL

"J(t):=1/(3)*m(t)*Lr(t)^(2) :"

"M(t):=g1*m(t)*(Lr(t))/(2)*sin(phi(t)) :"

k := 50*m1

NULL

NULL

``

eqx1 := m1*(diff(u(t), t)) = 0.; eqz1 := m1*(diff(v(t), t)) = m1*g1

900*(diff(u(t), t)) = 0.

900*(diff(v(t), t)) = -9900

eqx0 := diff(x(t), t) = u(t); eqz0 := diff(z(t), t) = v(t)

``

eqx1n := m1*(diff(un(t), t)) = Sx(t); eqz1n := m1*(diff(vn(t), t)) = m1*g1+S1z(t)+S2z(t)

eqx0n := diff(xn(t), t) = un(t); eqz0n := diff(zn(t), t) = vn(t)

eqr1 := TM1*(diff(omega(t), t)) = (S2(t)+S1(t)+shape_factor)*r1

NULL

u0n := u0*m1/(m1+mn)

15/26

NULL

phid0 := 2*u0n(t)/(l1-z0)

15/26

NULL

eqp := (diff(phi(t), t, t))*J(t) = M(t)-k*(diff(phi(t), t))

with(plots)

NULL

NULL

ini := x(0) = x0, u(0) = u0, z(0) = z0, v(0) = v0, xn(0) = x0, un(0) = u0, zn(0) = z0, vn(0) = v0, omega(0) = omega0, phi(0) = 0, (D(phi))(0) = phid0

sol1 := dsolve({eqp, eqr1, eqx0, eqx0n, eqx1, eqx1n, eqz0, eqz0n, eqz1, eqz1n, ini}, {omega(t), phi(t), u(t), un(t), v(t), vn(t), x(t), xn(t), z(t), zn(t)}, type = numeric, output = listprocedure)

odeplot(sol1, [t, 180*arccos(cosalpha1(t))/Pi], 0 .. 2, legend = ["alpha"], linestyle = [dashdot, solid], size = [300, 300])

temp := unapply(subs(xn = Xn, zn = Zn, cosalpha1(t)), t)

proc (t) options operator, arrow; piecewise(0 < -Xn(t), (25-Zn(t))/(Xn(t)^2+(Zn(t)-25)^2)^(1/2), 1) end proc

Xn := eval(xn(t), sol1)

Zn := eval(zn(t), sol1)

plot([t, 180*arccos(temp(t))/Pi, t = 0 .. 2], legend = ["alpha"], linestyle = [dashdot, solid], size = [300, 300])

Optimization:-Maximize(180*arccos(temp(t))/Pi, t = 0 .. 2)

[HFloat(22.00633969122702), [t = HFloat(0.6180259177597804)]]

 

Download evalv_max_ac.mw

There's nothing intrinsically wrong with returning NULL as an explicit statement. This is a common programming technique in Maple.

   return NULL;

One alternative is to have a statement that does nothing and happens to also return NULL, but that would be obfuscation for no benefit. The explicit return call is clear and understandable programming.

ps. Using assign brings the burden of having to remember that happens to return NULL. Since you didn't already think of that then using it would entail one more thing for you to remember. You already know what explicitly returning NULL means, and it's more likely that others reading your code would too.

Without a range supplied fsolve is trying to find roots from A=-infinity to A=infinity. That search is missing values very close to zero.

[edit] The situation is made more difficult due to the root lying close to a singularity, where it is steep, and with the expression nonreal on its other side.

restart:

N := 60: L := 10: a := 2*10^(-12):

eqn:=ns=1-((((N/A)+((A*L)^(L/(1-L))))^((1-L)/L))/(A*L))*(2+(a*exp((((N/A)+((A*L)^(L/(1-L)))))^(1/L)))/((A*L*(((N/A)+((A*L)^(L/(1-L))))^((L-1)/L)))+((a*exp((((N/A)+((A*L)^(L/(1-L)))))^(1/L)))))):

seq(fsolve(eqn,A=0..1e-6),ns=[0.9603,0.9647,0.9691]);

0.9300682773e-9, 0.3054144319e-8, 0.1172662805e-7

Download A_ac.mw

First 60 61 62 63 64 65 66 Last Page 62 of 336