Maple 2018 Questions and Posts

These are Posts and Questions associated with the product, Maple 2018

Maple does not have a GOTO. I do ?goto and nothing comes up (I thought it did at one point, but it seems to be gone). I also saw 

99052-How-To-Write-Procedures-That-Use-Go-To-In-Maple

GOTO is considered bad, and I agree in general. But there ONE very good use for GOTO which can't be easily replaced, which is having a common exit label. (at one work place sometime ago, this was actually the only recommened use for it in the programming guidelines. and I agree.)

Without this, one ends up with deep if then else if then else if then else., etc....

But having a common exit, where one can do common clean up things is very good. This reduced code duplication and actually makes the logic more clear.

Here is just some silly example to  illustrate

foo:=proc(x)
  if x=10 then
     .....
    close file, print common message
    return(final_result);
  fi;

  if x=12 then
     .....
    close file, print common message
    return(final_result);
  fi;

 etc...

end proc;

With common exit point, one could do

foo:=proc(x)
   if x=10 then 
      .....
     final_result :=...
     goto common_exit;
   fi;

   if x=12 then 
      .....
     final_result :=...
     goto common_exit;
   fi;

common_exit:
   close file; 
   print common message;
   return(final_result);

end proc;

The alternative is to have deep  nested if then else, like this

foo:=proc(x)
    if x=10 then 
       ..... 
       final_result :=...;
    else
         if x=12 then 
            ..... 
            final_result :=...;
         else
             if x= 20 then
                .....
                final_result :=...;
             fi;
         fi;
   fi;

  close file; 
  print common message;
 return(final_result);
end proc;

For complicated logic, I do not think the last case is better than the second one using GOTO.

The second case also eliminates duplicate code as was done in first case. Also first case has multiple return points from the proc, which is not good. As having one common return point is better.

Why was goto removed from Maple? Can one still use it somehow? Where is the documenation for it?

update

 

goto seems to be there. I did not think of trying, since ?goto did not show it. But now I found I could do this and it works

foo:=proc()
  local x;
  x:=10;
  goto(common_exit);
  x:=20;
common_exit:
  print(x);
end proc;

So please Maplesoft., do not remove GOTO.

Larson 6th edition gives the following solution; 

However, LineInt(VectorField(`<,>`(x, y)), Path(`<,>`(4*t, 3*t), t = 0 .. 1))

returns 25/2 and 

LineInt(VectorField(`<,>`(x, y)), Path(`<,>`(4*t, 3*t), t = 0 .. 1), output = integral)

returns

Int(25*t, t = 0 .. 1)

Why are the solutions different?

lineInt.mw

 

I am stumped at this.

I made a proc A which takes arguments using keywords. When I call A directly, it works. When I pass the argument I want to call A with to another proc B, and then from B call A with that argument, it fails. Maple tells me that it missing arguments. Here is a MWE

restart;
procA := proc({the_equation::`=`:=NULL})
  print("it worked, you passed in ", the_equation);
end proc:

procB :=proc(the_equation)
  print("inside procB, the equation is ", the_equation);
  procA('the_equation'=the_equation); 
end proc:

 

Now, calling procA directly, works

the_equation:= y=3:
procA('the_equation'=the_equation);

              "inside procA, you passed in ", y = 3

But when caling procB, and then have procB call procA, the argument passed in is NULL

procB(the_equation);

                  "inside procB, the equation is ", y = 3
                 "inside procA, you passed in "  <=== WHY NULL?

   

 

 

I must be doing something wrong, I just do not see it.

Update: rebooting the PC fixed this error for me. Now help comes up OK.

original question:

I am on windows 7, home editon, running Maple 2018.

For some reason, now each time I tried to get help, I get the message that it lost connection with server. I closed Maple, started it up again, and same error happens. Movie below.

This also happend from new worksheet also Each time I type ?anything I get the above.

 

Any idea what can cause it? and where I should look for errors?

I did not nothing before this to anything on system. Was just editing some worksheet which opens fine. It is only help that seems to be having hard time.

 

 

CODE:

sys_ode := 2*C__5*(diff(w(x), x))-C__1*(diff(u(x), x, x))-2*C__4*(diff(w(x), x, x, x))-Q(x) = 0, 2*C__2*u(x)-C__1*(diff(w(x), x, x, x))-2*C__3*(diff(u(x), x, x)) = 0

ics := (D(u))(0) = 1, ((D@@2)(w))(0) = 0, (D(u))(100) = 1, ((D@@2)(w))(100) = 2

 

NOTE:

C__1 to C__5 are constants. 

Following is the screenshot, is there anything wrong with my code?

Thanks for any answer or suggestion!

I downloaded alglib from 

http://algo.inria.fr/libraries/obsolete-releases.html

Downloaded the .mla and the .hdb files. Put them in current directory where my worksheet .mw is.

Opened the .mw and typed

restart;
libname := currentdir(), libname;
_algolibcontent();

Content of algolib (version 14.0), as of October 2010:

