nm

11353 Reputation

20 Badges

13 years, 12 days

MaplePrimes Activity


These are replies submitted by nm

@dharr 

Thanks. Your method works for polynomials. But what I am looking for is for any general expression and any general term. For example, given expression y(x)^4*diff(y(x),x)^2+y(x)^2*diff(y(x),x)^2+y(x); and the term is y(x) then it should return y(x)^2*(2*diff(y(x), x)^2 + 1)  and for the same expression, if the term was diff(y(x),x) then it should return diff(y(x),x)^2*(y(x)^4+y(x)^2); instead.

I tried to make your method work by substitution but that does not work well. For example if I replace y(x) by then this mess up the diff(y(x),x) terms there and they become zero. I could workaround this by converting to D form first. I am working on it.

Such a simple problem, we do by hand so easily all the time (just pull common factor out), but it seems hard to do using CAS.  May be it needs  frontend or freeze/thaw like you said. will keep trying. 

@Carl Love 

Fyi;

Maple gives an error when I put the base class and the extending class under a module.

I want to have all the modules be in same name space. So I have a top most module, say which just acts a name space to put all my code below it. So when I put the animal base class (module) and also the dog class (module) inside A, now Maple complains.

restart;

A:=module()
   export animal:= module()
      option object;
      export data1;
      export move::static:= proc(_self, $)
             print("In Animal class. moving ....")
      end proc;
    end module; #end base class
 
    export dog:= module()
        option object(A:-animal);  #PROBLEM IS HERE
        local ModuleLoad:= proc()
            move::static:= proc(_self, $)
                print("In dog class. moving ....")
            end proc;
           return
        end proc;
        ModuleLoad()  
    end module; #end extending class

end module;

I had to make animal class and dog class export, to be able to do   Object(A:-dog) later on, otherwise, can't access it if it is local. But even if dog module was local, same error results.

Maple gives the error

    Error, (in A:-dog) `A` does not evaluate to a module

This means I can't use this set, if I can put these inside the top most module. I do not want these modules to be seen from outside without having the prefix A:- 

I tried few things to workaround it, but so far,. no success. The problem is when doing 

             option object(A:-animal);

Maple still does not see as module, since it is partially evaluating it and this is not complete yet. It looks like it does one pass only on the module.  If I use just option object(animal); then now Maple gives error 

Error, (in A:-dog) argument of option object(animal) must refer to another object

So it seems this setup only works when both class (base and extending) are top level module. But this would not work for me. I need everything to be roots under same root module A.

I should add that this limitation has nothing to do with your solution. The original example I showed will also not work if I put them inside a root module. It seems just a limitation in Maple in that it does not allow option(A:-module_name) inside module A. This means all the objects I use (and want to extend) must now be top level (not under a module), which could conflict with any user's global object happend to be named the same. This is too bad. I hope Maple can fix this limitation in future release. 

Maple 2021.2

@Carl Love 

Hello Carl. Thanks for the answer to the other question. I simply had no idea someone gave another answer to it. That is all.

Since Mapleprimes does not  provide notification telling one they had reply or a comment, how is one supposed to know?

In Stackexchange, when I login, I see in red marker that I have notifcation in my inbox. There is nothing like this in this forum. 

And I do not always remember to go check old questions or answers looking for if there is any replies.  Unless it happened to be on first page and I see it.

I will test your code there now and see how it works. I am sure it will work well.

Thanks again for your answer.

regards

@Mac Dude 

I must be overlooking something. But there is no "type extension" here. dog() call just returns a module. This module does not even share the attributes of the base class Animal. 

Buster:=Animal:-dog();
Buster:-move();
Buster:-data1;

Error, module does not export `data1`

While when doing   option object(animal); now the new object has access to all base class animal data and methods.

How is this method you showed any better than just making a separate dog class?  As in

dogClass:=module()
   option object;

       export move:=proc(_self,$)
         print("In dog class. moving ....");
       end proc;  
end module;


Buster1:=Object(dogClass);
Buster2:=Object(dogClass);
etc...

But I agree with you in that Maple is not a true OOP language. I now just use Object as a "record" in other langauges (or "struct"). Where I have common data in one place. Then pass this object from one call to another. Just like when one passes a struct between functions in C.

@dharr 

"I think you wanted print(p) in B."

Yes ofcourse. Last minute change, forgot to update. Now typo fixed. The image is still not expored to a file. 

I nerver used interface(plotdevice=ps, etc...) before.  I am following https://maplesoft.com/support/help/maple/view.aspx?path=plotsetup  where it says to use plotsetup.  

But I just tried your suggestion, and it still did not work I am afraid.   now A wil call B1.


 

restart;

