nm

11353 Reputation

20 Badges

13 years, 19 days

MaplePrimes Activity


These are questions asked by nm

In Maple this works

my_list :=[1,2,3];
my_list[1]:=0;

But this does not

my_set:={1,2,3};
my_set[1]:=0;

gives error "Error, cannot reassign the entries in a set". I suppose it has to do with the fact that sets, mathematically speaking, do not have an "oder" per say? But the elements must be ordered internally as they show, right? So the first element in the set is "1" and the second element in the set is "2", etc...

Had to use the ugly and unatural notation of

my_set := subsop(1=0, my_set)

To change the element of a set. The above implifies an order as well. So why the first did not work, but the above works?

The question is why is this inconsistency of notation?   It is much more natural to write "A[i]:=something". 

If using "subsop(1=0, my_set)" is a must for some reason, then why Can't Maple make a short cut, where if a user types "A[i]:=something" where A is a "set", then it will internally get modified/replaced by "A:=subsop(i=something, A)", so that one can still use the more natural syntax instead?

But it would be better just removing this restriction of using A[i]:=something on a set.

in this ODE, with initial conditions, I am trying to verify my solution, but I can't figure how Maple obtained the final answer.  I can obtain same solution, but before using the initial conditions to find the constant of integrations. The problem comes in solving for the constant of integration from initial conditions. I do not know how Maple did it, becuause when I do the normal steps, I get division by zero.

restart;
ode:=diff(y(x),x)=x*ln(y(x)):
ic:=y(1)=1:
sol:=dsolve({ode,ic},y(x));

gives "sol := y(x) = 1"

Now I solve without IC, then try to find _C1 by hand

sol:=dsolve(ode,y(x));

       sol := y(x) = exp(RootOf(x^2+2*Ei(1, -_Z)+2*_C1))

Now used remove_RootOf

sol2:=DEtools:-remove_RootOf(sol);

            sol2 := x^2+2*Ei(1, -ln(y(x)))+2*_C1 = 0

Now I followed the steps I learned at school, which is to plugin y=1 and x=1 in the solution to get an equation to solve for _C1

eq := subs({y(x)=1,x=1},sol2);

            eq := 1+2*Ei(1, -ln(1))+2*_C1 = 0

But Ei(1, -ln(1)) is a division by zero. So can't solve for _C1

solve(eq,_C1);
       Error, (in Ei) numeric exception: division by zero

So how would you solve for _C1 in the above? Or how did the smart Maple do it?

I tried using limits, but that did not help.  I tried using allvalues instead of remove_RootOf, and that did not get rid of RootOf.  Next I tried not to remove RootOf and keep it there to see what happens

sol:=dsolve(ode,y(x));
eq := subs({y(x)=1,x=1},sol);
             eq := 1 = exp(RootOf(1+2*Ei(1, -_Z)+2*_C1))

c1:=solve(eq,_C1, AllSolutions);
              c1 := -1/2-Ei(1, -(2*I)*Pi*_Z1)

subs(_C1=c1,sol);
             y(x) = exp(RootOf(x^2+2*Ei(1, -_Z)-1-2*Ei(1, -(2*I)*Pi*_Z1)))

simplify(%);
            x^2+2*Ei(1, -ln(y(x)))-1-2*Ei(1, -(2*I)*Pi*_Z1) = 0

DEtools:-remove_RootOf(%);
           x^2+2*Ei(1, -ln(y(x)))-1-2*Ei(1, -(2*I)*Pi*_Z1) = 0

solve(%,y(x));
          exp(RootOf(x^2+2*Ei(1, -_Z)-1-2*Ei(1, -(2*I)*Pi*_Z1)))

So I can't figure how Maple obtained y(x)=1. Maple must have used different method to solve for _C1.

What would be the Maple commands to use to obtain y(x)=1, starting from

            sol:=dsolve(ode,y(x));

and given that y(1)=1 ?

 

Can someone please explain in simple terms, why when I do

 r:=foo(r), where "r" is a Record, then the returned  "r" is not what is returned from foo()?  I want to write a proc foo() which takes in a Record variable, update some of its fields, and then return the updated Record to the caller

