Rouben Rostamian

MaplePrimes Activity


These are answers submitted by Rouben Rostamian

Here is the proper way of defining your Lagrangian:

L := J/2*(diff(x(t),t)/R)^2
   + m__r/2*diff(x(t),t)^2
   + m__p/2*((diff(x(t),t) + l*diff(phi(t),t)*cos(phi(t)))^2 + (l*diff(phi(t),t)*sin(phi(t)))^2)
   + m__p*g*l*cos(phi(t));

but be sure to verify that I have not introduced errors in transcribing the image that you have provided.

If you are interested in the final form of the Euler-Lagrange equations and don't care about the intermediate steps, then Maple's EulerLagrange function in the VariationalCalculus package will produce the result directly, as in Method 1 below.  Otherwise look at Method 2.

Method 1:

tmp1 := VariationalCalculus:-EulerLagrange(L, t, [x(t),phi(t)]);

tmp1 consists of a set of four expressions—two equations of the form something=K1 and something=K2, which are the integrals of motion (conservation of energy and momentum).  The other two are the differential equations of motion.  In the next step I delete the integrals of motion, and keep the differential equations:

tmp2 := remove(type, tmp1, equation);

tmp2 consists of two differential equations as I noted above.  To verify that we indeed have two items, we do:

nops(tmp2);

and indeed it returns "2".

Next, we name those equations de1 and de2:

de1 := tmp2[1] = 0;
de2 := tmp2[2] = 0;

Then you do whatever you need to do with de1 and de2

Method 2:

If you insist on doing the calculations one-step-at-a-time as you have outlined in your statement, you need to load the Physics package.  The package redefines Maple's "diff" operator which then enables you to calculate derivatives with respect to derivatives.

with(Physics):
dL_dxdot := diff(L, diff(x(t),t));         # derivative of L with respect to xdot
dL_dphidot := diff(L, diff(phi(t),t));     # derivative of L with respect to phidot
dL_dphi := diff(L, phi(t));                # derivative of L with respect to phi
diff(dL_dxdot, t);

 

p1 := plot(x^2 - 1, x = -2 .. 2, color=blue):
p2 := plots:-pointplot([3/2,5/4], symbol=solidcircle, symbolsize=20, color=white):
p3 := plots:-pointplot([3/2,5/4], symbol=     circle, symbolsize=20, color=black):
plots[display](p1, p2, p3);

In the attached worksheet I show how to generalize the definition of the pedal curve to pedal surface and calculate the equation of the pedal surface in the general case.  Then I illustrate the result by calculating the pedal surface of an ellipsoid with respect to its center.  Here is what it looks like.

Download pedal-surface.mw

No need for extra packages.  Just do this:

restart;
k := x -> piecewise(x < -6, 1/2*x + 10, x < -3, 1, x < 6*Pi, sin(1/2*x) + 2, x < 25, x - 15);
plot3d(k(x), t=0..2*Pi, x=-20..20, coords=cylindrical);

The parametrization of a surface (any surface) is not unque.  The way a surface is parametrized can have a drastic effect in how it is rendered on screen.

The standard parametrization of the oloid does not produce good computer-generated graphics as you have observed. But an oloid has a great deal of symmetries.  It is not difficult to see that it may be decomposed into four congruent patches, each of which has a quite "tame" parametrization for which Maple's default plotting grid is more than adequate.  Here I construct the oloid by putting together the four patches. 

restart;
alpha[1] := sin(t):
alpha[2] := -1/2 - cos(t):
alpha[3] := 0:
beta[1] := 0:
beta[2] := 1/2 - cos(t)/(1+cos(t)):
beta[3] := sqrt(1 + 2*cos(t))/(1+cos(t)):
x := (1-m)*alpha[1] + m*beta[1];
y := (1-m)*alpha[2] + m*beta[2];
z := (1-m)*alpha[3] + m*beta[3];
plot3d([[x,y,z], [x,y,-z], [z,-y,x], [-z,-y,x]], m=0..1, t=-Pi/2..Pi/2,
    scaling=constrained, color=[red,green,blue,yellow]);

