Rouben Rostamian

MaplePrimes Activity


These are answers submitted by Rouben Rostamian

Here I do Exercise #7.  You do the rest.

restart;

with(LinearAlgebra):

with(DEtools):

A := < -1, 1; 0, -1>;

Matrix(2, 2, {(1, 1) = -1, (1, 2) = 1, (2, 1) = 0, (2, 2) = -1})

det := Determinant(A);    # the determinant
tra := Trace(A);          # the trace
dsc := tra^2 - 4*det;     # the discriminant (Delta)
Eigenvalues(A);           # the eigenvalues

det := 1

tra := -2

dsc := 0

Vector[column](%id = 36893613368677088300)

We see that the discriminant is zero, A is not diagonal, eigenvalues are negative.

Referring to the table shown in your question, we see that the equilibrium at (0,0)

is a Stable Improper Node.  Here is how we sketch it.

diff(<x(t),y(t)>, t) =~ A . <x(t),y(t)>;
sys := {seq}(%);

Vector(2, {(1) = diff(x(t), t) = -x(t)+y(t), (2) = diff(y(t), t) = -y(t)})

{diff(x(t), t) = -x(t)+y(t), diff(y(t), t) = -y(t)}

ic := [x(0)=1,y(0)=1], [x(0)=-1,y(0)=1], [x(0)=1,y(0)=-1], [x(0)=-1,y(0)=-1];

[x(0) = 1, y(0) = 1], [x(0) = -1, y(0) = 1], [x(0) = 1, y(0) = -1], [x(0) = -1, y(0) = -1]

DEplot(sys, [x(t),y(t)], t=0..8, [ic], axes=normal, tickmarks=[0,0], labels=["",""], dirfield=[10,10], arrows=comet, color="DarkCyan");

Download mw.mw

 

 

 

This is a linear system, therefore (0,0) is an equilibrium point.

To plot a phase portrait, do:

DEplot(sys, [x(t),y(t)], t=0..1, x=-4..4, y=-4..4, arrows=comet, color="DarkCyan",
    dirfield=[15,15], size=[800,600], axes=boxed);

I much prefer quaternions over Euler angles for expressing rotation of rigid bodies.  Euler angles work well when the rigid body's orientation is limited to rather narrow range (think of a spinning top).  Quaternions work well when a rigid body has the possibility of turning in every which way (think of a satellite in space).

Stylistically, each of the three Euler angles  serves a different purpose.  In contrast, the components of a quaternion participate symmetrically in the equations of dynamics, resulting in a more pleasant treatment.

That said, Euler angles tend to result in a more compact form of the differential equations of motion.  These are preferable for "calculations by hand".  The differential equations of motion obtained via quaternions are generally more complex, and are better suited for numerical calculations on a computer.

Here is a mini-lession on quaternion algebra

A quaternion is a pair [a, u], where a is a scalar and u is a 3D vector.  The algebra of quaternions prescribes the algebraic properties of such a pair.  Thus, the sum of the quaternions [a,u] and [b,v] is defined in the expected way as [a+b, u+v].  The scalar product  of a number c and a quaternion [a,u] is [ca, cu].

The interesting new concepts are those of the conjugate [a,u]* of a quaternion and the product [a,u] o [b,v] of two quaternions, defined as

[a, u]* = [a, -u]
[a, u] o [b,v] = [ab - u.v, av + bu + uxv]

where u.v and uxv are the dot product and the cross product of the vectors u and v.  Note that the quaternion product is not commutative because uxv = - vxu.

That's pretty much all of the quaternion algebra needed for expressing rotations in 3D.

To see that, let n be an arbitrary unit vector in 3D and phi an arbitrary angle.  Define the rotation quaternion

q = [ cos(phi/2), n sin(phi/2)]

Let P be an arbitrary point P in space and let r be its position vector, that is, the vector that stretches from the origin to P.  Then form the quaternion product

[a,v] = q o [0,r] o q*

Expanding the product according to the quaternion rules laid out above, we find that a = 0, that is

[0,v] = q o [0,r] o q*

Furthermore, an elementary geometric analysis shows that  the vector v is the result of rotating the vector r about the vector n by the angle phi.

Thus, to rotate a rigid body about a vector n by angle phi, apply the formula obtained above to all of its points. That expresses the rigid body's rotation in a natural way; there are no Euler angles!

