nm

8552 Reputation

19 Badges

12 years, 354 days

MaplePrimes Activity


These are replies submitted by nm

btw, it is not good idea to use I(t) in there since I is the complex number in Maple. Use different symbol. Say u(t)

other than all the typos in your code, how did you manage to overwrite equation? Since this is protected name in Maple

equation:=1
Error, attempting to assign to `equation` which is protected.  Try declaring `local equation`; see ?protect for details.

type(equation,'protected')
                              true
 

 

@tomleslie 

The second method you showed seems to work. But strange, I had to add extra simplify at end to get same output you show. How come it worked for you without that extra simplify?

restart;
expr := (x^2 - 1)/x^2*y + (x^2 - 1)/x^2:
r    := (x^2-1)/x^2:
Z    := freeze(r):
simplify(collect( algsubs( r=Z,expr),Z)):
thaw(%);

You see? Now adding simplify to the above gives desired result

simplify(%)

Lots of gymnastics there.  I think applyrule is much simpler :)

Thanks for the illustrations.

@tomleslie 

Thanks, but that is not what I wanted to do. I wanted to replace (x^2 - 1)/x^2  by one symbol Z in expr using algsubs like with applyrule.

How would one use this thaw and freeze trick to do this? 

I know you obtained the same final result I want, by inspection. But for what I am doing, I need to replace the other expression (x^2 - 1)/x^2 by one symbol first. Can your method work for this also?

 

@Carl Love 

Thanks. This version seems to work well. I'll report here if I find any bug. But so far, no problems.

restart;

Typesetting:-Settings(typesetprime=true):
tests:=[
[diff(y(x),x)=y(x)^(1/2),1],
[diff(y(x),x$2)+diff(y(x),x)^(1/2)=y(x),2],
[(1+diff(y(x),x)^2)^(3/2)=diff(y(x),x$2),2],
[3*y(x)^2*diff( y(x),x)^3- diff(y(x),x$2)=sin(x^2),1],
[sqrt(1+ diff(y(x),x)^2)=y*diff(y(x),x$3),2],
[sqrt(1+ diff(y(x),x)^2)=y*diff(y(x),x$3),2],
[sin(diff(y(x),x))+ diff(y(x),x$2)+3*x,FAIL],
[exp(diff(y(x),x$2))+sin(x)*diff(y(x),x)=1,FAIL],
[k*diff(y(x),x$2)^2=(1+ diff(y(x),x$2)^2)^3,6],
[x*diff(y(x),x$2)^3*diff(y(x),x)-5*exp(x)*diff(y(x),x$2)+y(x)*ln(y(x)),3],
[2*ln(x)*diff(y(x),x)^2+7*cos(x)*diff(y(x),x$2)^4*diff(y(x),x)^7+x*y(x)=0,4]
];

for i from 1 to nops(tests) do
  deg:= ODEdegree(tests[i,1]);
  if deg <> tests[i,2] then
     print("Failed on ",tests[i,1]," .Expected degree ",tests[i,2]," got ",deg);
  else
     print("Passed on ",tests[i,1]," .Expected degree ",tests[i,2]," got ",deg);
  fi;
od:

"Passed on ", diff(y(x), x) = y(x)^(1/2), " .Expected degree ", 1, " got ", 1

"Passed on ", diff(diff(y(x), x), x)+(diff(y(x), x))^(1/2) = y(x), " .Expected degree ", 2, " got ", 2

"Passed on ", (1+(diff(y(x), x))^2)^(3/2) = diff(diff(y(x), x), x), " .Expected degree ", 2, " got ", 2

"Passed on ", 3*y(x)^2*(diff(y(x), x))^3-(diff(diff(y(x), x), x)) = sin(x^2), " .Expected degree ", 1, " got ", 1

"Passed on ", (1+(diff(y(x), x))^2)^(1/2) = y*(diff(diff(diff(y(x), x), x), x)), " .Expected degree ", 2, " got ", 2

"Passed on ", (1+(diff(y(x), x))^2)^(1/2) = y*(diff(diff(diff(y(x), x), x), x)), " .Expected degree ", 2, " got ", 2

