nm

11353 Reputation

20 Badges

13 years, 13 days

MaplePrimes Activity


These are replies submitted by nm

no, there is no such thing, and there will never be such thing in CAS. It makes little sense and will cause all sort of problems.

Simplify write the ODE as normal using diff(y(x),x)

 

@Scot Gould 

but you did not mention the most important thing: did it autoscroll for you? i.e. when the print lines reach the bottom of the screen the first time, does it autoscroll so the last line being printed always shows up at the bottom of the screeen without having to manually scoll down to see it?

The whole reason I try to grab the bar on the right with the mouse, is to try to chase those lines being printed so I can see the last lines so I know the progress of the program.

 

@baharm31 

 If I add numeric I get an error.

I get no error on 2020.1

restart;
ode1:=-diff(q(t), t) - 1.851851852*10^(-7)*q(t)*(2.042885233*10^10 - 3.517396152*10^18*(0.00001474262739*cos((1000*sqrt(1122)*t)/33) + 0.00001474262739*sin((1000*sqrt(1122)*t)/33))^2) + 9.259259260*10^(-7):
ics := q(0) = 2.45*10^(-12):
sol:=dsolve({ode1,ics},numeric)

it works. I'll leave it up to you to check if the numerical solution is OK or not, as you know more what the solution should be. 

@mehran rajabi 

You can add assumptions to help Maple. Updated.

how is first  bc := q(-y) = 0, q(y) = 0  supposed to be boundary conditions?  since q is the dependent variable of the other ode. and the second bc bc1 := u(-y) = 1, q(y) = j  here is the dependent variable from first ode. These BC do not make sense to me.

