Robert Israel

6522 Reputation

21 Badges

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

MaplePrimes Activity


These are answers submitted by Robert Israel

You're getting the warning because the right side of your differential equation uses y instead of y(x).  If you change the right side to 0.2*x*y(x) it should work.  The real question is, why did it work when the independent variable was t?  To compound the mystery, your "With t as independ" version didn't work for me when I re-executed the worksheet in Maple 13.02: I got the warning.  Somehow you were getting y interpreted as y(t), without any warning, when the independent variable was t. 

It's very easy to ask Maple to do something that would require more memory than exists in the world, let alone in your computer.  Most of the time, an extra gigabyte or two would not help: it would only delay the problem.  In fact a common scenario is that Maple uses up all the main memory and goes into virtual memory, causing the computer to slow down so much that recovery becomes difficult, as it may be hard to get TaskManager started.  There may be things you can do to prevent Maple from trying to use so much memory, but we'd need more details of your code. 

The part you mention about "claims to exceed the output limit of 1000000" is a different matter: here it seems Maple has produced the result, but it is too large to display.  You might ask yourself whether you really want to see something that would require several hundred pages to print.  If you don't, then don't ask Maple to show it to you.  Terminate a command with a colon ":" rather than a semicolon ";" to avoid having the result shown on the screen.


Contact Maplesoft Technical Support.  They should be able to help you with this. 

I think the best way for you to produce such tables would be not to depend on Maple's own Latex output, but instead to write your own code for producing the tables using fprintf.  It really should not be difficult if you know a little Latex.

Maple is exactly right: the constraint is not linear.  Well, you could this: for each i, have a new variable v[i] with constraints v[i] >= w[i] and v[i] >= -w[i], and then you can have a constraint add(v[i], i = 1 .. NC) <= 4.

Note that I said <= 4, not = 4, because v[i] >= w[i] and v[i] >= -w[i] just forces v[i] >= abs(w[i]), not v[i] = abs(w[i]).  In fact, the feasible region ceases to be convex if you require the number of 1's and -1's to be equal to 4: in a convex problem, if w[i] = -1 and w[i] = 1 are allowed then w[i] = 0.


The best way to extract values from a set of equations such as {x=1, y=2} is using eval or subs, e.g.

> R:= isolve(x^2 + y^2 = 153);

R := {x = -12, y = -3}, {x = -12, y = 3}, {x = -3, y = -12}, {x = -3, y = 12}, {x = 3, y = -12}, {x = 3, y = 12}, {x = 12, y = -3}, {x = 12, y = 3}

> select(t -> eval(x>=0 and y >= 0 and x > y, t), {R});

                          {{x = 12, y = 3}}

> eval([x,y],%[1]);

                           [12,3]

Here is an example using LSSolve.  It seems to work quite a bit better in the linear least-squares version (because it's finding a global rather than local minimum).

> data:= [[2, 7.2], [4,11], [5,14], [6,14], [8, 9.3]];  
>    residuals:= [seq(1/d[2]^2 - (c2*d[1]^2 + c1*d[1] + c0), d = data)];
>    V:= Optimization:-LSSolve(residuals,{c0>=0,c2>=0});

V := [.150050928344287607e-6, [c0 = .398890886659023e-1, c1 = -.124784177663655e-1, c2 = .111610826911860e-2]]

> solve({c2=1/A^2,c1=(4*b-2*w0)/A^2,c0=w0^2/A^2},{A,b,w0},UseAssumptions=true) assuming positive;

{A = 1/(c2^(1/2)), b = 1/4*(c1+2*(c2*c0)^(1/2))/c2, w0 = 1/c2*(c2*c0)^(1/2)}

> R:= eval(%,V[2]);

R := {A = 29.9327650709977, b = .194050456082653, w0 = 5.97824754561864}

> resonance:= eval(A/sqrt((w-w0)^2+4*b*w),R);
   with(plots):
   display(plot(resonance,w=1..9),pointplot(data,colour=blue));

The result of the linear optimization can be used as initial point for the nonlinear one.

> residuals2:= [seq(d[2] - A/sqrt((d[1]-w0)^2 + 4*b*d[1]), d=data)];
   R2:= Optimization:-LSSolve(residuals2,{b>=0,A>=0},initialpoint=R)[2];

R2 := [A = 29.1148041020370, b = .177570149184052, w0 = 5.95778137311995]

The new curve (green) is a closer fit to the data than the old one (red) near the peak but not as good far away from the peak.

   resonance2:= eval(A/sqrt((w-w0)^2+4*b*w),R2);
   display(plot([resonance,resonance2],w=1..9,colour=[red,green]),pointplot(data,colour=blue));

This is something that has been complained about many times.  Try using the Classic interface, which still produces real PostScript 3D plots rather than bitmaps.

For example, suppose you want to minimize x^2 + y^2 + z^2 subject to x + y + z = 5 and z >= sqrt(x^2 + y^2).

> Optimization[Minimize](x^2 + y^2 + z^2, {x + y + z = 5, z >= sqrt(x^2 + y^2)});

[8.57864376269049700, [x = 1.46446609406726, y = 1.46446609406726, z = 2.07106781186548]]

The second argument to animate is the list of arguments to be given to the plot procedure.  In this case there is one argument, which itself is a list.  So you want

> animate(plot,[[s*cos(Pi/2*(1-t)),s*sin(Pi/2*(1-t)),s=0..1]],t=0..1);

I don't understand what you're trying to do.  Do you want points where f(x,y) = constant?   What do you mean by "with interval of 0.01? 

If you want points on a curve of the form y = y(x) on which f(x,y) is constant, then (as long as you don't run into points where D[2](f) = 0) this can be obtained from the differential equation D[1](f)(x,y(x)) + D[2](f)(x,y(x)) * diff(y(x),x) = 0.

So for example:

> f:= (x,y) -> x^2 + y^2;
   de:= D[1](f)(x,y(x)) + D[2](f)(x,y(x))*diff(y(x),x) = 0;
   S:= dsolve({de, y(0) = 2}, numeric, output=Array([seq(x,x=0..1, 0.01)]));
   A:= S[2,1];

 

Actually LSSolve is not the most convenient way to fit a curve to data.  Moreover, if it's a resonance curve like

y = A/sqrt((w-w0)^2 + 4*b*w)

that you want to fit, you might want to use a nonlinear least-squares fit (although it is possible to do linear least-squares on a transformed model 1/y^2 = c_2 * w^2 + c_1*w + c_0, then A = 1/sqrt(c_2) etc).  You might look at Fit in the Statistics package, which can do both linear and nonlinear fits. 

Are you talking about entering something in 1D Maple notation that looks like a conditional expression?

You could try something like

> `&mid;`(A,B);

`&mid;`(A,B)

Of course you can't "use" this in the sense of actually calculating something with it; this is purely for display purposes.

Interestingly, although the Relational and Operator palettes have entries for VerticalBar and VerticalLine, these seem only to be usable as delimiters (so |a| in 2-d math input parses as abs(a)).  This is a bug.

I suggest you use an Array, and plot it using listplot in the plots package.  Thus:

> A:= Array(1..nmax):
   for n from 1 to nmax do
       ...
       A[n]:= v
   end do:
   plots[listplot](A);

It looks to me like you're taking the inverse of the transpose of J, not J.  J^(-1) (which you could get by just entering J^(-1) if you defined J using Matrix rather than Array) should have its first row [0,0,1].

First 21 22 23 24 25 26 27 Last Page 23 of 138