Carl Love

Carl Love

28015 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

The easiest way to get the nontrivial solution is

solve({eq||(1..4)}, {DC, tau, ton, T})

Since there's only one solution, assumptions can't help.

Do

eval(A1, exp= cos)

It seems like the motivation for your Question is doing some preparation for solving your BVP by the shooting method. Acer's implicitplot shows that there are likely 4 solutions. Maple does have a direct numeric solver for BVPs, but it's difficult to use when there are multiple solutions. Shooting works well and fast in this case. The entire worksheet below executes on my computer in less than 1 second, generating plots of y(x) and y'(x) for all 4 solutions.

restart:

st:= time():  #CPUtime at start

#The fsolve command below will likely fail if the dsolve values computed
#at the right boundary are not done at higher precision than that requested
#for the fsolve left-boundary solution.
Digits:= 15:

#
ode:= diff(y(x),x,x) + y(x)^2*diff(y(x),x) + cos(y(x)) = x;
bc:= (1+y)*D(y) - 3*y: #common part of both BCs
bc1:= bc(0);  # "= 0" is implied in both BCs.
bc2:= (bc - y^2)(1) + 1/2;

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

(1+y(0))*(D(y))(0)-3*y(0)

-y(1)^2+(1+y(1))*(D(y))(1)-3*y(1)+1/2

bc1_sol:= solve(bc1, D(y)(0));

3*y(0)/(1+y(0))

ICs:= (ic1:= y(0)= a), D(y)(0) = subs(ic1, bc1_sol);

y(0) = a, (D(y))(0) = 3*a/(1+a)

dsol_ivp:= dsolve({ode, ICs}, numeric, parameters= [a]):

#The syntax in the next procedure requires that y(1) be replaced with y(x)
#in bc2, but this will only be used for x=1.
bc2_prep:= subs([y(1)= y(x), D(y)(1)= diff(y(x),x)], bc2);

-y(x)^2+(1+y(x))*(diff(y(x), x))-3*y(x)+1/2

BC2:= proc(a)
    #Digits is a special type of global variable called an "environment
    #variable", which means that its value be reset to its previous value
    #every time this procedure exits.
    Digits:= 15;
    if a::numeric then
        dsol_ivp(parameters= [a]);
        eval(bc2_prep, dsol_ivp(1))
    else
        'BC2'(a)
    fi
end proc
:

Digits:= 10:  #precision for fsolve

#These ranges come from acer's implicitplot:
A_rngs:= [-4..-3, -2.5..-1.5, -0.99..-0.7, 0..0.3];

[-4 .. -3, -2.5 .. -1.5, -.99 .. -.7, 0 .. .3]

a_sols:= fsolve~(BC2(a), a=~ A_rngs);

[-3.535939019, -2.002235920, -.7734241018, .1155584192]

for a in a_sols do
    dsol_ivp(parameters= [a]);
    (print@plots:-odeplot)(
        dsol_ivp, `[]`~(x, [y(x), diff(y(x), x)]), x= 0..1,
        axes= boxed, view= [0..1.1, DEFAULT], gridlines,
        legend= [y, `y'`], size= [400,200], legendstyle= [location= right]
    )
od:

time()-st;  #CPUtime for this whole worksheet

.766

 

Download Shooting_method.mw

Like this:

restart;
mysphere:= (x - a)^2 + (y - b)^2 + (z - c)^2 - 10^2 = 0;
L:= [seq](seq(seq(`if`(igcd(a,b,c)=1, mysphere, NULL), a= 1..5), b= 1..5), c= 1..5);

 

The command to merge the iterated exponents is combine. For example, starting with the original W, you could do

combine(convert(W, exp));

For future Questions, please note that uploaded worksheets are much more useful to us than uploaded screenshots. In this particular case, the Question is simple enough that a photo was sufficient, but that's rarely the case.

combine can also work directly on your hyperbolic trig functions, so this produces an equivalent result:

convert(combine(W), exp);

I know that this Answer is not exactly what you're asking for, but you might find it useful anyway; and it's what I use personally. Any plot in Maple is simply a data structure that can be assigned to a variable. (In formal computer science, they would be called "first-class data structures".) The assigning can be done either before or after the plot is produced.

Before:
MyPlot:= plot(x^2, x= -2..2);

After:
plot3d(x*y, x= -1..1, y= -1..1);

... plot output omitted ...

MyPlot2:= %:

This can be done with any command that produces a plot or plots as its formal output (i.e., return value); they needn't be from the specific plot or plot3d command. Like any first-class data structure, the assignment can be done can be done regardless of whether the plot appears on screen.

