Carl Love

Carl Love

28100 Reputation

25 Badges

13 years, 107 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@Markiyan Hirnyk The number option is not needed in this case, because the program can easily count that nops(DE13) = 2. If you do supply the option, then its value must be 2. I don't understand why that particular error message is issued, but setting number= 0 is ridiculous because it means that there are zero equations in the ODE system.

Clearly the OP had in mind something other than counting the number of equations by specifying number= 1000.

Quoting the help

number specifies the number of equations in the procedure-form first order system....

The number option is used to specify the number of equations, and is not needed when the equations are supplied algebraically (as you have them here). Obviously you had something else in mind by using number= 1000. Perhaps you meant the numpoints or numsteps option.

@sarra error is a reseved word in Maple. Replace data[error] with data[err].

Your values for b1, b2, and b3 are correct. b1 can be any positive number less than sqrt(72). b3 can be any number greater than sqrt(72).

If b=0, there is no damping, and the period is 2*Pi/sqrt(4.5). If b < sqrt(72), then the quasi-period is 8*Pi/sqrt(72-b^2). Note that this reduces to the former answer when b=0.

@teh_allchemist Your ig, the gearbox setting, is a discrete variable: its values are limited to {1,2,3,4,5}. Solve for each of the five values separately. I did it for ig = 5, and the solution only took 81 seconds. I guess the others would be about the same. And the solution was "only" 16 screens wide by 1 screen tall.

@Entvex Ah, I see. You want to extend the function periodically. That's a bit more complicated.

f:= t-> piecewise(0 <= t and t < 2, 2-t, 2 <= t and t <= 3, 2*t-4):

plot(f(t-3*floor(t/3)), t= 0..6);

 

@Mary Your only real mistake is that Array declarations need to be made with parentheses, not square brackets:

X:= Array(1..n);

You should also make i a local variable.

After that, your procedure works.

The %a format code is a powerful catch-all.

@Markiyan Hirnyk Yes, the numerators and denominators grow exceptionally fast. It is best to use floating point input for either of the first two arguments. This is an inherent property of the function and is not the fault of my code.

Indeed, Maple does not autocomplete if there is any character in front of the cursor. And this problem also exists in Worksheet mode.

All I see is two lines and a slider. Where's the actual code?

This is a really excellent Question, perhaps the best that I've seen on MaplePrimes. I don't know the answer. I am just posting this Reply to put this Question back on top of the Active Conversations list, with the hope that that will increase the chance for an Answer.

I am inlining your worksheet here.


restart;

M := module()

option package;

  export ModularArithmetic;

 

  export NewModulo := proc(p::posint)

    return Object(ModularArithmetic, p);

  end proc;

 

  ModularArithmetic := module()

  option object;

    local p := 0;

    

    export ModulePrint::static := proc(self::ModularArithmetic)

      cat("mod ", self:-p);

    end proc;

 

    export ModuleCopy::static := proc(self::ModularArithmetic, proto::ModularArithmetic, p::posint)

      self:-p := p;

    end proc;

 

   export ModuleApply := proc(n::nonnegint)

     # N.b. not static

     return modp(n, thismodule:-p);

   end proc;

 

  end module;

 

end module;

module () export ModularArithmetic, NewModulo; option package; end module

(1)

# Create a mla library file into local directory

# Location of the lib file,  It creates "M.mla" if mla does not exist.

savelibname := cat(".", kernelopts(dirsep),"M.mla");

# Save module to the current lib.

LibraryTools:-Save('M');

 

".\M.mla"

(2)

This uses the above typed code

with(M);

[ModularArithmetic, NewModulo]

(3)

Prototype prints as

ModularArithmetic;

thismodule

(4)

Construct new object...

m7 := NewModulo(7);

thismodule

(5)

Now m7 acts as an operator, computes integer mod 7...

m7(42), m7(13);

0, 6

(6)

Force restart and load package M from the .mla....

restart;

with(M);

[ModularArithmetic, NewModulo]

(7)

Prototype...

ModularArithmetic;

thismodule

(8)

Construct new object...

m7 := NewModulo(7);

thismodule

(9)

Now m7 barfs as operator.

Presumably the reference to thismodule has been resolved to point to the prototype instead of the instance.

Why does this happen when saved to .mla?  How can it be prevented / worked around so that the .mla works the same as code typed at command line?

m7(42), m7(13);

Error, (in ModuleApply) division by zero

 

 


Download BugThismoduleMLA.mw

@Syeda The context-menu solve feature that you are using is probably applying a numeric technique such as Newton's method that would never generate a non-real answer given that the starting points are real. It is probably not applying the cubic formula. If it is, then it is trimming the imaginary parts in the manner that I am suggesting.

To use the Re command, after generating each numeric solution, do

Re(%);

@nm The OP's formulas for the solution of the cubic are correct. The imaginary parts are due to round-off error in evaluating those formulas.

@J4James You need to remove the simplify around your dsolve command.

Eq1:=diff(psi(y),y$4)-b*diff(psi(y),y$2)=0; # b is parameter

res1:=dsolve(Eq1);
bcs:=psi(h1)=F,D(psi)(h1)=-1,psi(h2)=-F,D(psi)(h2)=-1;
res2:= dsolve({Eq1,bcs},psi(y));
match(rhs(res2)=rhs(res1),y,s);

                                            true

First 560 561 562 563 564 565 566 Last Page 562 of 709