Joe Riel

9530 Reputation

23 Badges

20 years, 24 days

MaplePrimes Activity


These are answers submitted by Joe Riel

What is the "it" you are referring? 

assume(Not(x::posint));

is equivalent to

assume(x::Not(posint));

In both cases, the (final) property is Not(posint).  However, the phrase x::Not(posint), which is of type `::`, is not a property.  It is a phrase that, in the context, applies a property to a variable.

I don't have Maple10 immediately.  However, I don't see why Not(x::posint), or, for that matter x::posint, should have been a property.  Seems to me like a bug that was fixed.

As expected

type(posint, property);
                                             true
type(Not(posint), property);
                                             true

Use unapply to create a procedure from an expression.  However, x and y are local to lister, so you cannot directly access them from pyra.  To fix that, make them parameters of lister and pass them in.  Better yet, modify lister to return procedures. 

Note that the code in lister is not particularly efficient.  Building up a list term by term in a loop is, in Maple, an O(n2) process.  Better to do this with a seq:

a := (u,n) -> max(min(abs(u-4*n)-2*n,n),-n):
b := (u,n) -> max(min(u,1/2*(abs(u-5*n)-abs(u-3*n))),u-8*n):
lister := proc(n)
local u,x,y;
    [seq(unapply([x+a(u,n),y+b(u,n)],x,y), u = 1..8*n)];
end proc:

lister(3);

Because your expression is not a polynomial, fsolve won't find all real roots. You might be able to use RootFinding:-Analytic, but that requires a bit more power than is needed for this problem.

Here is a procedure I wrote some time ago for this sort of problem.

findallroots := proc(eqs, x, rng::range(numeric))
local roots,pts,i;
    roots := {fsolve}(eqs, x, rng, 'avoid' = {x=lhs(rng), x=rhs(rng)});
    if roots = {} or not roots::set(numeric) then
        NULL
    else
        pts := sort([op(rng),op(roots)]);
        op(roots),seq(procname(eqs, x, pts[i-1]..pts[i]), i=2..nops(pts))
    fi
end proc;

f  := sin(4*x)*(exp(-(x-1)^4)):
df := diff(f,x):
a := findallroots(f, x, -2..1);
              a := -0.7853981634, -1.570796327, 0., 0.7853981634

Note that quo can assign the remainder to an optional argument (fourth, with this usage), so you could do

q := (4*a^4-2*a^3+8*a-5) / (3*a^2-1):
(nq,dq) := (numer,denom)(q):
quo(nq,dq,a,'rq') + rq/dq;
                                                   22 a
                          2               - 41/9 + ----
                       4 a    2 a                   3
                       ---- - --- + 4/9 + -------------
                        3      3               2
                                            3 a  - 1

Another possibility is to convert to a continued fraction

convert(q,confrac,a);
                    2
                 4 a    2 a                     22
                 ---- - --- + 4/9 + --------------------------
                  3      3            /    41        229     \
                                    9 |a + -- + -------------|
                                      |    66        /    41\|
                                      |         4356 |a - --||
                                      \              \    66//

Which suggests an easier way to do the original (with a slightly different, but equivalent, form):

map(normal,convert(q,confrac,a));      
                           2
                        4 a    2 a          -41 + 66 a
                        ---- - --- + 4/9 + ------------
                         3      3                2
                                           9 (3 a  - 1)


Did you mean

f := x^3;
g := piecewise(x<=0, m1*x+b1, m2*x+b2);

So is g just piecewise continuous?  Or do we have the additional constraint that m1*c+b1 = m2*c+b2?  In which case it isn't clear how to vary c. 

If we can assume that f > g for 0 < x < 1, then the solution is straightforward:

A := int(f-g, x=0..1):
dA := diff(A, c) assuming c > 0, c < 1;
solve(dA, {c});

Without that assumption, the problem gets significantly more difficult.  You need to check whether this is a minimum or maximum and satisfies the constraints.
                           

You mentioned using basis. That is a command in the deprecated linalg package. You should consider using LinearAlgebra.


You can also do

evalf[100](sqrt(x))

I agree with the original poster, there should be an inverse to CoefficientList/CoefficientVector in PolynomialTools. Creating one is easy enough, but it should really be in the PolynomialTools package. Otherwise less sophisticated users will do so with sum or even term by term in a do-loop.

Using the solution for hyperbolic motion (p. 323) try the following:

eqhyperb := (x+c^2/a)^2 - c^2*t^2 = c^4/a^2:
sols := solve(eq, x);
sol := sols[1]:

eqphoton := c*(t-t0):

asymp := convert(asympt(sol,t,1),'polynom');

asol := solve(identity(asymp = eqphoton,t),[a,t0]);

#check
plot(subs(asol[], a=3, c=1, [sol,eqphoton]), t=0..3);

Unzip the file and add the name of the directory to libname.  On my linux box I did

$ unzip Gravitation.zip
$ cd Gravitation
$ ls
Documentation.mw  Gravitation.mw  maple.ind  maple.lib
$ pwd
/home/joe/maple/lib/Gravitation
$ maple11
libname := "/home/joe/maple/lib/Gravitation", libname:
with(Gravitation);
[aboutGravitation, addObjects, areEqual, createMetric, createObject,
    createTetrad, deriveChristoffel, deriveEinstein, deriveKretschmann,
    deriveRicci, deriveRicciScalar, deriveRiemann, deriveSpinConnection,
    deriveSpinCurvature, deriveWeyl, multiplyObjects, subtractObjects]


Actually, what we would really do is simply

plot(sin, 1..12);

which is shorter and nicer than what is required in Matlab.  No use plotting vectors/lists if you can use Maple's adapative plotting capability. Just because Matlab is restricted to plotting vectors doesn't mean that that is the best way to go.

 

Not being particularly adept at evaluating integrals, I took a backwards approach and used Maple's identify function to guess the expression for particular values of a.  It was more amusing than enlightening:

# use the half-integral
J2 := a -> Int(exp(-a*x^2)*sech(x/2)^2, x=0..infinity):

guess := proc(a)
local y,id;
    y := evalf[30](J2(a));
    id := identify(y);
    if not id::float then
        'J2'(a) = id;
    end if;
end proc:

for a in [0,1,sqrt(Pi)] do
    guess(a);
end do;
                                   J2(0) = 2

                                       3/5      3/5
                                   10 7    ln(3)
                           J2(1) = -- -------------
                                   49        3/8
                                        ln(2)

                                        3/5        8/5
                             1/2    10 7    Zeta(5)
                        J2(Pi   ) = -- ---------------
                                    49         8/7
                                          ln(3)


You might try, instead, using animate.   I think the result would be more useful.

with(plots):
animate(plot, [x^n, x=-1..1], n=1..20);

fopen("/usr/local/mydir/examp/example.dat");

read "/home/user/example/mycode.mws";

Actually, that last one is questionable----normally one doesn't use the `read' command to directly read a .mws file, those files usually contain a classic style Maple worksheet.  If that file really contains Maple script code, than you might consider renaming it to mycode.mpl.

First 99 100 101 102 103 104 105 Last Page 101 of 114