End of the lesson

To connect this to what you have shown in your post, MapleSim expresses the rotation quaternion q as a list of four numbers, q0 for the scalar part, and q1, q2, q3 for the components of the vector part.  Since n is a unit vector in the rotation quaternion, we have q0^2 + q1^2 + q2^2 + q3^2 = 1.  That's the "algebraic constraint" seen in MapleSim's message.  There is some confusion there about the rest of the message.  There are 7 (not 8) generalized coordinates, x, y, z, q0, q1, q2, q3.  The duplicate q0 at the end of the vector vQ should not be there, unless MapleSim has some good reason for expressing vQ that way.

 

I can only guess what you are asking.  Consider formulating the question in your native language and having Google Translate change it to English.

Here is my best attempt to make something meaningful from what you have written.

The function f given in your post has infinitely many roots.  The roots are grouped in clusters.  You wish to find the first cluster which contains 50 or more roots.

It turns out that the first cluster contains 122 roots, so it meets your requirement.

To see that, we change the variable from x to s by setting x^3 = s that is, x = s^(1/3).  Then the roots (in s) within each cluster will be more or less uniformly distributed, making it easier for fsolve() to find them.  Here are the details.

restart;

f := x -> 0.995-cos(0.25*x)*sin(x^3);

proc (x) options operator, arrow; .995-cos(.25*x)*sin(x^3) end proc

Change from x to s through x^3 = s:

g := 0.995-cos(0.25*surd(s,3))*sin(s);

.995-cos(.25*surd(s, 3))*sin(s)

Here is what the graph of g looks like:

plot(g(s), s=0..2.4e3);

The envelope visible in the diagram is the graph of the function cos(0.25*surd(s,3)):

plot(cos(0.25*surd(s,3)), s=0..2.6e3);

The roots of g occur where the latter graph drops below the -0.995 level.  Let's see where that happens:

fsolve(cos(0.25*surd(s,3)) = -0.995, s=1000..2500, maxsols=4);

1800.799068, 2180.078129

This says that the first root cluster occurs in the interval 1800 < s < 2181.
Since the sin(s) factor oscillates with a period of 2*Pi, we can expect approximately
( 2181 - 1800)/Pi roots in that interval.  That value is

( 2181 - 1800) / (1.0*Pi);

121.2760666

Let's check:

s_roots := [fsolve(g(s), s=1800..2181, maxsols=130)];

[1801.693347, 1801.713539, 1807.958436, 1808.014816, 1814.231592, 1814.308027, 1820.507168, 1820.598817, 1826.784092, 1826.888260, 1833.061919, 1833.176800, 1839.340413, 1839.464672, 1845.619431, 1845.752020, 1851.898879, 1852.038939, 1858.178689, 1858.325496, 1864.458811, 1864.611739, 1870.739210, 1870.897708, 1877.019854, 1877.183430, 1883.300722, 1883.468929, 1889.581793, 1889.754224, 1895.863053, 1896.039332, 1902.144487, 1902.324264, 1908.426086, 1908.609032, 1914.707840, 1914.893645, 1920.989740, 1921.178111, 1927.271781, 1927.462438, 1933.553956, 1933.746630, 1939.836260, 1940.030693, 1946.118689, 1946.314631, 1952.401239, 1952.598447, 1958.683908, 1958.882146, 1964.966692, 1965.165729, 1971.249590, 1971.449198, 1977.532599, 1977.732555, 1983.815720, 1984.015802, 1990.098949, 1990.298940, 1996.382288, 1996.581968, 2002.665736, 2002.864887, 2008.949293, 2009.147698, 2015.232959, 2015.430398, 2021.516737, 2021.712988, 2027.800626, 2027.995466, 2034.084629, 2034.277830, 2040.368748, 2040.560079, 2046.652986, 2046.842208, 2052.937347, 2053.124215, 2059.221833, 2059.406096, 2065.506451, 2065.687845, 2071.791206, 2071.969458, 2078.076104, 2078.250927, 2084.361154, 2084.532244, 2090.646365, 2090.813401, 2096.931748, 2097.094385, 2103.217318, 2103.375183, 2109.503091, 2109.655778, 2115.789087, 2115.936149, 2122.075333, 2122.216270, 2128.361863, 2128.496108, 2134.648720, 2134.775619, 2140.935964, 2141.054742, 2147.223680, 2147.333393, 2153.511997, 2153.611444, 2159.801124, 2159.888685, 2166.091451, 2166.164725, 2172.383903, 2172.438641, 2178.682741, 2178.706170]

