nm

7165 Reputation

19 Badges

10 years, 146 days

MaplePrimes Activity


These are questions asked by nm

Fyi, this looks like a bug.

But I do not know if it is new or not. I am using Maple 2022.2 on windows 10

Why it fails first time?

(ps. unable to paste content of worksheet here. looks like forum is not working, will paste an image)

Here is the code also in plain text

restart;
delMdelY:=-2*y^2/((x^2 - y^2)^2*(x - k*sqrt(x^2 + y^2))) - 1/((x^2 - y^2)*(x - k*sqrt(x^2 + y^2))) - y^2*k/((x^2 - y^2)*(x - k*sqrt(x^2 + y^2))^2*sqrt(x^2 + y^2));
delNdelX:=-2*x/(x^2 - y^2)^2;
if simplify(delMdelY - delNdelX)=0 then
    print("ok");
else
    print("not ok");
fi;

Maple Worksheet - Error

Failed to load the worksheet /maplenet/convert/simplify_fails_in_proc.mw .

Download simplify_fails_in_proc.mw

I want to make proc that returns expression sequence of two numbers, say. A,B

This will be the normal return, but if the proc encounters an error, it should return FAIL. But this is not possible, because if I type A,B:=foo(0) and foo() happenes to return FAIL then Maple will complain

Error, mismatched multiple assignment of 2 variables on the left side and 1 value on the right side

The three workarounds I see are these

Method 1

I could wrap foo() with try/catch and have foo throw an exception when it encouters an error instead of returning FAIL, but I do not like this. This will look like

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):
foo:=proc(n::integer)::integer,integer;
  if n=0 then
     error ("encountered error");
  else
     return 1,2;
  fi;
end proc;

And now the caller will do

try
   A,B:=foo(0);
catch:
   print("encountered error");
end try;

method 2

Another option is to have foo() return ONE value back. In the case of an error it will be FAIL, and in the case of normal behavior, it will be a LIST of the two items, which then I have to extract.  Like this

interface(warnlevel=4);
kernelopts('assertlevel'=2):
foo:=proc(n::integer)::Or(list(integer),identical(FAIL));
      if n=0 then
         return FAIL;
      else
         return [1,2];
      fi;
end proc;

And now the caller will do this

L:=foo(1);
if L<>FAIL then
   A:=L[1];
   B:=L[2];
else
   print("failed call");
fi;

But this is not as easy as just calling foo() as   A,B:=foo() but I can't do this due to the mismatch problem.

Another method, commonly used in C programming is to have the function return status an additional output and this will indicate if the call was success or not. so the caller has to remember to always check for this before using the returned values. These are handled by errno, perror(), strerror(). But for now, lets make the function return the status.

So caller will first check if status is success first and if so, then it will read the actual returned values that follow it. Like this (status is true/false)

method 3

interface(warnlevel=4);
kernelopts('assertlevel'=2):
foo:=proc(n::integer)::truefalse,integer,integer;
  if n=0 then
     return false,0,0;
  else
     return true,1,2;
  fi;
end proc;

And the caller will do

status,A,B:=foo(1);
if status then
   print("call was success, A and B are ",A,B);
else
   print("call failed");
fi;

So the return values will always have status as first argument that the caller has to check before reading the rest of returned values.

From the above three options which you think is best?

Anyone can suggest alternatives to the above methods?

Encountered new exception using odetest which can't be cought. Is this new one? I do not have earlier version of Maple than 2022.2 to check. On windows 10.

btw, I could not update to latest Physics now, may be server problem.  Attached worksheet

interface(version);

`Standard Worksheet Interface, Maple 2022.2, Windows 10, October 23 2022 Build ID 1657361`

Physics:-Version(latest)

