Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Hi everyone! It's been a remarkably long time since I posted on MaplePrimes -- I should probably briefly reintroduce myself to the community here. My name is Erik Postma. I manage the mathematical software group at Maplesoft: the team that writes most of the Maple-language code in the Maple product, also known as the math library. You can find a longer introduction at this link.

One of my tasks at Maplesoft is the following. When a request for tech support comes in, our tech support team can usually answer the request by themselves. But no single person can know everything, and when specialized knowledge of Maple's mathematical library is needed, they ask my team for help. I screen such requests, answer what I can by myself, and send the even more specialized requests to the experts responsible for the appropriate part of the library.

Yesterday I received a request from a user asking how to unwrap angles occurring in an expression. This is the general idea of taking the fact that sin(phi) = 'sin'(phi + 2*Pi), and similarly for the other trig functions; and using it to modify an expression of the form sin(phi) to make it look "nicer" by adding or subtracting a multiple of 2*Pi to the angle. For a constant, real value of phi you would simply make the result be as close to 0 as possible; this is discussed in e.g. this MaplePrimes question, but the expressions that this user was interested in had arguments for the trig functions that involved variables, too.

In such cases, the easiest solution is usually to write a small piece of custom code that the user can use. You might think that we should just add all these bits and pieces to the Maple product, so that everyone can use them -- but there are several reasons why that's not usually a good idea:

  • Such code is often too specialized for general use.
  • Sometimes it is reliable enough to use if we can communicate a particular caveat to the user -- "this will not work if condition XYZ occurs" -- but if it's part of the Maple library, an unsuspecting user might try it under condition XYZ and maybe get a wrong answer.
  • This type of code code generally doesn't undergo the careful interface design, the testing process, and the documentation effort that we apply to the code that we ship as part of the product; to bring it up to the standards required for shipping it as part of Maple might increase the time spent from, say, 15 minutes, to several days.

That said, I thought this case was interesting enough to post on MaplePrimes, so that the community can take a look - maybe there is something here that can help you with your own code.

So here is the concrete question from the user. They have expressions coming from an inverse Laplace transform, such as:

with(inttrans):
F := -0.3000*(-1 + exp(-s))*s/(0.0500*s^2 + 0.1*s + 125);
f := invlaplace(F, s, t)*u(t);
# result: (.1680672269e-1*exp(1.-1.*t)*Heaviside(t-1.)*(7.141428429*sin(49.98999900*t-
#         49.98999900)-357.*cos(49.98999900*t-49.98999900))+.1680672269e-1*(-7.141428429*sin
#         (49.98999900*t)+357.*cos(49.98999900*t))*exp(-1.*t))*u(t)

I interpreted their request for unwrapping these angles as replacing the expressions of the form sin(c1 * t + c0) with versions where the constant term was unwrapped. Thinking a bit about how to be safe if unexpected expressions show up, I came up with the following solution:

unwrap_trig_functions := module()
local ModuleApply := proc(expr :: algebraic, $)
  return evalindets(expr, ':-trig', process_trig);
end proc;

local process_trig := proc(expr :: trig, $)
  local terms := convert(op(expr), ':-list', ':-`+`');
  local const, nonconst;
  const, nonconst := selectremove(type, terms, ':-complexcons');
  const := add(const);
  local result := add(nonconst) + (
    if is(const = 0) then
      0;
    else
      const := evalf(const);
      if type(const, ':-float') then
        frem(const, 2.*Pi);
      else
        frem(Re(const), 2.*Pi) + I*Im(const);
      end if;
    end if);
  return op(0, expr)(result);
end proc;
end module;

# To use this, with f defined as above:
f2 := unwrap_trig_functions(f);
# result: (.1680672269e-1*exp(1.-1.*t)*Heaviside(t-1.)*(7.141428429*sin(49.98999900*t+
#         .27548346)-357.*cos(49.98999900*t+.27548346))+.1680672269e-1*(-7.141428429*sin(
#         49.98999900*t)+357.*cos(49.98999900*t))*exp(-1.*t))*u(t)

Exercise for the reader, in case you expect to encounter very large constant terms: replace the calls to frem above with the code that Alec Mihailovs wrote in the question linked above!

Hello all,

The following minimal worksheet leads to a "Kernel Connection Lost" message. At seemingly random times, I get a `System error, `, "bad id" message in the worksheet output instead.

Temporarily disabling ESET Internet Security did not help. Before I contact technical support, I would like to ask if there is anything obvious that I am overlooking that could cause this problem.

Thank you very much.

kernelopts(version);

`Maple 2021.1, X86 64 WINDOWS, May 19 2021, Build ID 1539851`

(1)

with(Iterator):

P := CartesianProduct([1,2,3,4],[1,2,3,4]):

add(p,p in P);


Download Minimal.mw

I don't know how overcoming this error . Thank you. MyPackage := module() export f1, f2; local loc1; option package; f1 := proc() loc1 end proc; f2 := proc( v ) loc1 := v end proc; loc1 := 2; end module: savelib('MyPackage'); Error, cannot open archive, C:\Program Files\Maple 2018\lib, for writing. restart; with(MyPackage); Error, invalid input: with expects its 1st argument, pname, to be of type {`module`, package}, but received MyPackage