r:=Record('a','b');
foo:=proc(r)
    r:-b:=5;
    return(r);
end proc;

But now when I call the above as follows

r:-b:=99;
print(r);
r:=foo(r):
print(r);

The last print above just prints "r" and not the Record. It seems to have erased the Record.

 

But it works, if I change the name of the variable to return the result into, as 

r:-b:=99;
print(r);
r0:=foo(r):
print(r0);

When I do the same on say a Matrix, there is no problem

restart;
r:=<<1,1>>:
foo:=proc(r)
    r[1]:=5;
    return(r);
end proc;

And now

r;
r:=foo(r):
print(r);

 

Why it worked with a Matrix but not with Record? Why can't one overwrite the Record on the call return?

What would be the correct way to pass in a Record to a function, and have the function update some of its fields, and then return back the updated copy of the Record without having to make a new variable "r0" as above?

I really like Maple Record. I think it is one of the hidden gems in Maple. Very useful.

But I have basic questions on it. I just started to learn how to use it. It is very similar to Pascal Record.

1)

r:=Record(a,b);
                       r := Record(a, b)
type(r,'record');
                              true
whattype(r);
                             symbol

Why  type(r,'record') says true, but whattype(r) says symbol?

2)
Why Maple displays the record content to the screen automatically only first time, after it is created, but second time, it only echos the name? So one has to use print() each time to display the content of the record.  Not a big deal, but it is little annoying

r:=Record(a,b);
                       r := Record(a, b)
r;
                               r

print(r);
                          Record(a, b)

r:-a:=5;
                             a := 5
r
                               r

print(r);
                        Record(a = 5, b)

 

Compare this to say a set type, where it displays the content each time

r:={1,2,3};
                         r := {1, 2, 3}
r
                           {1, 2, 3}

I tried changing max_record_depth but I must be doing something wrong. It still does not display the content

interface(max_record_depth=10)
                               10
r:=Record(a,b);
                       r := Record(a, b)
r;
                               r

3) Why are these two behave the same way

r:=Record("y");
r:-y:=4;

r:=Record('y');
r:-y:=4;

Giving the name of the field as string worked the same way as second example which is a name.  I thought the first one above will not work as field name should be a name according to help.

One of the frustrating things I am finding in using Maple debugger is that I can't set breakpoint using stopat() at some line number in some inner module, if the inner module is local module. It has to be an exported module.

Here is an example

restart;
foo:=module()
   export main_entry;
   local foo1; #inner module. But if local, Can't set breakpoint from outside

   foo1:=module()
     export main_entry;
     local foo2;

     foo2:=proc() #or breakpoint in first line here
        local s,x;
        s:=1;     #suppose I want to set break point here
        s:=s+sin(x);
     end proc;
     
     main_entry:=proc()         
        foo2();
     end proc;    
  end module;

  main_entry :=proc()
    foo1:-main_entry(); #call inner module's proc
  end proc;

end module;

Since there is inner module, local to outside module, I can't set break into the inner module procs anywhere.

stopat(foo:-foo1::foo2);
Error, module does not export `foo1`

A workaround for now is to change "local" to "export" on the inner modules declarations I want to debug, so I can setbreak points inside them, then when done, make them local again. So changed "local foo1" to "export foo1" above, and now

          stopat(foo:-foo1::foo2,2);

works.

This was also a little strange to me, since foo2() is a LOCAL proc to module foo1, yet Maple did not complain like it did when module foo1 was a LOCAL module to foo. I would have expected Maple to complain again for same reason.

So I am using the above workaround for now. But it is just a little annoying becuase I have to keep changing module from LOCAL to EXPORT in order to set breakpoints, then remember to make them local again.

Is there a better workaround?

A product suggestion: make stopat() ignore the local module setting and treat it as export for the purpose of setting a break point. This way one does not have to change the code just to set a breakpoint. Or if not to change current behavior, add a new option, as in

          stopat(........, option= ignore_local_setting)

So the default remain the same as now, but with the new option, it will set breakpoint anywhere, even in local modules.

 

Thank you

 

 

First 154 155 156 157 158 159 160 Last Page 156 of 199