I have colored the patches in four different colors in order to delineate them.  Change surface style and color as it suits your needs.

 

T := t -> (t+459.47) * 5/9;
seq(printf("%10d %10.2f\n", t, T(t)), t=100..110);
       100     310.82
       101     311.37
       102     311.93
       103     312.48
       104     313.04
       105     313.59
       106     314.15
       107     314.71
       108     315.26
       109     315.82
       110     316.37

 

Inversion in a sphere is much simpler than what you have in your worksheet.  Here is how I would do it.

Inversion in a sphere

Consider a sphere Sof radius R centered at the origin.  Let `#mover(mi("r"),mo("&rarr;"))` be the position vector of any

point Pin space. The inversion of P with respect to S is the point given by the position

vector `#mover(mi("&rho;",fontstyle = "normal"),mo("&rarr;"))` = R^2*`#mover(mi("r"),mo("&rarr;"))`/abs(`#mover(mi("r"),mo("&rarr;"))`)^2  provided that `#mover(mi("r"),mo("&rarr;"))` is nonzero.  We see that inversion maps the outside

of the sphere into the inside, and vise versa.  Let's note that in Cartesian coordinates
`#mover(mi("r"),mo("&rarr;"))` ="<x,y,z>     implies    (rho)=(R^(2))/(x^(2)+y^(2)+z^(2))*<x,y,z>."

 

Here we illustrate this graphically by inverting a torus in a sphere.

restart;

with(plots):

with(plottools):

The equation of a torus of radii a and b, displaced by d along the x axis in the Cartesian coordinates:

T := < d + (a + b*cos(s))*cos(t), (a + b*cos(s))*sin(t), b*sin(s) >;

Vector(3, {(1) = d+(a+b*cos(s))*cos(t), (2) = (a+b*cos(s))*sin(t), (3) = b*sin(s)})

The inversion of the torus in the sphere S

T__inverse := R^2/(T^+ . T) * T;

Vector(3, {(1) = R^2*(d+(a+b*cos(s))*cos(t))/((d+(a+b*cos(s))*cos(t))^2+(a+b*cos(s))^2*sin(t)^2+b^2*sin(s)^2), (2) = R^2*(a+b*cos(s))*sin(t)/((d+(a+b*cos(s))*cos(t))^2+(a+b*cos(s))^2*sin(t)^2+b^2*sin(s)^2), (3) = R^2*b*sin(s)/((d+(a+b*cos(s))*cos(t))^2+(a+b*cos(s))^2*sin(t)^2+b^2*sin(s)^2)})

Pick parameters for illustration:

params := { R=10, d=8, a=3, b=1 };

{R = 10, a = 3, b = 1, d = 8}

plots:-display([
        sphere(eval(R, params), style=line),
        plot3d(eval(T, params), s=0..2*Pi, t=0..2*Pi, style=surface, color="Green"),
        plot3d(eval(T__inverse, params), s=0..2*Pi, t=0..2*Pi)
], scaling=constrained, viewpoint=[circleleft, frames=100], axes=none);

 

 

Download inversion-in-sphere.mw

 

There are mnay ways of doing it, depending on what you want to do with the results.  Also it depends on how you represent quaternions.  You say that you want to represent a quaternion as a vector of length 4, but in your example your write qaa and qab as lists.  Lists and vectors are different types of objects in Maple.

Let's say you represent a quaternion as a list of length 4.  Then this will do what you want:

restart;

mult := proc(p::list,q::list)
        [
                p[1]*q[1] - p[2]*q[2] - p[3]*q[3] - p[4]*q[4],
                p[1]*q[2] + p[2]*q[1] + p[3]*q[4] - p[4]*q[3],
                p[1]*q[3] - p[2]*q[4] + p[3]*q[1] + p[4]*q[2],
                p[1]*q[4] + p[2]*q[3] - p[3]*q[2] + p[4]*q[1]
        ];
end proc:

 

mult([a,b,c,d],[e,f,g,h]);