nops(s_roots);

122

That agrees with our estimate.  The roots of f(x) are the cube roots of these roots:

x_roots := surd~(s_roots, 3);

[12.16821734, 12.16826280, 12.18230534, 12.18243197, 12.19637891, 12.19655019, 12.21042549, 12.21063039, 12.22444283, 12.22467518, 12.23843010, 12.23868576, 12.25238696, 12.25266286, 12.26631325, 12.26660698, 12.28020894, 12.28051852, 12.29407406, 12.29439782, 12.30790866, 12.30824516, 12.32171283, 12.32206081, 12.33548668, 12.33584501, 12.34923033, 12.34959798, 12.36294390, 12.36331994, 12.37662752, 12.37701111, 12.39028134, 12.39067167, 12.40390548, 12.40430182, 12.41750009, 12.41790175, 12.43106532, 12.43147163, 12.44460131, 12.44501166, 12.45810820, 12.45852200, 12.47158615, 12.47200282, 12.48503530, 12.48545429, 12.49845579, 12.49887659, 12.51184777, 12.51226986, 12.52521139, 12.52563428, 12.53854680, 12.53897000, 12.55185414, 12.55227718, 12.56513356, 12.56555597, 12.57838519, 12.57880652, 12.59160919, 12.59202899, 12.60480571, 12.60522351, 12.61797488, 12.61839025, 12.63111684, 12.63152933, 12.64423175, 12.64464091, 12.65731974, 12.65772511, 12.67038095, 12.67078209, 12.68341553, 12.68381197, 12.69642362, 12.69681489, 12.70940537, 12.70979098, 12.72236091, 12.72274037, 12.73529038, 12.73566318, 12.74819394, 12.74855954, 12.76107172, 12.76142956, 12.77392387, 12.77427337, 12.78675054, 12.78709107, 12.79955188, 12.79988278, 12.81232804, 12.81264860, 12.82507919, 12.82538861, 12.83780548, 12.83810291, 12.85050709, 12.85079158, 12.86318422, 12.86345466, 12.87583707, 12.87609221, 12.88846587, 12.88870422, 12.90107092, 12.90129064, 12.91365259, 12.91385136, 12.92621140, 12.92638608, 12.93874825, 12.93889414, 12.95126507, 12.95137385, 12.96377041, 12.96381688]

Here are the residuals.  For greater accuracy, set Digits to something greater than 10.

f~(x_roots);

[0.87e-8, -0.20e-8, 0.546e-7, -0.688e-7, 0.212e-7, -0.456e-7, -0.418e-7, 0.884e-7, -0.1183e-6, 0.594e-7, -0.274e-7, -0.294e-7, -0.752e-7, 0.158e-7, 0.130e-7, 0.94e-8, 0.1221e-6, -0.600e-7, -0.325e-7, 0.263e-7, -0.464e-7, 0.439e-7, 0.613e-7, 0.1038e-6, 0.1970e-6, 0.1855e-6, 0.764e-7, 0.893e-7, 0.216e-7, -0.2005e-6, 0.1556e-6, 0.372e-7, -0.1430e-6, 0.241e-7, -0.754e-7, 0.199e-7, 0.703e-7, 0.1814e-6, -0.733e-7, -0.1366e-6, -0.1173e-6, 0.1139e-6, 0.551e-7, 0.1999e-6, -0.349e-7, 0.1162e-6, -0.2262e-6, -0.713e-7, -0.1909e-6, 0.1621e-6, -0.324e-7, -0.1744e-6, 0.930e-7, -0.1534e-6, 0.724e-7, -0.1816e-6, -0.651e-7, -0.291e-7, -0.2492e-6, -0.249e-7, 0.1284e-6, -0.1600e-6, 0.2146e-6, 0.1103e-6, -0.1058e-6, -0.2276e-6, -0.2148e-6, 0.401e-7, 0.405e-7, -0.232e-7, -0.1335e-6, 0.1712e-6, -0.2065e-6, -0.2210e-6, -0.58e-8, -0.474e-7, 0.1054e-6, -0.599e-7, 0.2052e-6, -0.828e-7, -0.1365e-6, 0.137e-7, -0.1618e-6, 0.1374e-6, 0.989e-7, 0.880e-7, -0.1078e-6, 0.2022e-6, -0.815e-7, 0.123e-7, -0.75e-8, 0.477e-7, 0.701e-7, -0.796e-7, 0.197e-7, -0.14e-8, 0.1472e-6, 0.1679e-6, -0.1135e-6, 0.209e-7, -0.69e-8, -0.615e-7, 0.1503e-6, 0.1314e-6, 0.450e-7, -0.762e-7, -0.924e-7, 0.1371e-6, 0.381e-7, 0.1007e-6, 0.29e-8, -0.1353e-6, -0.573e-7, -0.1134e-6, -0.158e-7, -0.46e-8, -0.242e-7, -0.379e-7, 0.38e-8, 0.576e-7, 0.51e-8, -0.28e-8]


