Maple 2018 Questions and Posts

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

Why does

MultiSeries:-series(LegendreQ(-1/2,x),x=-1))

not work?

series(LegendreQ(-1/2,x),x=-1))

seems to work, but does it give the correct result?

I actually thought there was a pole at -1.

Thx

PS: or is the cut between -1 and 1 with both logarithmic singularities?

I'm still wondering about the behaviour of MultiSeries

is there a way  for a proc() in a parent module to call an exported proc in a child module, without having to use long form of the call    child:-child_proc() and just do child_proc()?  Here is an example

A:=module()
  option package;
  export foo;
  local B; #child module

  B:=module()     
     export boo;
     boo:=proc()
        print("in B:-boo()");
     end proc;
  end module;
  
  foo:=proc()
     B:-boo();  #how can one just type  boo() here?
  end proc;
end module;

B:-foo(); now works ok. But I'd like to just use  boo() and not B:-boo() since the name of the child module is too long. 

I can't figure how to do it. I can't use with(B) in the parent, Maple complains. 

 

Hi 

I have a question about function as parameter in procedure

is it possible that I type 

f := x-> x+1

Test (f(x))

instead of Test(f) ? 

where Test is a simple procedure that takes in one function parameter 

Test := proc (f)
return f(1) + f (2) 

 

How am I going to evaluate function like this ? I tried signum evalf, eval and solve, they dont work

When a child proc calls a parent local proc using parent_module:-parent_proc(), Maple gives an error. But when the child calls the parent local proc using just parent_proc() it works. Why is that?

parent_module:=module()
 
 local child_module;
 local parent_proc;

 export parent_entry;

 child_module:= module()
    export child_entry; 
    child_entry :=proc()
     #parent_module:-parent_proc(); #this fails
     parent_proc(); #this works
    end proc;
  end module;

 #local
 parent_proc :=proc()
   print("insider parent proc");
 end proc;

 #public
 parent_entry :=proc()
   child_module:-child_entry();
 end proc;
end module;

parent_module:-parent_entry();
              "insider parent proc"

but the other way, (the commented code above) gives

parent_module:-parent_entry();
Error, (in child_entry) module does not export `parent_proc`

 

Bisection := proc (f, a, b, delta)

local startpoint, endpoint, midpoint; startpoint := a; endpoint := b;

do midpoint := (1/2)*startpoint+(1/2)*endpoint;

if abs(startpoint-endpoint) < delta or abs(f(midpoint)) < delta then

return midpoint

elif f(midpoint) < 0 then endpoint := midpoint

elif 0 < f(midpoint) then startpoint := midpoint

end if end do end proc

 

I'm trying to do a procedure for bisection method but it doesnt give me answer when  I type 

Bisection (x-> x + 0.001 , 1, -1, 0.001 )

it returns Bisection (x-> x + 0.001 , 1, -1, 0.001 )

why this is happening, Is it because the procedure is wrong ? or does not provide answer 

my main module is getting big. I want to break it to main module, and submodule. But now everything is in the same .mpl file. I'd like to put the sub module in seperate mpl file. I do not know the syntax to do this and how to do it. I looked at the programming guide chapter 8.

Currently in main_module.mpl, lets say I have this

main_module:=module()
 option package;
 local C; 
 local sub_module;
 export main_entry;

 C:=99; #see if this can be "seen" from child module

 sub_module:= module()
    export main_entry;
    main_entry :=proc()
     print("In main_module:-sub_module:-main_entry(), C=",C):
    end proc;
  end module;
 
 main_entry :=proc()
   print("in main_module:-main_entry()"):
   sub_module:-main_entry();
 end proc;
end module;

Now main_module:-main_entry(); gives

                 "in main_module:-main_entry()"
       "In main_module:-sub_module:-main_entry(), C=", 99


I'd like to move the code of the submodule to another .mpl file. So I end up with two files, like this

# main_module.mpl
main_module:=module()
 option package;
 local C; 
 local sub_module;
 export main_entry;

 C:=99; #see if this can be "seen" from child module

 main_entry :=proc()
   print("in main_module:-main_entry()"):
   sub_module:-main_entry();
 end proc;
end module;

And

#sub_module.mpl
sub_module:= module()
    export main_entry;
    main_entry :=proc()
     print("In main_module:-sub_module:-main_entry(), C=",C):
    end proc;
 end module;

But when I do this, I can't call main_module:-main_entry(); since it gives error

Error, (in main_entry) `sub_module` does not evaluate to a module
I do not want to make sub_module a separate package. I want it to remain a sub module for the main module, so it can only be seen by the main module and no one else.

So logically sub_module is a child of main_module, but physically I want to put them in separate files to make it easier to modify.

I use plain text files for everything and use Maple to load the packages and test.

How does one go about doing this? How would this be done for the above example?

 

I tried $include "sub_module.mpl"; but it gives error.

main_module:=module()
 option package;
 local C; 
 local sub_module;
 export main_entry;

 C:=99; #see if this can be "seen" from child module
	
 $include "sub_module.mpl";

 main_entry :=proc()
   print("in main_module:-main_entry()"):
   sub_module:-main_entry();
 end proc;
end module;

Where the file "sub_module.mpl" contains the code for the submodule I want to insert at that location. When I read "main_module.mpl" Maple gives error

read "main_module.mpl";

Error, on line 10, syntax error, unexpected string:
 $include "sub_module.mpl";

This is too advanced for me. I am still learning module and package use in Maple.

thanks

Hello all!
Can some one please help me in translating this code, for newton forward and backward interpolation, and get the same output in maple. I am not very good at matlab so that is why I am having problems converting it to maple code.

only forward or backward would be enough I am sure I will figure out the second myself.
https://www.codewithc.com/newtons-interpolation-in-matlab/

What is the best way to check if solve returned one or more solution? Currently I check if the returned sol is of type exprseq, and if so, I put the result in a list. If the sol is not of type exprseq, then I know only one solution is returned. Here is an example

foo:=proc(eq,x)
  local sol;
  sol:=solve(eq,x);
  if whattype(sol)='exprseq' then
     sol:=[sol];
  fi;
  return(sol);
end proc:

And now

Is there better way to do this?

 

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?

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