+ encyclopedia.            [Written by Stéphanie Petit, with contributions by Bruno Salvy and Michèle Soria.]
+ gdev.                [Written by Bruno Salvy.]
+ gfun (version 3.53).        [Maintained and extended by Bruno Salvy, with contributions by Ludovic Meunier, Marc Mezzarobba, Marni Mishna, and Eithne Murray, original version by Bruno Salvy and Paul Zimmermann.]
+ Holonomy (version 3.4).    [Written by Frédéric Chyzak.]
+ MAD (version 1.445).        [Written by Ludovic Meunier.]
+ Mgfun (version 4.1).        [Written by Frédéric Chyzak, with contributions by Shaoshi Chen, Cyril Germa, Lucien Pech, and Ziming Li.]
+ MultiSeries.            [Written by Bruno Salvy.]
+ regexpcount (version 1.5).    [Written by Pierre Nicodème.]
 

Ok. Now how to obtain help? I can call one of its functions, like this

MADLaTeX:-latex(1/2);

    \frac{1}{2}

 

But I do not know how to find help on MADLaTeX:-latex since ?MADLaTeX does nothing and ?MADLaTeX:-latex does nothing. 

How to obtain the help pages for this package? I looked online and do not see anything. I do not know what to do with the .hdb file that I downloaded. I am using Maple 2018 and it does not seem to support .hdb files anyway. 

Does I need to go through all the conversion steps described in

https://www.maplesoft.com/support/help/Maple/view.aspx?path=HelpTools%2fMigrate

just to see help on one function? 

I just need to find how to call is Latex function and if it has any options. Any one knows an online page that have these on it?

After solving something, sometimes the result comes in piecwise. I'd like to just obtain all those results which are not undefined, into a list, so I can process them more easily. I am not sure what is the correct way to do this in Maple.

Here is an example.

restart;
f := piecewise(x>-1 and x<=0, x^3, 
               x>0 and x<=Pi/2, sin(x), 
               x>Pi/2, undefined, 
               x=20, 5, 
               x=50, undefined);

I need to pick all entries that do not have "undefined". I do not need the rhs condition  which is x<=1. So for the above, I'd like to obtain

                               sol:=[ x^3, sin(x), 5]

If there more entries which are also not undefined, they go into the list in order. 

when I do 

sol:=convert(sol,pwlist,x);

This gives     

sol := [0,-1,x^3,0,sin(x), (1/2)*Pi,undefined,20,undefined,20,undefined,50,undefined,50,undefined]

Now it gets confusing. How to change the above to 

       sol:=[ x^3, sin(x), 5]

I do not even understand the conversion result above. I do not know why it gives 50 twice. And I do not even see the "5" in there. So I do not know how to decode this now.

Update:

I found this solution. But it might not be best:

contents :=[op(f)];
[seq(`if`(contents[i]=undefined,NULL,contents[i]),i=2..nops(contents),2)];

gives

              [x^3, sin(x), 5]

When I have an Operator like

eq:=1/r*diff(r*diff(f(r),r),r)

typically maple evaluates/expands it by product rule.

How can I tell him to not do it?

I tried using the inert operator % but probably i didn't do it right.

I am learning patmatch. And found strange problem.

When I make an expression inside a proc A, and pass this expression to another proc B, which then uses patmatch  on it, the pattern fails to match.

but calling proc B directly, with exactly same expression, patmatch does match.

This is confusing and not sure why it happens. It seems related to using symbol which was declared local vs. same symbol but is global. Here is an example

restart;
foo:=proc()
  local x,C1;
  boo(exp(C1+x));
end proc;

boo:=proc(expr)
  local a,b,c,la;
  patmatch(expr,a::anything*exp(b::anything*C1+c::anything),'la');
end proc;

Call to foo() returns false. But call to boo() returns true. Even though I am using same expression.

foo();
   false


C1:='C1':
x:='x':
boo(exp(C1+x));
   true

  

What Am I doing wrong, and how to make it work in both cases?

Hello everyone!

I miss a convinient way to build interactive plots with parameters assigned to sliders. E.g. of such expressions as "a*sin(b*x+c)". Before Maple 2017 I could just right-click the expression, choose "plot builder" and then select "interactive plot with three parameters". That's it. Since the introduction of the new interactive plot builder I am at a loss because that way have been lost and I don't know any other way equally quick and convinient. "Interactive plot builder" now means quite another thing!

Any suggestions?

 

 

Probably I'm doing something severely wrong, but

sum(x^n,n=0..infinity)

does not evaluate to the geometric series result 1/(1-x), why?

Similarly this happens for the sum(x^n/n,n=1..infinity)

 

It works with Maple17 though.

Hi everyone !!

I have a problem to find a solution for some symbolic nonlinear equations. I used the solve command but it takes much time and finally, I stopped the process because doesn't give me a solution. I have attached the code. 

Please, help me

 

Cond_Poincare.mw


 

I*mu*A(t[2])*omega[0]*(1/2)-A(t[2])*omega[0]*(diff(B(t[2]), t[2]))+I*(diff(A(t[2]), t[2]))*omega[0]-(1/4)*A(t[2])^5*beta[2]*omega[0]^2-(1/4)*A(t[2])^3*beta[1]*omega[0]^2-(1/2)*F[0]*exp(I*sigma*t[2]-I*B(t[2]))+5*alpha[2]*A(t[2])^5*(1/16)+3*alpha[1]*A(t[2])^3*(1/8);