currentdir("C:\\tmp\\TEST_MAPLE");
p:=DocumentTools[RunWorksheet]( "B1.mw" , [the_function=sin(x),the_variable=x]  ):
print("Back from calling worksheet B. Here is the result");
p;

"C:\tmp\TEST_MAPLE"

"Back from calling worksheet B. Here is the result"

"OK"

 


 

Download A.mw

This is B1.mw. tried interface(plotdevice=ps, plotoutput=filename );  and interface(plotdevice=postscript, plotoutput=filename );


 

Inputs

 

the_function:=0;

the_variable:=0;


full_file_name:=cat("C:\\tmp\\TEST_MAPLE\\tmp.ps");
interface(plotdevice=postscript, plotoutput=filename );
plot(the_function,the_variable=-2*Pi..2*Pi):
return "OK";

 


 

Download B1.mw

 

@Rouben Rostamian  

"The format of the font specification is defined in ?plot,options under the "font" entry. Your specification axesfont=[12,12] does not fit that specification. Maple does not complain about that in the worksheet mode."

I am getting these errors. May be we are using different versions? (not able to post an image)

plot(sin(x),x=0..2*Pi,axesfont=12);
Error, (in plot) expecting option [axesfont, axes_font] to be of type list but received 12


plot(sin(x),x=0..2*Pi,axesfont=[12,12]);  #works OK
 

 

@vv 

It is not that easy. The issue becomes what value of slope to choose? 

Compare 

restart;
f:= (3 - 2*x)*exp(5*x);
f1:= diff(f, x):
maxslope:=100:
ff:=piecewise(abs(f1) < maxslope, f, undefined):
plot(ff, x=0..2*Pi);

With the result if using slope=5000 say

This choice worked better for this function as it shows more relevent parts.  But I will try setting some large slope value and run the program and see how the plots look like as there are 10's of thousands of functions to plot.  This will take 1-2 days to finish. This looks like a good solution until Maple smart view becomes more smart :)

 

 

 

@ecterrab 

Thanks for the quick fix. I confirm it is fixed in Latest Physics update. It it great job you are doing by giving fixes so quickly in these updates instead of one having to wait a year or so for a new version of Maple to get the fix.

I have found few more problems  elsewhere in Maple 2021.1 in the last 2-3 months, but I send these to technical support in emails already so I did not post them here.

The only main problem that remains for me with using Maple, is that timeout does not always timeout anywhere near the timeout value given all the time. I still see cases where it hangs or takes much much longer than the timeout value.

But I talked about this many times before so will not bring up anymore. I have many examples showing this. I'll wait for Maple 2022 to see if this problem is hopefully finally resolved.

Thanks again for your support.

@Preben Alsholm 

I think you did not get the errors when you simplified the integrand, is because of the call to simplify() being made before int(). This causes something to be loaded and changes memory layout?

To show this, I used the simplified version of the integrand (copied from different worksheet so I do not have to call simplify()) and repeated things, and now it fails.

 

Now repeated the same thing, but used simplify()  like you did, and the error went away.

This tells me that it has nothing to do with the simpler version of the integrand. It is due to the call to simplify() before which caused something to be loaded which had the side effect of removing the error.

To proof this more. I kept the original integrand, but loaded something else. Calendar package. And now i am not able to reproduce the error no matter how many times I tried.

Removing the call to Calender. Closing Maple. Starting again, and now tried it, and got the error back: of course Calender package has nothing to do with int() command. but this shows that it seems to be a memory layout or something related as loading something before, even if not related causes different behavior. These were all done after starting Maple again each time with nothing else running in Maple.

 

 

issue_int_nov_11_2021_simplified_version.mw

Download issue_int_nov_11_2021_simplified_version_2.mw

issue_int_nov_11_2021_with_calender.mw

issue_int_nov_11_2021_no_calender.mw

@itsme 

I do not have any custom stuff in my ~maple folder. Never used it actually. I am on windows.  I do not have anything special installed for Maple. I use the original Maple installation but do install the Physics package as extra using the command Physics:-Version(latest).  I have updated Physics just 2 days ago also. I do not think this is related to Physics as I have not even used it or loaded it in this example.  This is single user PC sitting on my kitchen table. Nothing fancy going on here. No network installation, etc.. 

It just seems it depends on how memory is allocated in Maple at the time, and it seems random.   

@itsme 

"But I completely disagree with you that an option to do this should not be available"

I did not agree with the design that Maple latex generator should try to do automatic line wrapping to help the end user. I think it is the wrong place to do so. But I never said it should not be available. I said at the end this 

"May be a new setting called     donotaddlinebreak which will override linebreak and linelength settings?"

So users can have a choice. That is all. For those who want automatic newlines added, they can choose so. But for those who do not, can choose so.

