dharr

Dr. David Harrington

8235 Reputation

22 Badges

20 years, 342 days
University of Victoria
Professor or university staff
Victoria, British Columbia, Canada

Social Networks and Content at Maplesoft.com

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

MaplePrimes Activity


These are replies submitted by dharr

@Axel Vogt If you enter local gamma in 2-D notation and then convert it to 1-D, then it appears as _local(gamma). I assume this is some sort of internal form that is functionally equivalent. But to avoid confusion, local gamma is of course preferred.

@Carl Love @mmcdara When I looked at it I saw similar things to those listed by @Carl Love. I guessed that if you come from a traditional programming language and you see or use X[i,j] then you think that they are array elements, so you promptly declare an array for them to go into. Adding symbol = x just changes the X names for x. My solution was to comment out the array line; then I got stuck on "max" making it unsuitable for a linear problem with binary variable, for which Carl had a nice solution.

Please upload your worksheet using the large green up-arrow in the Mapleprimes editor.

@Preben Alsholm maybe inf=3 was just for debugging, and perhaps there are to be many more odes? I never like this sort of approximation for infinity and prefer to change variables to a finite range, e.g., [0..infinity) to [0..1].

@Scot Gould I don't have flow, but this should be equivalent

cat(C, 1..numelems(V)) := seq(V);

@dharr I think the problem may be that the code works only when the click-and-drag mouse pointer is used. After the image loads, click the plot, then on the plot toolbar select the   icon. Then reset button and click. (Spurious errors may occurr but the reset button should fix them.)

@Traruh Synred Start with just running my worksheet without any modifications. Looks like you might have removed the Plot0 component, which is the empty square below the xrng,yrng message:

When you run the worksheet (with the !!! icon) the image should appear inside Plot0 (it's slow to load). Once you get it working on mine, it is probably easier to modify my worksheet with your code.

 

@dharr This version draws a red line between the two selected points. (Reset doesn't remove the line because it is very slow to redraw the image, but the line disappears when you draw the next line.) If you want an arrow (there are many options for this), then the plottools:-line can be changed to plottools:-arrow in the plot component click code.

MeasureImage.mw

 

@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.

@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.

@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?

@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. 

@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.

restart

ode := diff(y(x), x, x, x) = (c-1)*(diff(y(x), x, x))-2*a*(diff(y(x), x))+b*x^3+sin(x)-a*c

diff(diff(diff(y(x), x), x), x) = (c-1)*(diff(diff(y(x), x), x))-2*a*(diff(y(x), x))+b*x^3+sin(x)-a*c

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:NULL

ode_to_poly(ode, y(x))

-A1+(c-1)*A2-2*a*A3+b*A4+A5-a*c

``

Download dcoeffs4.mw

@dharr works at least for your last example

dcoeffs3.mw

@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?

First 34 35 36 37 38 39 40 Last Page 36 of 85