Download mw.mw

I can't tell why Maple does what it does.  But a close look at the Maple's result makes it possible to find the correct solution as follows.

restart;

ode:=diff(y(x),x)=1+y(x)+y(x)^2*cos(x);

diff(y(x), x) = 1+y(x)+y(x)^2*cos(x)

dsolve({ode, y(0)=0}):
dsol :=simplify(%) assuming x > 0, x < 2*Pi;

y(x) = (2*c__1*MathieuS(-1, -2, (1/2)*x)+2*MathieuC(-1, -2, (1/2)*x))/(-c__1*MathieuS(-1, -2, (1/2)*x)+c__1*MathieuSPrime(-1, -2, (1/2)*x)-MathieuC(-1, -2, (1/2)*x)+MathieuCPrime(-1, -2, (1/2)*x))

indets(dsol, name);

{c__1, x}

That c__1 should not be there.  Let's see how dsol's initial value depends on c__1NULL

eval(dsol, x=0);

y(0) = 2/(-1+c__1)

Okay, so if we want y(0) = 0, then c__1 should be infinity.

limit(dsol, c__1=infinity):
mysol := unapply(rhs(%), x);

proc (x) options operator, arrow; 2*MathieuS(-1, -2, (1/2)*x)/(-MathieuS(-1, -2, (1/2)*x)+MathieuSPrime(-1, -2, (1/2)*x)) end proc

Here what the solution looks like:

plot(mysol(x), x=0..5);

 

Download mw.mw

Maple's mod, modp, and mods are intended for use in polynomial algebras.  For modular arithmetic with integers use irem instead.  Thus,

FB := sum(irem(5, product(2, t = 0 .. irem(q - 1, 3))), q = 1 .. 2);

evaluates to 2 as you would expect.

 

restart;

with(plots):

HarmonicEnergies := proc(N::posint)
    local n;
    return Vector([seq(n + 1/2, n = 0..N-1)]);
end proc:

BuildM := proc(N::posint, mx::positive)
    local m, n, Mentry, M;
    Mentry := (m,n) -> exp(1/(4*mx)) *
        sqrt(min(m,n)!/max(m,n)!) *
        (1/sqrt(2*mx))^abs(m-n) *
        LaguerreL(min(m,n), abs(m-n), -1/(2*mx));
    M := Matrix(N, N, (m,n) -> evalf(Mentry(m-1, n-1)));
    return M;
end proc:

GaussianStateCoeffs := proc(N::posint, mx::positive,
                             x0::realcons := 0.0, vx0::realcons := 0.0,
                             omega::realcons := 1.0,
                             sigmax::realcons := 1/sqrt(2*mx*omega))
    local px0, alpha, pref, C, n;

    px0 := mx * vx0;
    alpha := x0 / (sqrt(2) * sigmax) + I * px0 * sigmax;
    pref := exp(-abs(alpha)^2 / 2);

    # Proper n from 0 to N-1
    C := Vector(N, n -> evalf(pref * alpha^(n-1) / sqrt((n-1)!)), datatype = complex[8]):
    return C;
end proc:

N := 3:
mx := 2:
my := 1:
lambda := 1:
y0 := 0:
p0 := -5:
t_final := 1:   # was 30(!)

E := HarmonicEnergies(N);

Vector(3, {(1) = 1/2, (2) = 3/2, (3) = 5/2})