Playing with values for linelength setting is not the correct way to do this, even though setting linelength to 10^6 would prevent automatic linewrapping in most practical cases.

The issue of long math display in Latex have been around for decades and there are many solutions for this in Latex itself using packages and other math environments. If you look at tex site at stackexchange for example you will see many examples and solutions.  

@ecterrab 

For me, the latex generator software should just generate correct Latex and not try to guess things related to what the final paper width could be and add line breaks to "help" the user. I do not think that is the right place to do this. 

It should leave the Latex as is, no matter how long it is, and let the the actual Latex compilation phase worry about these issues. Trying to guess what the page width will be and trying to help by adding lines breaks in the middle can make things worst and might not be what the end user wanted.

There are many ways to handle these in the Latex compiling stage that the user can choose to do. Such as using breqn package, or  the user might be using landscape mode, or by using the geometry package, or by using the gather environment which shrinks math to page width, and so on.

My point is, the Latex generator should not try to anticipate what the physical paper width is and try to help the user by doing automatic line breaks. In the example I showed, it lead to an output which does not look good and not what is expected and is different from what shows on the screen. I remember you once said that the Latex generated sould match what shows on the screen (worksheet Maple output). In this case, it does not.

but for now, I set linelength=100000 in the settings. I did try breaklines=false which the help shows as possible option, but I got an error saying

Error, (in latex:-Settings) wrong left-hand-side in breaklines = false

Even though help says the default is false. I wanted to be sure.

May be I am doing something wrong. If one can turn off this breaking lines feature, regardless of the linelength setting, then that will be even better, so that the user could have a choice to use it or not. and not worry about the linelengtn setting.

May be a new setting called     donotaddlinebreak which will override linebreak and linelength settings?

But for now linelength=100000 seems to have done the trick. Hopefull, I will not have a latex expression generated longer than this.

regards

@ecterrab 

I found a case where PDEtools:-Solve can't solve for the unknowns in the equation. May be I am not understanding  some of the functionality. It works on some equations but not on others, when I was testing it. Here is an example where it can not solve it

restart;
eq:=-4*c1*sin(2*x)+4*c2*cos(2*x)+2*c3*cos(2*x)-8*c3*x*sin(2*x)+2*c4*sin(2*x)+8*c4*x*cos(2*x) = 3*x*cos(2*x);
the_constants:={c1, c2, c3, c4};
PDEtools:-Solve(eq,the_constants,independentof = x);

Here it seems to hang. Waited for more than one hr. While

restart;
eq:=-4*c1*sin(2*x)+4*c2*cos(2*x)+2*c3*cos(2*x)-8*c3*x*sin(2*x)+2*c4*sin(2*x)+8*c4*x*cos(2*x) = 3*x*cos(2*x);
sol := solve(identity(eq,x),{c1,c2,c3,c4});

Gives the answer immeadiatly

Also Solving this by "hand", by comparing terms gives

restart;
eq1:=-4*c1+2*c4=0;
eq2:=4*c2+2*c3=0;
eq3:=-8*c3=0;
eq4:=8*c4=3;
the_constants:={c1, c2, c3, c4};
PDEtools:-Solve([eq1,eq2,eq3,eq4],the_constants);

Here is an example where it works:

restart;
eq:=-3*c1*exp(-x)+cos(x)*(-3*c2-c3)+sin(x)*(-3*c3+c2)=exp(-x)+2*cos(x);
PDEtools:-Solve(eq,{c1,c2,c3},independentof=x)

Which agrees with the "manual" solution

restart;
eq1:=-3*c1=1;
eq2:=-3*c2-c3=2;
eq3:=-3*c3+c2=0;
PDEtools:-Solve([eq1,eq2,eq3],{c1, c2, c3});

Why did the first example above not solve it?

 

@Preben Alsholm 

        "This works:"

I am afraid it does not work.

expr:=x^2*A[2]+A[1];
select(type,expr,identical(x^2) &* anything);

gives 0

Maple 2021.1

 

 

@Joe Riel 

             "Try changing anything to indexed"

this does not really help. First, it has to work for any expression. I do not know what is being multiplied by x^2. This was just an example.

restart;
expr:=3*x+sin(x);
select(type,expr,'`*`'({anything, identical(x^2)}));

gives 3*x also. I needed something similar to pattern matching

patmatch(3*x^2,a::anything*x^2,'la');la

works

 but

patmatch(3*x,a::anything*x^2,'la');la

does not as expected.     But need to do it using structured types, just to learn it better as it is "supposed" to be the better way to do this, but I find it much confusing than using simple patterns.

 

 

First 35 36 37 38 39 40 41 Last Page 37 of 91