Error, (in Physics:-Version) unable to determine the Physics Updates version, could you please report the problem to support@maplesoft.com

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1351. The version installed in this computer is 1348 created 2022, November 14, 15:59 hours Pacific Time, found in the directory C:\Users\Owner\maple\toolbox\2022\Physics Updates\lib\`

restart;

 

sol:=y(x) = -LambertW(x/sin(x)*exp(c[1]/sin(x)))+c[1]/sin(x);
ode:=exp(y(x))+cos(x)*y(x)+(exp(y(x))*x+sin(x))*diff(y(x),x) = 0;
odetest(sol,ode)

y(x) = -LambertW(x*exp(c[1]/sin(x))/sin(x))+c[1]/sin(x)

exp(y(x))+cos(x)*y(x)+(exp(y(x))*x+sin(x))*(diff(y(x), x)) = 0

Error, (in tools/map) too many levels of recursion

try
sol:=y(x) = -LambertW(x/sin(x)*exp(c[1]/sin(x)))+c[1]/sin(x);
ode:=exp(y(x))+cos(x)*y(x)+(exp(y(x))*x+sin(x))*diff(y(x),x) = 0;
odetest(sol,ode);
catch:
   print("error in odetest");
end try;

y(x) = -LambertW(x*exp(c[1]/sin(x))/sin(x))+c[1]/sin(x)

exp(y(x))+cos(x)*y(x)+(exp(y(x))*x+sin(x))*(diff(y(x), x)) = 0

Error, (in tools/map) too many levels of recursion

 

Download problem_odetest_nov_20_2022.mw

I do not know what to do now, since if I can't catch the exception, the program can't run anymore and just stops.

I think I mentioned this before long time ago and never got any satisfactory answer. So I thought I will try again.

I never been able to figure why/how dsolve decides when to integrate the intermediate result vs. keeping the integral inert, even though it can integrate it.

It must use some rule internal to decide this, and this is what I am trying to find out.

Here is a very simple separable ode. So this is just really an integration problem.

restart;
ode:=diff(y(x),x)=(b*y(x)+sqrt(y(x)^2+b^2-1) )/(b^2-1);
dsolve(ode)

The first thing that comes to mind, is that Maple could not integrate it, that is why it gave inert integral. but it can integrate it but the result is a little long

int((b^2 - 1)/(b*y + sqrt(y^2 + b^2 - 1)),y)

So it could have generated the above implicit solution instead. Now notice what happens when I make very small change the ode.

restart;
ode:=diff(y(x),x)=(y(x)+sqrt(y(x)^2+b^2-1) )/(b^2-1);
dsolve(ode)

In the above I changed b*y to just y and guess what, now maple will integrate it and give an implicit solution instead of an inert integral

In both cases, Maple is able to do the integration. But in first case, it returned an inert integral and in the second it did not.

my question is why?  Does it have a rule where if the size of the integral is larger than some limit, it does not solve it? Did it say,

     "I think this result is too complicated to the user, so I will keep the integral inert instead"

If so, what are the rules it uses to decide when to do the integration and when to keep it inert? Is it based on leafcount? number of terms? something else?

infolevel does not give a hint on this, as all what it says is that it is separable.

Any one has an ideas on this?

This ode from textbook, and the solution is given in back of book and I verified it is correct.

odetest gives zero also when asked to verify the solution.

but when asked to verify both the solution and the initial conditions, instead of returning [0,0] as expected, it returns [the_ode,0]

Here is an example
 

interface(version);

`Standard Worksheet Interface, Maple 2022.2, Windows 10, October 23 2022 Build ID 1657361`

restart

ode:=diff(y(x), x) = 2*(2*y(x) - x)/(x + y(x));
ic:=y(0) = 2;
booksol:=(x-y(x))^2/( y(x)-2*x)^3 = 1/2;

diff(y(x), x) = 2*(2*y(x)-x)/(x+y(x))

y(0) = 2

(x-y(x))^2/(y(x)-2*x)^3 = 1/2

#this returns zero, so maple agree the book solution is correct
odetest(booksol,ode)

0

#when adding ic, when does it not give [0,0] ?
odetest(booksol,[ode,ic])

[diff(y(x), x)-2*(2*y(x)-x)/(x+y(x)), 0]

 


How shoulld one interpret the above answer?

Download question_on_odetest_nov_14_2022.mw

1 2 3 4 5 6 7 Last Page 1 of 141