"Passed on ", sin(diff(y(x), x))+diff(diff(y(x), x), x)+3*x, " .Expected degree ", FAIL, " got ", FAIL

"Passed on ", exp(diff(diff(y(x), x), x))+sin(x)*(diff(y(x), x)) = 1, " .Expected degree ", FAIL, " got ", FAIL

"Passed on ", k*(diff(diff(y(x), x), x))^2 = (1+(diff(diff(y(x), x), x))^2)^3, " .Expected degree ", 6, " got ", 6

"Passed on ", x*(diff(diff(y(x), x), x))^3*(diff(y(x), x))-5*exp(x)*(diff(diff(y(x), x), x))+y(x)*ln(y(x)), " .Expected degree ", 3, " got ", 3

"Passed on ", 2*ln(x)*(diff(y(x), x))^2+7*cos(x)*(diff(diff(y(x), x), x))^4*(diff(y(x), x))^7+x*y(x) = 0, " .Expected degree ", 4, " got ", 4

 

 

Download test_1.mw

@Carl Love 

I've been playing with indets, found that this seems to work also

expr := y^2*sin(1/y) + y^(3/2)  + x*y^7;
indets[flat]( expr,  {`^`('identical'(y),algebraic),'identical'(y)} );

gives

{y^(3/2), 1/y, y^2, y^7}

Do you see anything wrong with the above?  I used flat to prevent Maple from giving y as also a possible match.

@Christian Wolinski 

"Should y be included in the answer to the following expression: 

expr := y^2*sin(1/y) + y^(3/2) + x*y^7;

"

The result of the above should be {y^2, y^(-1), y^(3/2), y^7}  only.  So y should not show there.

@Rouben Rostamian  

"You may rearrange that equation into (y')^(/1/2)=y-y'' then square both sides"

Yes. good point. So degree is 2 and not undefined as I said above. Will correct now. I'll also check for this case in my Maple function that it handles this case Ok also.

@Carl Love 

The way I understand it, is that the degree of the ODE is the degree of highest order
derivative in the ODE when the ODE can be written as a polynomial in derivatives.

If the ODE can not be written as polynomial in the derivatives, then the degree is not defined.

The hard part of this, is to see if the ODE can be written as polynominal in derivatives or not.
(May be Maple has some build in functions to help with this algebra part?)

In a polynomial, all powers must be integers.

Examples
---------
1)  y'= y^(1/2)  