((1/2)*I)*mu*A(t[2])*omega[0]-A(t[2])*omega[0]*(diff(B(t[2]), t[2]))+I*(diff(A(t[2]), t[2]))*omega[0]-(1/4)*A(t[2])^5*beta[2]*omega[0]^2-(1/4)*A(t[2])^3*beta[1]*omega[0]^2-(1/2)*F[0]*exp(I*sigma*t[2]-I*B(t[2]))+(5/16)*alpha[2]*A(t[2])^5+(3/8)*alpha[1]*A(t[2])^3

(1)

simplify(%);

-(1/2)*F[0]*exp(-I*(-sigma*t[2]+B(t[2])))+I*(diff(A(t[2]), t[2]))*omega[0]+(1/2)*(-2*(diff(B(t[2]), t[2]))*omega[0]+(-(1/2)*beta[2]*omega[0]^2+(5/8)*alpha[2])*A(t[2])^4+(-(1/2)*beta[1]*omega[0]^2+(3/4)*alpha[1])*A(t[2])^2+I*mu*omega[0])*A(t[2])

(2)

subs(C(t2)=-sigma*t2+B(t2),%);

-(1/2)*F[0]*exp(-I*(-sigma*t[2]+B(t[2])))+I*(diff(A(t[2]), t[2]))*omega[0]+(1/2)*(-2*(diff(B(t[2]), t[2]))*omega[0]+(-(1/2)*beta[2]*omega[0]^2+(5/8)*alpha[2])*A(t[2])^4+(-(1/2)*beta[1]*omega[0]^2+(3/4)*alpha[1])*A(t[2])^2+I*mu*omega[0])*A(t[2])

(3)

 


Download no_change.mw


 

 

C_t := -A(t)*omega[0]*(sigma-(diff(C(t), t)))-(1/4)*A(t)^5*beta[2]*omega[0]^2-(1/4)*A(t)^3*beta[1]*omega[0]^2-(1/2)*F[0]*cos(C(t))+5*alpha[2]*A(t)^5*(1/16)+3*alpha[1]*A(t)^3*(1/8) = 0;

-A(t)*omega[0]*(sigma-(diff(C(t), t)))-0.3297500000e-1*A(t)^5*omega[0]^2-0.8345000000e-1*A(t)^3*omega[0]^2-cos(C(t))+0.4059375000e-1*A(t)^5+.1249125000*A(t)^3 = 0

(1)

 

A_t := (1/2)*mu*A(t)*omega[0]+(diff(A(t), t))*omega[0]-(1/2)*F[0]*sin(C(t)) = 0;

0.5000000000e-2*A(t)*omega[0]+(diff(A(t), t))*omega[0]-sin(C(t)) = 0

(2)

 

F[0] :=2: w0 := 1: alpha[1]:=0.3331:alpha[2]:=0.1299:beta[1]:=0.3338:beta[2]:=0.1319:mu:=0.01:sigma=0:

sigma = `0:`

(3)

 

C_t;A_t;

-A(t)*omega[0]*(sigma-(diff(C(t), t)))-0.3297500000e-1*A(t)^5*omega[0]^2-0.8345000000e-1*A(t)^3*omega[0]^2-cos(C(t))+0.4059375000e-1*A(t)^5+.1249125000*A(t)^3 = 0

 

0.5000000000e-2*A(t)*omega[0]+(diff(A(t), t))*omega[0]-sin(C(t)) = 0

(4)

ICS:=[C(0)=0,D(C)=0,A(0)=1,D(A)=0]:

sol:=dsolve({C_t,A_t,ICS},[C(t2),D(C),A(t2),D(A)],type=numeric):

Error, (in dsolve/numeric/process_input) system must be entered as a set/list of expressions/equations

 

pRange:=0..20:

 Atime:=odeplot( sol, [t, A],t=pRange, numpoints=10000 ):

Atime;

odeplot(sol, [t, A], t = 0 .. 20, numpoints = 10000)

(5)

 


 

Download phase_plot.mw

Currently, I have some definitions of modules and or functions in one worksheet, say A.

To reduce clutter in A, I'd like to open second worksheet, say B, and invoke the functions defined in A in the B worksheet. This way I keep the definitions in one worksheet, and the tests/trying them, in another worksheet.  I do this all the time in Mathematica. It useful, as I like to keep one notebook for just definitions, and second one for testing and calling the functions.

I just found out, that a function defined in worksheet is not "seen" in worksheet B.  I looked at options and settings, googled a little, but not able to find an option to allow me to do this. I tried Tools->General->Share one engine among all documents. Clicked Apply. But that still did not do it.  From worksheet B, it tells me it does know the function I am trying to call. Only in worksheet A it can see the function.

Is there an option to allow one to have the function definition be seen on all open worksheets?

I know I could save the functions as mpl files, and then load them in the second worksheet. But during development, the first method is easier.

First 54 55 56 57 58 59 60 Page 56 of 61