You can solve the ode without BC (need to fix the first one as well to change q to q(y)

restart;
ode := xi*diff(q(y), y, y) - N*diff(u(y), y) - 2*N*q(y) = 0;
ode1 := (1 + N)*diff(u(y), y, y) + N*diff(q(y), y) = p;
dsolve([ode,ode1],[q(y),u(y)]

I am really just curious, how would you suggest Maple should decide if f(x) is meant to be f*x  vs being just a normal function call f(x)?

@acer 

"I don't really understand why you want big_car:-set_name declared as static, "

Well, Maple help says to make all object methods static, to avoid making copy of them each time a new object instance is created. 

But in your solution, you changed the sub-module to become Object class. But this will now require changing all the signatures of its methods to use ::static, and not only that, but also adding the object name to each internal method API.

Which means changing 10's of internal API's inside the submodule and each call as well, which will break things.   

I also do not need to make instances of those modules, so making them Objects is not logically needed. I simply wanted to use the code they provide  from inside the object, but as private or local modules to the Object class.

But I ended up with just keeping them as separate modules for now. Like this

restart;	
module car_class()
      option object;
      local name::string :="UNKNOWN";

      export set_name::static:=proc(o::car_class,_name::string)
        o:-name := _name;
        big_car:-set_name(_name);
      end proc;

end module:

#separate module.
big_car :=module() 
   local big_car_name::string:="UNKNOWN";  

   export set_name :=proc(_name::string)
       big_car_name:=_name;
   end proc;        

end module;

This ofcourse works.

Only disadvantage is that big_car is module on its own, while before it was submodule or local module. 

So it is now not private to, or child to the object.

But it is not a very big problem for now. This way I do not need to modify many many API's just to make these modules child to the object. 

But thank you  for the suggestion.

It might be better to explain what the algorithm does (i.e in words. What is the input and what is the output, and short description. A small example is also good) and then try to write it from scratch the Maple way, instead of trying to write it as Maple++.  This is always the best way to do such things.

 

@Carl Love 

This is another reason why the common object:-method(args)  is better than method(args,..,object,...args) used by Maple.

In the first case, there is no ambiguity of the name scope of the method, as it clearly bounded to class of the object.  by just looking at the call.

In the second case, Maple has to parse the whole call, scan all the arguments one by one, looking for an object somewhere there, then look into the class/type of that object, and then see if the method belongs to that class or not. 

Maple did not do that, and just saw process as external command name, and not  a name inside the class of the object.

So now in Maple one has to write this somewhat convoluted code instead

                  object:-method(object,args) 

Since object:-method(object,args) works, then I wonder if Maple could add feature to its OO in next version to allow the use of just object:-method(args). Saving one having to type the object name in two places. each time. I don't like redundancy and duplication as it can cause errors.

 

@itsme 

I agree. I also noticed the same thing. It would be much better to have the object as the first argument.

Btw, in Ada programming language, when they first added OO to the language (I think this was in 1995), they did not use the Object.method(args)  initially either, and many people complained but they used method(object,args)

Then in Ada 2005 version I think, they finally added the dot notation so one can now do Object.method(args)  instead, which is more natural for me because in OO one thinks of the object first as the central thing, then its methods, not the methods then the object. May be Maple could not find a good way to do object.method. They run out of keyboard keys to use for the "dot" operator as ~,->,:-,.,::,%,@ etc.. are all used in Maple already for other things.  

 

@Carl Love 

I am learning OO in Maple. I have not looked at it much before.

But one thing I find a little awkaward, is that one can not use the object.method(arg) notation, common in all OO languages, but have to use method(arg,object). Which is a little strange for OO programming, and will take a while to get used to. For example

restart;
module car_class()
      option object;
      local name;  #private

      export set_name::static:=proc(name::string,o)
          o:-name := name;
      end proc;

      export get_name::static:=proc(o)
          return o:-name;
      end proc;      

end module;

my_car:=Object(car_class); #make an object of class car

and now to set the name and get the name:

set_name("toyota",my_car);

get_name(my_car)
      "toyota"

It would be much more natural to do something like   my_car[set_name]("toyota") or my_car:-set_name("toyota")

And then my_car:-get_name() since in these, the object itself is upfront, instead of being passed as an argument.

It would be best to use the dot notation ofcourse, but that would probably break many things. So one could write my_car.set_name()  which is what Java/Python, and many other OO languages use, but this is asking too much in Maple.

But it is nice to have OO in Maple.

 

 

@Preben Alsholm 

 

I am not able to understand what this means. The index variable i is NOT private to the seq invocation.  It is recommended that you always explicitly declare the index variable to be local inside procedures.

What procedure is this?  When doing this 

seq(expression, i = integer1..integer2

how is one supposed to declare `i` as local? There is no procedure here anywhere.  (if this was inside a proc, sure, I can say local i; ) 

And how to apply this to the example given?

seq(%, x[j] in L);

 

 

 

it is even more strange when comparing these 3 variations, which all should give same output. Only when using % it gives 4.

restart;
L := [1,2,3,4]:
x[j]:
seq(x[j], x[j] in L):
x[j];


restart:
L := [1,2,3,4]:
seq(x[j], x[j] in L):
x[j]


restart:
L := [1,2,3,4]:
x[j]:
seq(%, x[j] in L):
x[j]

 

@tomleslie 

The first issue relates to your use of multiline strings - anyy 'linter' which didn't flag this piece of code isn't worthy of the name.

 

This is news to me. As multilines strings is a feature touted by many programming languages over others that do not support it. 

https://en.wikipedia.org/wiki/Here_document

"Here documents originate in the Unix shell,[1] and are found in shcsh,[2] tcsh,[3] kshbash, and zsh, among others. Here document-style string literals are found in various high-level languages, notably the Perl programming language (syntax inspired by Unix shell) and languages influenced by Perl, such as PHP and Ruby. Other high-level languages such as PythonJavaScript and Tcl have other facilities for multiline strings."

C++ added multiline strings in 2011 as new big feature of the language. See the second answer here https://stackoverflow.com/questions/1135841/c-multiline-string-literal which got 408 votes up.

There is absolutely nothing wrong with multiline strings. It is a good feature and can make doing something much simpler than without it. It also works in Maple with no problem and I have used it for long time in Maple with no problems at all.

The problem is that Maple's lint says it is syntax error when used in one specific construct and not in other places.

 

@Carl Love 

"Personally, I would never use a multiline string."

That is reasonable. But this was not really the question I was asking. I would agree with you though, that it is probably best not to use it and do "A\n","B" explicitly. I am changing my code to do that.

When you say "I think that mint should be stricter than regular Maple"  I thought that mint uses the Maple language rules to check the syntax,

Where does it say that

 cat("A
      B")

is a syntax error in Maple? Or even it says one should not do this? 

I did not see it when I searched, but I could have overlooked it. Notice also that the code actually runs inside Maple with no errors.

Does mint have its own rules for what constitute a syntax error in the Maple language? If so, do you know where these are described? I use mint sometimes check for possible problems in code.

The quesiton was, why it gives syntax error only when using 

if not x in ["A","B"] then

before it. 

First 55 56 57 58 59 60 61 Last Page 57 of 91