In this, the ODE is allreay a polynomial in derivatives. since it can be written as

      (y')^n = f(x,y)
      
Where n=1. So degree is 1. We do not care above y^(1/2) since that has no derivatives of y(x) in it.

2) y''+ (y')^(1/2) =y.

This is not a polynomial in derivatives. Since powers on all the derivatives are not all integers.      
     
If we can rewrite the above as polynomial (y'')^n + (y')^m = f(x,y) where n,m are integers, then n will be the degree.

<corrected. Thanks to Rouben Rostamian >

For this one, writing it as y'(1/2) = y-y'' and squaring both sides gives

               y' = y^2 -2 y y'' +(y'')^(2)

Now all powers on derivatives are integers.  Power on highest derivative is 2. Hence degree is 2.

3)   (1+ y')^(3/2)  = y''.  

This is Not a polynomial in the derivatives. But squaring both sides gives

         (1+y')^3 = (y'')^2
         1+ 3 y' + 3 (y')^2 + (y')^3 = (y'')^2
         
Now it is a polynomial in derivatives since all powers on each derivative is an integer.
Looking at result, we now find the power on the highest derivative. It is 2. Hence degree is 2.

@Carl Love 

fyi. I found a bug. 

ode:=diff(y(x),x) = x^(1/2);
ODEdegree(ode)

gives 2. But It is clear the degree of the ODE is 1.

@tomleslie 

"You (as author) have control over the order of arguments in the function call, so why use an order that you do not want? "

 

Not everyone works alone. Imagine you are working in a team and looking at others code on the same project.

Having keyword arguments be placed in between positional arguments can be just a little confusing when reading others code as one have to look at required argument.

Imagine a proc that takes many more arguments with mixed positional and keyword.

I always prefer the language itself to enforce something than rely on some convention or something to remember as code is written.

 

@Daniel Skoog 

Thanks. Should the file Visualization.mm  have Data := module() in it and the file Data.mm (after renaming) also have Data := module()

Also, for something meant to be used to learn from, there is NO readme.txt file anywhere, telling one what to  call to make this run. So after I did read("RandomnessTests.mpl") I was saying to myself, ok. Now what do I do? Do I need to make another call to something? 

Maplesoft should be a little bit more effort on this, as these meant to be code to learn from.

@Carl Love 

 

Maplesoft no longer sells this product from its web site

https://www.maplesoft.com/products/toolboxes/IDE/

I actually bought this product from Maple when it came out. Tried it for few days, could never figure how to use it or make it work, it seems to be based on Eclipse.

Called customer support and explained this to them, and they were nice enough to agree to refund my money.

 

@Carl Love 

"Your command subs(sol, ode) is total nonsense because sol is an implicit solution"

yes, I overlooked this, since I was using code to verify   explicit solutions I had and did not pay good attention.

I will remove it now.

@Carl Love 

"if you really actually don't care about a0, let me know"

Maple automatically sometimes does this. For example:

expr:=sin(x)+sqrt(3*x*y);

Maple returns

After more testing, It seems the general pattern which will cover all cases is

               a0 * ( a1 * x ^ a2  OPERATOR a3 * y ^ a4 ) ^ a5  + a6 

Where a0,a1,a2,a3,a4,a5,a6 can be some values and OPERATOR is either +,*,/,- This accounts to everything I tried so far. The following is the notebook. 

If all of this can be done by hastype (in addition to being able to know the values of a_i above, which is important, that that will good to see and I am sure useful for many others. What I have below seems to work for me so far and I am sure it can be improved more.
 

restart;
expr:=[sin(x)*(x*y)^(1/3),
       sin(x)+(3*x*y)^(1/6),
       sin(x)*sqrt(x/y)+3,
       sin(x)*sqrt(a*y*x),
       3*sqrt(a*y+x),
       3*sqrt(a*y-x),
       3*sqrt(a*y-x)+x,
       3*sqrt(a*y/x),
       3*sqrt(a*y/x)-y,
       3*sqrt(x/y),
       3*sqrt(x/y)+x,
       3-sqrt(x/y)+x,
       3+sqrt(a*x*y)*x,
       3*sqrt(y+x),
       3*sqrt(y+x)+y,
       sqrt(x)/sin(x)*sqrt(y+x^2)+3*x,
       3+sqrt(y-x)+x,
       3/sqrt(y-x)*x,
       a+sin(x*y)/sqrt(y-x)-3*x,
       int(x,x)+3^sqrt(y-x)-3*x]:

foo:=proc(expr,x,y)
  #looks for expression f(x,y) inside radical anywhere.
  local a0,a1,a2,a3,a4,a5,a6;  
  if patmatch(expr, a0::anything*(a1::anything*x^a2::anything * a3::anything*y^a4::anything)^a5::nonunit(radnum)+a6::anything,'la') or
     patmatch(expr, a0::anything*(a1::anything*x^a2::anything + a3::anything*y^a4::anything)^a5::nonunit(radnum)+a6::anything,'la') or
     patmatch(expr, a0::anything^((a1::anything*x^a2::anything + a3::anything*y^a4::anything)^a5::nonunit(radnum))+a6::anything,'la') or
     patmatch(expr, a0::anything^((a1::anything*x^a2::anything * a3::anything*y^a4::anything)^a5::nonunit(radnum))+a6::anything,'la')
then
        print("matched");
  else
        print("did not match");
  fi;
end proc:
seq(foo(expr[i],x,y),i=1..nops(expr))

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

"matched"

 

 

Download parsing.mw

 

First 40 41 42 43 44 45 46 Last Page 42 of 71