Robert Israel

6522 Reputation

21 Badges

18 years, 180 days
University of British Columbia
Associate Professor Emeritus
North York, Ontario, Canada

MaplePrimes Activity


These are replies submitted by Robert Israel

In general, consider an expression of the form A = sum (c[j](x[1],`...`,x[m])*D[j](f)(p[1](x[1],`...`,x[m]),`...`, p[n](x[1],`...`,x[m])),j=1..n) which you want to rewrite as sum(a[i](x[1],`...`,x[m])*diff(f(p[1](x[1],`...`,x[m]),`...`,p[n](x[1],`...`,x[m])),x[i]), i=1..m) Can it be done? Maybe. It requires solving the n linear equations c[j](x[1],`...`,x[m]) = sum(a[i](x[1],`...`,x[m])*diff(p[j](x[1],`...`,x[m]),x[i]),i=1..m) for the m unknowns a[i](x[1],`...`,x[m]) In a case such as this (n=2 < m=3) you would expect non-unique solutions. If n=m there may be a unique solution, while if n > m, there are usually no solutions. Anyway, "solve" should have no problem with this. In this example:
C:= [-1,-1]; P:= [x-y,z-y]; X:= [x,y,z];
eqs:= {seq(C[j] = add(a[i]*diff(P[j],X[i]),i=1..3), j=1..2)};
solve(eqs, {a[1],a[2],a[3]});
{a[1] = a[1], a[2] = 1+a[1], a[3] = a[1]}
eval(add(a[i]*Diff(f(op(P)),X[i]),i=1..3),%);
a[1]*Diff(f(x-y,z-y),x)+(1+a[1])*Diff(f(x-y,z-y),y)+a[1]*Diff(f(x-y,z-y),z)
Oh, sorry, it should have been
`diff/T`:= (a,x) -> T(diff(a,x));
Then you'll get `.`(T(diff(g(a), a)), h(a))+`.`(T(g(a)), diff(h(a), a))
Oh, sorry, it should have been
`diff/T`:= (a,x) -> T(diff(a,x));
Then you'll get `.`(T(diff(g(a), a)), h(a))+`.`(T(g(a)), diff(h(a), a))
I don't think there is a reasonable way of doing that in a typical internet-connected environment with all kinds of background processes going on. Maybe if you isolated your system from everything else, and Maple was the only application you started after power-on. Since there's no guarantee that the calculation will go the same way in different sessions, what you should try to do is arrange things so the final results will be as immune as possible to these changes. So, for example, if something gives you several solutions, you don't pick out the 5th one, you pick out the one that is distinguished by some more intrinsic property (say the one where x[3] > 2). It takes some practice, but usually can be done.
I don't think there is a reasonable way of doing that in a typical internet-connected environment with all kinds of background processes going on. Maybe if you isolated your system from everything else, and Maple was the only application you started after power-on. Since there's no guarantee that the calculation will go the same way in different sessions, what you should try to do is arrange things so the final results will be as immune as possible to these changes. So, for example, if something gives you several solutions, you don't pick out the 5th one, you pick out the one that is distinguished by some more intrinsic property (say the one where x[3] > 2). It takes some practice, but usually can be done.
Your code has been mangled, I think, between the
 B12 := B1 
and the
 E13 := ...
because this forum interprets the < sign as the start of an HTML tag. You have to use & lt; instead. I think one of the main problems with your code itself is the distinction between formal parameters and global variables. When you say
> B11:=x1 <=B1 and x2 <=B2;
you're defining B11 in terms of the global variables x1 and x2. On the other hand, in the function definition
> Eobj := (x1,x2) -> ...
x1 and x2 are the formal parameters. If you called, say, Eobj(a,b), then any x1 or x2 in the body of the definition will be replaced by a or b respectively, before the body is executed. Now the body of the procedure has a statement containing B11; when that statement is executed, B11 is evaluated to a result containing x1 and x2. But since the replacement of x1 and x2 by the formal parameters has already been done, these x1 and x2 are never replaced, but stay as the global variables x1 and x2. Then the `if` functions can't be evaluated, because their first arguments don't evaluate to boolean values. To get around this, you might put all of the definitions of B11, E11, etc inside the definition of Eobj. Thus
Eobj := proc(x1,x2) 
         local B11, E11, B12, E12, B13, E13; 
         B11 := x1 <= B1;
...
         `if`(B11,E11,0) + `if`(B12,E12,0) + `if`(B13,E13,0);
    end proc; 
It comes from the identity a^2 - b^2 = (a + b)(a - b) with a = sqrt(x^2 + 9), b = 3. This is a standard trick for dealing with the difference of two square roots.
It comes from the identity a^2 - b^2 = (a + b)(a - b) with a = sqrt(x^2 + 9), b = 3. This is a standard trick for dealing with the difference of two square roots.
Actually, the problem here isn't division or square root, it's subtraction. More specifically, "catastrophic cancellation" which occurs when you subtract two numbers that are almost equal. Thus with the default Digits = 10 and x = 0.0001, sqrt(x^2 + 9) = 3.000000002 (correct to 10 significant digits) but subtract 3 and you have 2*10^(-9) (only one significant digit). In this case there's a trick to avoid catastrophic cancellation: notice that g(x) = 1/(3 + sqrt(x^2+9)).
Actually, the problem here isn't division or square root, it's subtraction. More specifically, "catastrophic cancellation" which occurs when you subtract two numbers that are almost equal. Thus with the default Digits = 10 and x = 0.0001, sqrt(x^2 + 9) = 3.000000002 (correct to 10 significant digits) but subtract 3 and you have 2*10^(-9) (only one significant digit). In this case there's a trick to avoid catastrophic cancellation: notice that g(x) = 1/(3 + sqrt(x^2+9)).
Whether here or elsewhere, it's usually better to post in ordinary text ("1D Maple input") rather than typeset mathematics ("2D Maple"). The 2D stuff may look nice, but it's impossible to copy-and-paste as Maple input. For general mathematics help, you might try The Math Forum or the sci.math newsgroup.
Yes. The difference between "add" and "sum" is that "sum" tries to do a symbolic summation, while "add" just adds together an explicit sequence of terms. See the help pages for these commands.
I don't understand: n is a constant, why would you want it to be one of the axes? Perhaps you mean e.g.
plots[odeplot](S, [seq([t,j,y[j](t)],j=1..n)], t = 0 .. 2,
  axes = box, labels = [t, j, y[j]], orientation = [250, 60]);
Something like this:
> n:= 5;
  k:= (m,l) -> (m^(1/3) + l^(1/3))^2;
  des:= {seq(diff(y[l](t),t) = 
    1/2*add(k(m,l-m)*y[m](t)*y[l-m](t), m=1..l-1)
    -y[l](t)*add(k(l,m)*y[m](t),m=1..n), l=1..n)};
  ics:= {seq(y[j](0)=1,j=1..n)};
  S:= dsolve(des union ics, numeric);
  plots[odeplot](S, [seq([t,y[j](t)],j=1..n)], t=0..2);
Yes, it is somewhat trickier. For a matrix of floats, roundoff error usually turns an eigenvalue with multiplicity > 1 into several close, but not exactly equal, eigenvalues. Exactly how this will happen, and what will be the resulting eigenvectors, is probably not easily predictable.
First 182 183 184 185 186 187 Page 184 of 187