M := BuildM(N, mx);

Matrix(3, 3, {(1, 1) = 1.133148453, (1, 2) = .5665742265, (1, 3) = .2003142388, (2, 1) = .5665742265, (2, 2) = 1.416435566, (2, 3) = .9014140745, (3, 1) = .2003142388, (3, 2) = .9014140745, (3, 3) = 1.735133569})

B := Matrix(N,N, (m,n) -> exp(I*(E[m]-E[n])*tau) * M[m,n]);

Matrix(3, 3, {(1, 1) = 1.133148453, (1, 2) = .5665742265*exp(-I*tau), (1, 3) = .2003142388*exp(-(2*I)*tau), (2, 1) = .5665742265*exp(I*tau), (2, 2) = 1.416435566, (2, 3) = .9014140745*exp(-I*tau), (3, 1) = .2003142388*exp((2*I)*tau), (3, 2) = .9014140745*exp(I*tau), (3, 3) = 1.735133569})

Cvec := Vector(N, i -> C[i](tau));

Vector(3, {(1) = C[1](tau), (2) = C[2](tau), (3) = C[3](tau)})

de_C := seq(diff(Cvec,tau) =~ lambda*exp(-y(tau)) * B . Cvec);

diff(C[1](tau), tau) = 1.133148453*exp(-y(tau))*C[1](tau)+.5665742265*exp(-I*tau)*exp(-y(tau))*C[2](tau)+.2003142388*exp(-(2*I)*tau)*exp(-y(tau))*C[3](tau), diff(C[2](tau), tau) = .5665742265*exp(I*tau)*exp(-y(tau))*C[1](tau)+1.416435566*exp(-y(tau))*C[2](tau)+.9014140745*exp(-I*tau)*exp(-y(tau))*C[3](tau), diff(C[3](tau), tau) = .2003142388*exp((2*I)*tau)*exp(-y(tau))*C[1](tau)+.9014140745*exp(I*tau)*exp(-y(tau))*C[2](tau)+1.735133569*exp(-y(tau))*C[3](tau)

de_y := diff(y(tau),tau) = p(tau) / my;

diff(y(tau), tau) = p(tau)

de_p := diff(p(tau),tau) = lambda * exp(-y(tau)) * Cvec^+ . B . Cvec;

diff(p(tau), tau) = (1.133148453*exp(-y(tau))*C[1](tau)+.5665742265*exp(I*tau)*exp(-y(tau))*C[2](tau)+.2003142388*exp(-y(tau))*C[3](tau)*exp((2*I)*tau))*C[1](tau)+(.5665742265*exp(-y(tau))*C[1](tau)*exp(-I*tau)+1.416435566*exp(-y(tau))*C[2](tau)+.9014140745*exp(-y(tau))*C[3](tau)*exp(I*tau))*C[2](tau)+(.2003142388*exp(-y(tau))*C[1](tau)*exp(-(2*I)*tau)+.9014140745*exp(-I*tau)*exp(-y(tau))*C[2](tau)+1.735133569*exp(-y(tau))*C[3](tau))*C[3](tau)

ic := seq(subs(tau=0, Cvec) =~ GaussianStateCoeffs(N, mx)),
        y(0)=y0, p(0)=p0;

C[1](0) = HFloat(1.0)+HFloat(0.0)*I, C[2](0) = HFloat(0.0)+HFloat(0.0)*I, C[3](0) = HFloat(0.0)+HFloat(0.0)*I, y(0) = 0, p(0) = -5

dsol := dsolve({de_C, de_y, de_p, ic}, numeric);

`Non-fatal error while reading data from kernel.`

Plot the real and imaginary parts of y(tau)

display(
    < odeplot(dsol, [tau, Re(y(tau))], tau=0..t_final) |
      odeplot(dsol, [tau, Im(y(tau))], tau=0..t_final) > );

 

 

 

 

 

 

display(
    < odeplot(dsol, [tau, Re(p(tau))], tau=0..t_final) |
      odeplot(dsol, [tau, Im(p(tau))], tau=0..t_final) > );

 

 

 

 

 

 

display(
    < odeplot(dsol, [tau, Re(C[1](tau))], tau=0..t_final) |
      odeplot(dsol, [tau, Im(C[1](tau))], tau=0..t_final) > );

 

 

 

 

 

 

