Carl Love

Carl Love

28035 Reputation

25 Badges

12 years, 320 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

As you already realize, each problem can be reduced to a set of equations and/or inequalities in the two real variables x and y. For inequalities, the best command is plots:-inequal.

Here are some mistakes that you made:

a) 1. Note that z + 2 - I = z - (2+I). So, the distance formula is sqrt((x-2)^2 + (y-1)^2).
2. Your sqrt(2) should just be 2.

b) 1. Same mistake as above: distance formula on left side should be sqrt((x-1)^2 + (y-2)^2).
2. Distance formula on right side should be sqrt((x-3)^2 + (y-0)^2).

c) The bar symbol over a complex number or variable is called conjugate in English and Maple. It simply means to negate th​​​​​​e imaginary part. So, the left side is 2*x and the right side is x^2 + y^2.

d) For real x and y, arg(x+I*y) = arctan(y,x), using Maple's two-argument form of arctan.

e) 1. This is an equation not an inequality. Thus, its graph must be a curve (essentially 1-dimensional), not a region (essentially 2-dimnesional).
2. Re(z) = xIm(z) = y.

f) Same as d.

Opts:= labels= [Re,Im](z), scaling= constrained: #common plot options

(*3a:
For inequalities, use plots:-inequal.
 
You could use the distance formula for abs (absolute value), but it's a
bit easier to use its square.
*)
plots:-inequal(
    [1 <= (x-2)^2 + (y-1)^2, (x-2)^2 + (y-1)^2 <= 4],
    x= 0..4, y= -1..3, Opts
);
(*3b:
This is asking for the points equidistant between two points. Obviously
that's a line. If you solve the abs equation, all the square terms will
cancel leaving just y = x-1. Thus the regular plot command is a good
choice for this one.
*) 
plot(
    solve((x-1)^2 + (y-2)^2 = (x-3)^2 + y^2, y), x= 0..4, y= 0..4, 
    Opts
);
(*3c:
When put in (x,y) form, the equation has both x^2 and y^2. Thus
plots:-implicitplot is a good choice for this one.
*)
plots:-implicitplot(2*x = x^2+y^2, x= 0..2, y= -1..1, Opts);

(*3d: 
For real x and y, argument(x+I*y) = arctan(y,x).
optionsopen is used to highlight the effect of the strict
inequalities.
*)
plots:-inequal(
    [
        1 <= x^2+y^2, x^2+y^2 < 9,
        -Pi/4 <= arctan(y,x), arctan(y,x) < 3*Pi/4
    ],
    x= -3..3, y= -3..3,
    optionsopen= [linestyle= dash, color= red, thickness= 2], Opts
);

 

Your expression can be displayed in your desired form using this code. This seems elaborate, but the vast majority of this code is to retrieve the mathematical expression (as an ordinary Maple expression) from the displayed form. If the goal was only to get the displayed form without retrieval, it could be done in three lines or so.

restart
:
TS:= module()
uses T= Typesetting;
local
    #Using Typesetting:-_Hold introduces unwanted parentheses. I get
    #around that by using attributes and my own Hold.
    Hold, 
    ModuleApply:= e-> setattribute(T:-Typeset(e), Hold(e))
;
export
    #`macro` is needed because Typesetting:-Typeset declares its 1st
    #parameter uneval.
    Mn:= e-> (parse@sprintf)("macro(%a=%a)", ``||e, T:-mn(""||e)),
        
    Value:= e-> subsindets(
        subsindets(
            subs[eval](``= (()-> args), e), attributed,
            e->
            local p, A:= [attributes](e);
                `if`(membertype(specfunc(Hold), A, 'p'), op(A[p]), e)  
        ),
        specfunc({T:-mn, T:-mi}),
        N-> try parse(op(1,N)) catch: N end try
    )
;
end module
:

Usage:

TS:-Mn(2):
TS(a/(`2`*d)) . ``(b/c);
TS:-Value(%);
lprint(%);

You will need to execute the above to see the output. MaplePrimes will not display it correctly for me.