[a*e-b*f-c*g-d*h, a*f+b*e+c*h-d*g, a*g-b*h+c*e+d*f, a*h+b*g-c*f+d*e]

mult([8,4,6,2], [2,4,6,8]);

[-52, 76, 36, 68]

That said, I much prefer the [scalar, vector] pair representation of quaternions (see the Wikipedia article) rather than lists of length 4.  But that again depends on what you want to do with them.

 

de := a*diff(y(x),x,x) + b*diff(y(x),x) + c*y(x) = 0;
dsolve(de) assuming b^2 < 4*a*c;

 

restart;

P := [[1,1], [6,6], [7,12], [8,15], [10,17]];

[[1, 1], [6, 6], [7, 12], [8, 15], [10, 17]]

plot(P);

Returns the endpoint coordinates of the segment of the "second gradient".

select_second := proc(P::list)
        local i, s, Q;

        if nops(P) < 3 then
                error "the argument P should have at least 3 points";
        end if;

        # calculate the sequence of slopes
        seq(P[i+1]-P[i], i=1..nops(P)-1);
        s := map(p -> p[2]/p[1], [%]);

        # find the first index where consecutive slops are different
        for i from 2 to nops(P)-1 do
                if s[i] <> s[i-1] then
                        break;
                end if;
        end do;
        if i = nops(P) then
                error "there is no second gradient in the given P";
        else
                Q := [ P[i], P[i+1] ];
        end if;

        return Q;
end proc:

select_second(P);

[[6, 6], [7, 12]]

 

Download mw.mw

 

Okay, your hand-written calculations are good.  Here I will do those in Maple.

restart;

In your hand calculations the symbol m is used with two

different meanings, first as an unknown exponent, and

second, as an abbreviation for "meter".  That's not a good.

I will write k for the exponent to remove the confusion.

expr := v = P/L * eta^n * R^k;

v = P*eta^n*R^k/L

Below, we work with expr/v, in order to make the left-hand side

of the expression into the dimensionless "1".

subs(v=m/s, P=N/m^2, L=m, eta=N*s/m^2, R=m, expr/v);
eq := simplify(%) assuming m>0, N>0, s>0;

1 = s*N*(N*s/m^2)^n*m^k/m^4

1 = m^(-4-2*n+k)*s^(1+n)*N^(1+n)

We want this equation to hold identically for all m, s, N.  Therefore the

exponents of these quantities should be zero, that is,

sys := { -4 - 2*n + k = 0, 1 + n = 0, 1 + n = 0 };

{1+n = 0, -4-2*n+k = 0}

solve(sys);

{k = 2, n = -1}

This answer agrees with your hand calculations.

 

Note:  I formed the expression "sys" above by typing the three

exponents by hand.  It is possible to have Maple extract those

exponents programmatically but that would go far beyond the

scope of the beginner user of Maple.

 

Download mw.mw

 

How do you like this?

restart;

# macro emulates Matlab's "jet" colorscheme:
macro(jet=["zgradient", ["DarkBlue", "Blue", "DeepSkyBlue", "Cyan", "LawnGreen", "Yellow", "Orange", "Red", "DarkRed"]]):

plot3d((1-xi^2)*(1+tau), tau=-1..1, xi=-1..1,
    colorscheme=jet, orientation=[-120,72,0], axes=framed);

plot3d((1-xi^2)*(1+tau), tau=-1..1, xi=-1..1,
    colorscheme=jet, gridstyle=triangular, orientation=[-120,72,0]);

As Kitonum has noted, this is not an infinite fraction.  The integrand is z = ..  Then we see that z^2 = x*z, and therefore z = x.  Then the integral of z is x^2/2 + constant.  QED.

Forget about solve.  After you define psi, just do:

plots:-contourplot(psi, x=-1..1, eta=-2..2);

 

Try this:

restart;
plot(x^2, x=-1..1, labels=[typeset(NFE), typeset(log__10(`Max Err`))]);

First 17 18 19 20 21 22 23 Last Page 19 of 58