display(
    < odeplot(dsol, [tau, Re(C[2](tau))], tau=0..t_final) |
      odeplot(dsol, [tau, Im(C[2](tau))], tau=0..t_final) > );

 

 

 

 

 

 

display(
    < odeplot(dsol, [tau, Re(C[3](tau))], tau=0..t_final) |
      odeplot(dsol, [tau, Im(C[3](tau))], tau=0..t_final) > );

 

 

 

 

 

 

 

Download mw2.mw

I assume that you are writing your notes in LaTeX.  If not, then you should.

You may do the drawings in Maple, but that will be a struggle.  Things will go much smoother if you learn how to use the TikZ package and do the drawings in LaTeX.  That will require some investment of time and effort, but it would be a worthwhile investment.

Here is a sample.  Took me less than 10 minutes to do it.

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[>=latex]
    \pgfmathsetmacro{\R}{2.5}
    \pgfmathsetmacro{\h}{0.05*\R}

    % the coordinate axes
    \draw[->] (-1.2*\R,0) -- (1.2*\R,0) node[below] {$x$};
    \draw[->] (0,-0.1*\R) -- (0,1.2*\R) node[right] {$y$};

    % the contour
    \draw[red, thick]
        (-\R,0) 
        -- (-1/\R,0)
        arc [start angle = 180, delta angle = -180, radius = 1/\R]
        -- (\R,0)
        arc [start angle = 0, delta angle = 180, radius = \R]
        -- cycle;

    % arrowheads
    \draw[->, >=stealth, red, very thick] (-0.5*\R,0) -- +(0.01,0);
    \draw[->, >=stealth, red, very thick] ( 0.5*\R,0) -- +(0.01,0);
    \draw[->, >=stealth, red, very thick] ( 0, \R)    -- +(-0.01,0);

    % labels
    \node at (45:1.15*\R) {$\mu_R$};
    \draw
        (-\R,0) -- +(0,-\h) node [below] {$-R$}
        (-1/\R,0) -- +(0,-\h) node [below] {$-\frac{1}{R}$}
        ( 1/\R,0) -- +(0,-\h) node [below] {$ \frac{1}{R}$}
        ( \R,0) -- +(0,-\h) node [below] {$ R$}
    ;
        
\end{tikzpicture}
\end{document}

 

 

restart;

with(plots):

The vertices:

A, B, C := <0,0>, <3,0>, <3*cos(Pi/3), 3*sin(Pi/3) >;

Vector[column](%id = 36893622867421332772), Vector[column](%id = 36893622867421332892), Vector[column](%id = 36893622867421333012)

The points P, Q, R:

Q := 1/3*A + 2/3*C;
P := 1/3*C + 2/3*B;
R := <4,0>;

Vector(2, {(1) = 1, (2) = sqrt(3)})

Vector(2, {(1) = 5/2, (2) = (1/2)*sqrt(3)})

Vector[column](%id = 36893622867421339764)

If P lies on QR, them this equation will have a solution, otherwise there won't be a solution:

P = (1-t)*Q + t*R;
solve(%, t);

(Vector(2, {(1) = 5/2, (2) = (1/2)*sqrt(3)})) = (Vector(2, {(1) = 1+3*t, (2) = (1-t)*sqrt(3)}))

{t = 1/2}

display(
        pointplot([A,B,C,A], connect, color="Green"),
        pointplot([B,R], connect, color="Green", linestyle=dash),
        pointplot([P,Q,R], symbol=solidcircle, symbolsize=20, color="Red"),
        pointplot([Q, R], connect, color="Blue"),
        textplot([
                [seq(A), 'A', align={below,left}],
                [seq(B), 'B', align={below}],
                [seq(C), 'C', align={above}],
                [seq(Q), 'Q', align={above,left}],
                [seq(P), 'P', align={above,right}],
                [seq(R), 'R', align={below}],
        NULL]),
scaling=constrained, axes=none);

Download mw.mw

 

restart;

with(plots):

with(plottools):

The integers m and n specify a hexagon's column and row indices, and col is the color.

p := proc(m, n, col)
        local p, x, y;
        p := polygonbyname("hexagon", color=col, radius=sqrt(3)/2);
        x := 3/2*m;
        y := sqrt(3)* `if`(type(m, even), n, n+1/2);
        translate(p, x, y);
