nm

8552 Reputation

19 Badges

13 years, 31 days

MaplePrimes Activity


These are questions asked by nm

I have a function inside a file called proc2.mpl

When I read the file from a worksheet using the command read("proc2.mpl"); I see warning messages

Warning, incomplete string;  use " to end the string
Warning, incomplete string;  use " to end the string

printed on the screen.  Now if I copy the same exact code and past it into the worksheet and invoke the function, I see no warning messages.

Why is that? Here is the content of "proc2.mpl"

process_file := proc()
  local str,fileName;


  fileName := "output.txt";
  
  str:="
   \\begin{align*}
     A =& B  \\\\ 
       =& 3
   \\end{align*}
  ";
	
  writebytes(fileName, str);
  close(fileName);

end proc:

Here is screen shot loading the function from worksheet

But now when I call it using process_file(); it works as expected.

Now here is screen shot with same code inside the worksheet itself. No warning messages show up when I call it.

And the above call also works as expected.

So I am now ignoring these warning messages since I also do not know what causes them.

Any ideas why they show up when the code is inside a .mpl file and not in the work sheet?

Maple 2017.3 on windows.

 

 

 

I want to save multiline string to a file. I am not sure Maple likes my string. Also when I look at the textfile after writing the string to it, the string does not look like what is expected. I given small example

First, created a "proc.mpl" in the folder. Here is the content of "proc.mpl"

process_file := proc()
local str;
  
str:="
   \\begin{align*}
     A =& B \\\\
       =& 3
   \\end{align*}
";

FileTools[Text][WriteString]("output.txt", str);
FileTools[Text][Close]("output.txt");

end proc:

Then opened Maple, and from a worksheet, called the above proc() like this

restart;
currentdir("C:\\where_the_file_is");
read("proc.mpl");
Warning, incomplete string;  use " to end the string
Warning, incomplete string;  use " to end the string
Warning, incomplete string;  use " to end the string
process_file();

You see these warnings there. So how does one make a multiline string in Maple? Please tell me it is possible. Else this whole process will not work.

When I look at the "output.txt", where the string is written, this is what shows


   \begin{align*}
     A =& B \      =& 3
   \end{align*}

Which is wrong, I expected this


   \begin{align*}
     A =& B \\     
        =& 3
   \end{align*}

 

I use \ to escape each \, since this is Latex code. 

QUestions are:

1) Can one have multiline string in Maple? as in

"
line one
line two
"

With implied carriage return, just as it appears in the input?  I do this all the time in Mathematica.

2) Is something wrong with how I am saving the string to the file?
 

On a side note: I noticed I had to close the textfile to see the output in it. It looks like FileTools[Text][WriteString] does not flush the string autmatically to a otuput file after each write() which is a little annoying.

Using Maple 2017.3 on windows.

This is how the above is done in Mathematica

And this is "test.txt" which shows the output as expected

   \begin{align*}
     A =& B \\
       =& 3
   \end{align*}

I'd like to do the same in Maple.

First, is patmatch command is the main Maple command for doing pattern matching on expressions?  

I trying to understand how it works, but failing on the most basic expressions. 2 basic questions

1)patmatch( x^n/y^n,  x∷symbol^n::symbol /  y::symbol^n::symbol);
                               false

It did not like that I told it x::symbol in the above. Why? But when I remove ::symbol it works

patmatch(x^n/y^n,x^n::symbol/y^n::symbol);
                   true

But when I do "whattype(x);" Maple replies saying it is "symbol"

2)Trying to match x^2/y^2, not having any luck
patmatch(x^2/y^2,x^n::nonunit(integer)/y^n::nonunit(integer));
                        false

patmatch(x^2/y^2,x^n::integer/y^n::integer);
                         false

How to match x^2/y^2? Why the above fail? 

I learn better by examples. Is there a place where one can look at many examples using patmatch? 

The help page have only few examples, and the link to the page called "examples,patmatch" does not help either with few examples and many are the same as the other page.  I tried to run it using 

infolevel[all]:=5:
printlevel:=10:

To see if I can figure what is wrong, but did not understand any of the code printed.

Compare this to Mathematica, where pattern matching there has hundreds of examples and detailed tutorials just on this one subject.

 



   


 

 

Given an expression such as (x^2+1)*y^3*exp(-x-y), how to "factor" it to product of the two functions, one in x only and the other in y only. These products in this example are

                  exp(-x)*(1+x^2)

and

                 exp(-y)*y^3

For reference, this was also asked at Mathematica site here

addition:

Is it possible to obtain these separated products in a list or a set to make them easier to get hold of after the call? something like

   myFactor(  (x^2+1)*y^3*exp(-x-y) , {x , y} )

will return

    { exp(-x)*(1+x^2) , exp(-y)*y^3 }

This is current test cases

funcs:=[
   arcsin(x)/(sqrt(1-x^2)*y^2),
   x*y,
   x^2+x^2*y,
   2*x+1,
   cos(2*x),
   y,
   (x-1)/y,
   ln(1+y^2),
   1-x+y^2-x*y^2,
   x^2+x^3*y,
   1/(x+y),
   (1+sqrt(x))/(1+sqrt(y)),
   (1-x^2+y^2-x^2*y^2)/x^2,
   2*x*y^2+3*x^2*y^2,
   3*exp(2*x)+2*y,
   (5*sqrt(x)-y)/x,
   2*x*y+3*x^2*exp(x^2),
   sqrt(1+x+y^2),
   1,
   1+x*y,
   -y+4*x^3*y,
   exp(x^2)+2*x*y,
   -(y-exp(x))/(x-2),
   arcsin(x)/((1-x^2)*y^2),
   -(y-exp(x))/(x-2),
   -y+4*x^3*y,
   (x^2*y+y)*y^3*exp(-x-y+1)*3^(-x-y)*sqrt(x^2*y-y),
    sqrt(1-y^2)/x,
    sqrt(1-y^2)/(2*sqrt(x)),
    sqrt(1-y^2)
];

This functions checks if expression is product separable or not

is_separable:=proc(f,x,y)
  #checks if f(x,y) is separable to X(x)*Y(y) or not
  #but do not do the separation. The separation is done by
  #another function I have

  if diff(simplify(diff( simplify(ln(f)),x)),y) = 0 then
     return(true);
  else
     return(false);
  fi;
end proc:

it used as

for z in funcs do
   is_separable(z,x,y);
od;

 

I just found that Maple 17 and Maple 16 do not have the option "output=string" in the latex command.

And I need a way to convert the Latex generated to the screen to a string and save it to a variable like I can do with Maple 2017

Here is an example. In current Maple 2017 this works

result_of_int:=int((-5+3*x)^2/(2*x-1)^(7/2),x):
my_latex:= latex(result_of_int,output=string);

But in Maple 16, it gives an error

If I remove the output, then the result is not string.

How to capture the above output which is on the screen and save it as string in a variable?

I do not want to send the output to a file as is. I need to first convert it to a string, and save
it to variable first.

 

 

First 128 129 130 131 132 133 134 Last Page 130 of 164