## dharr

Dr. David Harrington

## 6003 Reputation

19 years, 302 days
University of Victoria
Professor or university staff

## Social Networks and Content at Maplesoft.com

I am a professor of chemistry at the University of Victoria, BC, Canada, where my research areas are electrochemistry and surface science. I have been a user of Maple since about 1990.

## button and boxes...

@Traruh Synred Did you see the reset button and start, end and distance displays below the plot? Try hitting the reset button, then click on a point on the image, then on a second point on the plot, and then look under "distance" to see what the distance between the two points is. You don't neet to do any programming, just run the program (the file takes a little while to load), then 3 clicks and you have your distance. I guess if you really want, it could be modified to draw the line or arrow between those two points as well as calculate the distance.

I don't think you can access the length of your drawn line on an image; I tried to do that before I did the programming for the plot component.

## misunderstanding...

@Traruh Synred You say "That only tells me the number of pixels in the picture", but that is not true. You click where you want to start the measurement and then where you want to end it, and it tells you the distance between them in a straight line. So that is the same as clicking the two ends of the arrow. The units are in pixels, but if you then measure a known distance you can convert it to whatever units you want.

## automatic simplification...

@MDD The combination of sin(x) and -sin(x) is simplified to zero as part of Maple's automatic simplification. This cannot be prevented unless you write the ode in an inert form and explicitly handle the inertness, which I would not recommend. This simplification is mathematically correct, so presumably what you want.

You could process individual terms into two lists, of coefficients and non-coefficients. This would not use dcoeffs, which has an explicit order and discards information. In other words, you would have to write your own version of dcoeffs. At the moment, your result is not mathematically unique, since b*x^3 + sin(x) gives a different result from sin(x)+b*x^3. Likewise  bacause of the use of expand, sin(x+a) will give sin(a)+cos(a) but perhaps you want sin(x+a). If you don't use expand, then then a*(x-1) and a*x-a are treated differently, which again is not mathematically unique.

So if you want a mathematically unique answer, you need to specify what you want more precisely. If you are interested in the coefficients "as written" then that would be done in a different way, but then you need to think about what you mean by a coefficient, e.g. in ... + (b+x)*diff(y(x),x)+ you presumbly want 1?

## information lost...

@MDD It is not possible to go back. For the non-derivative terms the information about the function of x has been discarded. Even for the derivative terms, they could be squared or other powers and still have the same coefficient.

## try this...

@MDD I think this covers all the cases. Only x is treated as a variable in the non-derivative terms. Note that e*(x-1) gives two terms because it is the same as e*x-e.

 >
 >

 > ode_to_poly:=proc(ode,fn::function)   local ode1,cfs,lastterms,withx,withoutx,vars,xvar,i,dummy,zz;   xvar:=op(1,fn);   if type(ode,`=`) then ode1:=rhs(ode) - lhs(ode) else ode1:=ode end if;   cfs := [PDEtools:-dcoeffs(ode1,fn)];   lastterms := [op(expand(cfs[-1] + dummy))];   withx, withoutx := selectremove(has, lastterms, xvar);   withx:=map(zz->if type(zz,`*`) then remove(has,zz,xvar) else 1 end if, withx);   cfs := [cfs[1 .. -2][], withx[]];   vars := [seq(cat(A, i), i = 1 .. nops(cfs))];   add(cfs[i]*vars[i], i = 1 .. nops(cfs)) + subs(dummy = 0, add(i,i in withoutx)); end proc:
 >

 >

## maybe this...

@dharr works at least for your last example

dcoeffs3.mw

## rule...

@MDD So I had to guess at what you wanted for the part that doesn't contain y(x).

What do you want for a*sin(x)+b*x+c? (a*sin(x)+b*x)*A4+c or a*sin(x)*A4+b*x*A5 +c? Is the function of x always a polynomial?

@MDD Oops, I uploaded the wrong file. dcoeffs2 above should work.

## without elementwise...

@MDD Sorry, this should work in your version of Maple.

dcoeffs2.mw

## useassumptions...

`sol := {solve(HurwitzConditions,useassumptions)}:`

 >
 >

 >

 >

 >

## You need a modulus...

@delvin For the 4th time - you need a modulus! I chose l=1, but you might need some other value or maybe just symbolic.  I put sum back to add as I told you originally.

Eq1 is now found without errors. simplification is slow and I didn't wait. Of course in the next step you can't solve one equation for 13 variables. I've fixed the Maple, but it is up to you to take it to the next step.