This Answer is just to provide a clue to the source of the error, not to provide a solution to the problem. The mn is a MathML operator used to make symbols and variables display in an upright style rather than the usual italics. An upright style would ordinarily be used for imaginary i. There are two ways see this in action (in Maple proper rather than MapleFlow, which I don't have):

Typsetting:-mn("i");
                               i

`#mn("i")`;
                               
i

The Typesetting commands are only suitable for display, but the second form is just a Maple symbol, so it can be used in computation like any other symbol. For example, you could define

i:= `#mn("i")`:

and then used in any input expression would display upright in the prettyprinted output.

 

Current Maple has a form of eval called eval[recurse]. I think that your Maple 15 doesn't have it, but it can be implemented as a one-liner anyway:

EvalRecurse:= proc(e, v::{list, set}(`=`), L:= lhs~(v))
    `if`(has(e,L), thisproc(eval(e,v), v, L), e)
end proc
:

Then, simply do

EvalRecurse(diff(u(Y(xi)), xi$5), {diff(Y(xi), xi) = mu*(1-Y(xi)^2)});

I see three major ways to simplify UV:

  1. It's not necessary to assume that variables are real; that is handled automatically by evalc.
  2. The number of parameters of most "simple" procedures f can be determined by nops([op](1,eval(f))) . Thus n doesn't need to be passed.
  3. By returning a list of two procedures constructed with unapply rather than a list of two expressions you can avoid the need to use possibly contaminated (i.e., already assigned) global variables x[1]y[1], etc. And the results will be easier to use.

Using those, UV becomes

UV:= proc(f::procedure)
local x, y, XY:= map2(index~, [x,y], [$1..nops([op](1,eval(f)))]);
    map(unapply, (evalc@[Re,Im]@f@op@(Complex@op)~)(XY), op~(XY))
end proc
:
#Example usage:
uv:= UV((z1,z2)-> (z1+z2)^2);
  [(x_1, y_1, x_2, y_2)-> -(y_1+y_2)^2+(x_2+x_1)^2, 
   (x_1, y_1, x_2, y_2)-> 2*x_1*y_1+2*x_1*y_2+2*y_1*x_2+2*x_2*y_2
  ]

Complex(uv(1,2,3,4)[]);
    -20 + 48*I

The issue that you're having with the lists Z and F is unrelated to this, but it can also be corrected with unapply, like this:

map(UV@unapply, F, Z);

In this case, it's very easy to express x as an explicit function of y. That would make getting numerical data easier, and the plotting could be done by the more-efficient and more-accurate command plot rather than plots:-implicitplot.

There are several ways to get this explicit function. Given the work already done by @dharr , the easiest way is

F:= unapply(solve(sol2, x), y);

evalf(F(1.1)); #numeric data
plot([F(y), y, y= 0.8..2]);


However, if you were starting from scratch, there are several ways to obtain this explicit function that are easier (from a computation perspective).

1. The FunctionAdvisor 3D plot of ln(z) can be made by

plots:-complexplot3d(
    ln(z), z= -5-5*I..5+5*I, view= [default$2, 0..4], title= ln(z),
    orientation= [-50, 60], labels= [Re, Im, abs@ln](z)
);

Using the real-number 3D plotting command plot3d, the above is equivalent to 

plot3d(
    abs(ln(x+I*y)), x= -5..5, y= -5..5, view= [default$2, 0..4], title= ln(z),
    color= arctan((Im,Re)(ln(x+I*y))),
    orientation= [-50, 60], labels= [Re, Im, abs@ln](z)
);

In complex analysis, for z = x+I*y, the arctan function used in the color option in the plot3d command above is a fundamental function called argument; specifically argument(z) = arctan(y,x). See ?argument, and see ?arctan for the precise definition of arctan(y,x) (essentially it's arctan(y/x) with some small adjustments). Every complex number can be uniquely specified by its absolute value r and argument theta via z = r*exp(I*theta) = r*cos(theta) + I*r*sin(theta). Understanding this equation is one of the most important steps in learning complex analysis.


2. A table of plots can be displayed by plots:-display(A) where A is a Vector or Matrix each of whose entries is a plot (from any plotting command). Examples:

PD:= rcurry(plots:-display, size= [200$2]):
PD(Vector(2, i-> plot(x^i, x= -2..2)));
PD(<seq(plot(x^i, x= -2..2), i= 1..2)>);
PD(Vector[row](4, i-> plot(x^i, x= -2..2)));
PD(<seq(plot(x^i, x= -2..2), i= 1..4)>^+);
PD(`<|>`(seq(plot(x^i, x= -2..2), i= 1..4)));
GT:= GraphTheory:
PD(
    Matrix(
        (4,4), 
        (i,j)-> GT:-DrawGraph(
            GT:-CompleteGraph(i,j), stylesheet= "legacy"
        )
    )
);

 

1. The 3d plot of ln(z) shown by FunctionAdvisor can be obtained by

plots:-complexplot3d(
    ln(z), z= -5-5*I..5+5*I, view= [default$2, 0..4], 
    orientation= [-45,45], labels= [Re(z), Im(z), abs(ln(z))]
);

2. A table of plots can be displayed via plots:-display(A) where A is a Vector or Matrix each of whose entries is a plot. Examples:

PD:= rcurry(plots:-display, size= [200$2]):
PD(Vector(2, i-> plot(x^i, x= -2..2)));
PD(<seq(plot(x^i, x= -2..2), i= 1..2)>);
PD(Vector[row](4, i-> plot(x^i, x= -2..2)));
PD(<seq(plot(x^i, x= -2..2), i= 1..4)>^+);
PD(`<|>`(seq(plot(x^i, x= -2..2), i= 1..4)));
GT:= GraphTheory:
PD(
    Matrix(
        (4,4), 
        (i,j)-> GT:-DrawGraph(
            GT:-CompleteGraph(i,j), stylesheet= "legacy"
        )
    )
);

 

Regarding your first example, note that even simplify(eq) returns an error. Your integral does not have a name as its 2nd argument; I'm not aware of that being a valid way of specifying an integral. The fact that you've found some simplify calling sequence that does something that you consider useful is I guess just a case of GIGO (garbage in, garbage out).

Looking at the help ?simplify,details, I don't see any possibility of assume= anything being used as the 3rd argument. Nor do I see anything that would allow assume= name::property to be used. The documented usage is only assume= property, which applies the property to all variables in the expression being simplified.

Even in Maple itself, the common use of assign to assign solution values to variables that were previously used symbolically (such as to specify a system of equations as in your case) is a sloppy programming practice that very often causes problems later on. You should use new variables, as in

(x0, y0):= eval([x, y], s)[];

It is not the assign command itself that causes problems; rather, it's assigning values (by any means) to the original variables x and y. Thus, I'd also recommend that Samir's suggestion be changed to

x0:= eval(x, s)  #x0 can be anything other than x or y.

Here is how to use a discrete approximate solution to a numeric BVP. I've used the same BVP as Rouben with a small modification to make it more general by including a symbolic parameter.

restart:
Digits:= 15 #suggested starting value
:
# I've included a symbolic parameter a in the ODE system in order to make this example as general as possible. 
ode:= diff(u(x),x$2) + a*surd(u(x),3)
:
# We need one additional boundary condition for each symbolic parameter:
bcs:= u(0) = 0, u(1) = 0, D(u)(0) = -.01
:
# This procedure solves the system, allowing for an optional discrete approximate solution, 
# and plots the solution.
Solve:= proc({
    DiscAppx::Matrix:= NULL, 
    plotopts::list({name, name=anything}):= 
        ['size'= [300,200], 'numpoints'= 50]
})
local 
    sol:= dsolve(
        {ode,bcs}, 'numeric', 'method'= 'bvp'['midrich'], 
        'maxmesh'= 2^9,
        `if`(DiscAppx=NULL, NULL, 'approxsoln'= DiscAppx),         
        _rest
    )
;
    print(plots:-odeplot(sol, [x, u(x)], plotopts[]));
    sol(0.5) #just to see the format
end proc
:

Solution with no approximation given:

S:= Solve();

S;
  [                                      
  [x = 0.5, u(x) = -0.00278207352306078, 
  [                                      

     d                             -20                       ]
    --- u(x) = -4.47952031890384 10   , a = 0.170377519905245]
     dx                                                      ]

# These names will be the 1st column of the discrete approximation matrix:
lhs~(S);
                     [          d         ]
                     [x, u(x), --- u(x), a]
                     [          dx        ]

npts:= 9: #minimum number of approximation points
X:= Vector[row](npts, i-> (i-1)/(npts-1)):
BuildMatrix:= Model->
    <<lhs~(S)[]> | <X, Model~(X), D(Model)~(X), eval(a,S)~(X)>>
:

Solve(DiscAppx= BuildMatrix(x-> -0.003*sin(2*Pi*x))):

Solve(DiscAppx= BuildMatrix(x-> -0.003*sin(Pi*x))):

Download DiscreteBVPApprox.mw

The relevant equations are given on the web page "Effect of atmospheric drag on artificial satellite orbits". The 2nd equation (10.131) gives the impression that the atmospheric density is a simple function of altitude. That's only an approximation; the density is also affected by the presence of magnetic storms and how much sunshine the specific portion of atmosphere is receiving.

The plot below is almost identical to your model plot. The value of M is 1408, i.e., the number of values of r used, 3 <= r <= 4. These values are chosen by the adaptive routine of plot. The value of iter ranges from a low of 110 to a high of over 450,000, depending on r. It is chosen by my procedure for convergence of the Lyapunov limit to 5 decimal places. It takes about 16 seconds to produce the plot.

I used my procedure from 5 years ago that Acer posted a link to. It only required one minor modification due to the extremely strict syntax requirements of evalhf.

LyapunovExponent:= proc(
     F::procedure,
     x0::complexcons,
     {epsilon::positive:= 1e-7}, #absolute error tolerance
     {max_iters::posint:= 2^21}   #infinite loop prevention
)
option `Author: Carl J. Love, 2016-May-10`;
description
"Computes a numeric approximation to "
"lambda(x0) = limit(sum(ln(abs(f'(x[i]))), i= 0..n-1)/n, n= infinity), "
"where x[i] = f(x[i-1]), x[0]= x0. "
"See: https://en.wikipedia.org/wiki/Lyapunov_exponent"
;
local 
    #Trick evalhf into believing that F has no lexical variables:
    f:= parse(sprintf("%a", eval(F))), 
    f1:= D(f)
;
    evalhf(
        proc(f, f1, x0, epsilon, max_iters)
        local S:= 0, L:= epsilon, newL:= 0, x:= x0, n;
            for n to max_iters while abs(newL-L) >= epsilon do
                L:= newL; 
                newL:= (S:= S+ln(abs(f1(x))))/n; 
                x:= f(x)
            od;
            if n > max_iters then
                error
                    "didn't converge; abs. err. = %1; "
                    "increasing epsilon or max_iters might help.",
                     abs(newL-L)
            fi;
            userinfo(
                1, LyapunovExponent, "Converged; iterations =", n
            );
            newL
        end proc
        (f, f1, x0, epsilon, max_iters)
    )
end proc
:
f:= a-> x-> a*x*(1-x):
infolevel[LyapunovExponent]:= 1:
CodeTools:-Usage(
    plot(
        a-> LyapunovExponent(f(a), 0.2, epsilon= 1e-5), 3..4, 
        smartview= false
    )
);

MaplePrimes will not let me post the plot (I guess due to the fairly high number of points).

It can be done by

Ont_data:= rawdata[rawdata[prname] =~ "Ontario"];

See the help page ?DataFrame,indexing, particularly the "Boolean" sections.

The command is timelimit. You had timeout.

If you add option implicit to dsolve, this ode is solved instantly.

First 56 57 58 59 60 61 62 Last Page 58 of 395