I've had a similar (although not identical) thing happen several times (although not with Maple 2023). In my case, some math symbols changed also: for example, + became C and - became K. 

In my case, the problem could be corrected by saving and closing the worksheet, then closing the entire Maple session, then restarting Maple and the worksheet.

The problem was only with the display of the worksheets, not their underlying content (which remained unchanged). Once it affected one of my open worksheets, it affected all of my open worksheets. And, I do tend to keep worksheets open for many days, sometimes weeks.

Let me know if opening and closing corrects the problem for you.

Here's a workaround that isn't perfect, but I think is a lot better than making s an export of A:

restart;

module A() option object;
    local s::string:= "";
end module:

module B() option object(A);
    local my_inner_proc::static:= proc(self::B)
        self:-s:= cat(self:-s, "somethig");
        print(self:-s)
    end proc
   ;
   export foo::static:= proc(_self, $)
       my_inner_proc(_self) 
   end proc:
end module:

o:= Object(B);
o:-foo();
                 o := Object<<B,1582203658720>>
                           "somethig"

 

There is a long-standing (well over 20 years), fairly well-known, formal mechanism for doing this. This can be done for any (unevaluated) function:

`print/pochhammer`:= (a,n)-> ``(a)[n];
pochhammer(1/2, n);

Unlike the proposed methods using subs or eval, the method above only affects the prettyprinted display of the function; it doesn't change the function itself or your ability to perform further computations with it.

I think that what's happening is that due to a design oversight, the overload wrapping obscures the special status of a parameter named _self in an object method. A workaround is to use a normal procedure as a wrapper of the overload. The normal procedure explicitly passes _self to the overload, and implicitly (via _rest) passes the user's other arguments.

restart;
module person() option object;
local 
    Name::string:= "*", Age::numeric, #non-static object data

    set_info_inner::static:= overload([
        proc(self::person, name::string, $) option overload;
            self:-Name:= name;
            return
        end proc,

        proc(self::person, name::string, age::integer, $) option overload;
            self:-Name:= name;  self:-Age:= age;
            return
        end proc,

        proc() error "Wrong number or type of arguments", args[2..] end proc
    ])
;
export
    #wrapper that passes _self to overload:
    set_info::static:= _self-> set_info_inner(_self, _rest),

    Name?::static:= proc(_self, $) Name end proc,
    Age?::static:= proc(_self, $) Age end proc
;
end module
:
o:= Object(person);
o:-set_info("me"):
o:-set_info("me", 20):

o:-Name?();
o:-Age?();
Name?(o), Age?(o);
              o := Object<<person,1582091427520>>
                              "me"
                               20

                            "me", 20

o:-set_info("me", "you", 20);
Error, (in person:-set_info_inner) Wrong number or type of arguments, me, you, 20

  By the way, I haven't seen you on MaplePrimes for a long time. I'm glad that you're back.

Try adding this option to whatever plot command you used to generate that plot:

axis[1]= [tickmarks= [["0 - 2", "3 - 5", "6 - 8", "9 - 11"], rotation= Pi/2]]

If that doesn't work, please post the actual plot command you used; I'm sure that some minor adjustment will work. The font for the tick labels can also be changed.

Replace sin(x) with sin(x[i]), and replace sin*t[j] with sin(t[j]).

Here are two more ways: If you know that you want the index of the maximum element, use

max[index](R);

To get the index of any element, use

member(96, R, 'p'):  p;

where p is any variable.

Let be any type. Then

  • Type [T] matches lists with exactly 1 element, which must be type T;
  • Type list(T) matches lists with any number of elements (including 0), all of which are type T.

If you want to forbid the case of empty lists, you could make the declaration

m::And({Matrix, list(Matrix)}, Not([])) 

or

m::And({thistype, list}(Matrix), Not([])).

thistype is the identity function for types (not to be confused with the identical functional type).

Assuming that the 5 terms that you call Lr represent the beginning of an infinite power series in r, then that's a simple geometric series that converges iff abs(r) < 2/Pi, and its exact value is 

2*r/(1 + (2/Pi/r)^2),

or, equivalently,

2*r*(Pi*r)^2/((Pi*r)^2 + 4).

Since this exact value is easily obtained and is a degree-[3,2] rational function, it doesn't make sense to me to use a pade approximation.

Even if you truly only want to consider those 5 terms, they can be considered as the difference of two infinite geometric series to obtain

2*r*(1 + 1/R^5)/(1 + R), where R = (2/Pi/r)^2,

which is mathematically identical to your original 5 terms, not an approximation (with removable singularities for r in {-1, 0, 1}*2*I/Pi, but no inequality restriction on abs(r)).

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