x1^4 + x2^4 + 0.4*sin(7*x1) + 0.3*sin(4*Pi*x2) -1 = 0;
The task itself is not needed by anyone, it's just for rest and distraction from work.
(For example, this is not difficult to do with Draghilev's method.)




I have a system of equations that returns a RealRange :

xLp_tmp := RealRange(85.32914119, infinity)

it actually looks like this:
 

anyway, I want to "pick" the lowerbound of that range and assign it to a variable but I can't figure  out how to do it.  

I've tried:

xLp_tmp[1] 

lowerbound(xLp_tmp)

but neither worked.  I don't know what else to try.

Thank you in advance for the help.

Dear Forum, 

 

I want to make a Document where some values are initialised and left alone afterwards.
The startup-code seems to be the solution. The manual says, it is executed, when the document is reloaded.

But if i execute the document with "!!!" the startup-code is executed too. 
How can I avoid this ? 
Is there a good way to write "run once" code ?

 

Thank you very much

 

Klaus

startup code is  : 

init:=false;

After reloading, this should be false  init = trueNULL

the startup code should be executed after reloading but is executed when the code is executed with !!! . init is set to false again
If the code is executed stepwise , ! by ! , it behaves as expected.

if not init then x := 3; y := 4; init := true end if
 

2*x = 8NULL

x := 4

4

(1)

2*x = 8NULL

NULL

NULL

NULL


 

Download doesnotrunonce.mw

Dear esteem colleagues,

Please I am trying to plot a function using both implicitplot and contourplot. However, I found out that I have two different plots. What are the differences between them and perhaps which is better?

Thank you all for your time and best regards.

with(GroupTheory):
MinimumPermutationRepresentationDegree(PermutationGroup({[[2, 3], [4, 5]], [[2, 5], [3, 4]]}, degree = 5, supergroup = PermutationGroup({[[2, 3, 4]], [[1, 2], [4, 5]]}, degree = 5)));

#an error appears in Maple 2017
 

As a newbie I tried to do some simple calculations. Unfortunately one of my calculations does not solve. I assume I do not see the obvious. Would someone be so kind to help me out? Thank you
 

restart

with(LinearAlgebra)

pH := Vector(2, {(1) = 7.17, (2) = 7.25})

Vector[column](%id = 4598165698)

(1)

pCO2 := Vector(2, {(1) = 74, (2) = 56})

Vector[column](%id = 4696862338)

(2)

pK := 6.1

6.1

(3)

CO2 := `~`[`*`](pCO2, 0.3e-1)

Vector[column](%id = 4696842050)

(4)

HCO3 := `~`[`*`](`~`[`*`](0.3e-1, pCO2), 10^`~`[`-`](pH, pK))

Error, (in rtable/Power) exponentiation operation not defined for non-algebraic exponents

 

TCO2 := CO2+HCO3

28.30272572

(5)

VCO2 := 22.4*(28.3-25.41)*5.9

381.9424

(6)

NULL


 

Download test.mw
 

restart

with(LinearAlgebra)

pH := Vector(2, {(1) = 7.17, (2) = 7.25})

Vector[column](%id = 4598165698)

(1)

pCO2 := Vector(2, {(1) = 74, (2) = 56})

Vector[column](%id = 4696862338)

(2)

pK := 6.1

6.1

(3)

CO2 := `~`[`*`](pCO2, 0.3e-1)

Vector[column](%id = 4696842050)

(4)

HCO3 := `~`[`*`](`~`[`*`](0.3e-1, pCO2), 10^`~`[`-`](pH, pK))

Error, (in rtable/Power) exponentiation operation not defined for non-algebraic exponents

 

TCO2 := CO2+HCO3

28.30272572

(5)

VCO2 := 22.4*(28.3-25.41)*5.9

381.9424

(6)

NULL


 

Download test.mw

 

with(Student:-Basics); simplify((b - 1)/(b + 2 - (b^2 + 2)/(b - (b - 2)/(b + 1)))); b - 1 This is correct, but I want to see the step-by-step solution. P.D. I try the ExpandSteps command already but the result doesn't give me the solution. Please, help me. Thanks in advance

Is there an option or a tool to know if maple is trying to finish the calculation or if it is in a bucle?

Is there a Maple function that given a group gives its name?

In a calculation I am encountering expressions of the following kind:

-.27059805007310*sin(.12+epsilon)+.27059805007310*sqrt(1.-cos(.12+epsilon)^2)

As is known, for epsilon < Pi-0.12, the two terms are equal but opposite in sign and the result should be zero (ok, maybe a few 1E-15 for round-off). But for the heck of it I cannot get Maple to simplify this with the assumption e.g. epsilon < 0.1.

This can probably be simplified by squaring the two terms and then subtracting them, but that can possibly lead to other "interesting" effects and besides is a bit cumbersome.

Has anybody found a good way of  doing this?

Thanks,

M.D.

How to build a library (package) containing my own procedures ? Could you give me an example. Thank you.

Not_evaluating_theta.mw

 

When I tried to explain to a student how to set it up, it stopped working.  I tried changing the order, but got the same result. I tried using "t" instead of theta, but got the same result. Please help.

First 254 255 256 257 258 259 260 Last Page 256 of 2097