end proc:

P :=
        p(0,0,red),
        p(1,0,green),
        p(2,0,blue),
        p(0,1,yellow),
        p(1,1,cyan),
        p(2,1,magenta):

display(P, scaling=constrained, size=[600,600], axes=none);

 

 

Download mw.mw

Added later:

With the proc(m,n,col) on hand, we can generate tilings of desired size:

M, N := 10, 7:
seq(seq(p(m,n,red),   n=irem(m,2)..N, 3), m=0..M),
seq(seq(p(m,n,green), n=irem(m,2)+1..N, 3), m=0..M),
seq(seq(p(m,n,blue),  n=2*irem(m+1,2)..N, 3), m=0..M):
display(%, scaling=constrained, axes=none);

Here is yet another solution.  The logic is explained in the attached PDF.

restart;

local gamma:

Warning, A new binding for the name `gamma` has been created. The global instance of this name is still accessible using the :- prefix, :-`gamma`.  See ?protect for details.

eq1 := alpha = b/(2*a)*h^2;

alpha = (1/2)*b*h^2/a

eq2 := beta = a*b/4*( (a/2-h)/(a/2) )^2;

beta = b*((1/2)*a-h)^2/a

eq3 := gamma = a*b/4 - alpha;

gamma = (1/4)*a*b-alpha

sol := solve({eq1,eq2,eq3}, {a,b,gamma});

{a = RootOf(_Z^2-4*_Z*alpha+4*alpha^2-2*alpha*beta)*h/alpha, b = 2*RootOf(_Z^2-4*_Z*alpha+4*alpha^2-2*alpha*beta)/h, gamma = 2*RootOf(_Z^2-4*_Z*alpha+4*alpha^2-2*alpha*beta)-3*alpha+beta}

We get two choices for gamma:

gamma_choices := {allvalues(subs(sol, gamma))};

{alpha-2*2^(1/2)*(beta*alpha)^(1/2)+beta, alpha+2*2^(1/2)*(beta*alpha)^(1/2)+beta}

Let's evaluate

simplify(eval(gamma_choices, {alpha=2, beta=9}));

{-1, 23}

Area can't be negative, and therefore gamma is 23.

 

area-puzzle.pdf

Download area-puzzle.mw

The "solution" that you have obtained says that y(t)^2 = arctan(t) / t.   Letting t go to zero we get y(0)^2=1.  In what way does that satisfy the initial condition y(0)=0?

If you are looking for a way to mark a missing point on a graph by an empty circle, as it's done in textbooks, this may be of some use to you.

restart;

with(plots):

expr := (x^3-1)/(x-1);    # change as needed

(x^3-1)/(x-1)

Want to remove the point (x0,y0) from the graph

x0 := 1;

1

y0 := limit(expr, x=x0);

3

Size of the gap in the graph

h := 0.025;

0.25e-1

The symbolsize is determined by trial-and-error

display(
  plot(expr, x=0..x0-h),
  plot(expr, x=x0+h..2),
  pointplot([x0,y0], symbol=circle, symbolsize=30),
color="Green", thickness=3);

 

Download mw.mw

You have been shown several fancy approaches to solving your problem. Here is a  very basic approach, which is not much different from what you already have in your worksheet.  It's just organized in a cleaner way.

restart;

A, B, C := [0,1], [-1,4], [1,2];

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

f := x -> a*x^2 + b*x + c;

proc (x) options operator, arrow; a*x^2+b*x+c end proc

eqns :=
  A[2] = f(A[1]),
  B[2] = f(B[1]),
  C[2] = f(C[1]);

1 = c, 4 = a-b+c, 2 = a+b+c

sol := solve({eqns});

{a = 2, b = -1, c = 1}

subs(sol, f(x));

2*x^2-x+1

 

Download mw.mw

 

Consider using the inert form %* of multiplication:
 

v := <a,b>;

Vector(2, {(1) = a, (2) = b})

v %* cos(theta*t+phi);

`%*`(Vector(2, {(1) = a, (2) = b}), cos(t*theta+phi))

Evaluate the result when needed:

value(%);

Vector(2, {(1) = cos(t*theta+phi)*a, (2) = cos(t*theta+phi)*b})

1 2 3 4 5 6 7 Last Page 2 of 58