Carl Love

Carl Love

28085 Reputation

25 Badges

13 years, 99 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

There are many ways to do this. The way that I prefer is to use a single plot command with a seq-loop inside instead of a plot command inside a for-loop. Then no display is needed.

HA:= [1,2,3]:
n:= nops(HA):
plot(
   [seq(eval([f[1], f[2], f[3]], R= HA[i])[], i= 1..n)], 
   x = 0 .. 1, size = [300, 250], labels = [y, T(y, t)], 
   titlefont = ["Arial", 10, Bold], 
   labelfont = ["Arial", 10, Bold], 
   labeldirections = [horizontal, vertical], 
   axes = boxed, color= [blue $ n, green $ n, red $ n], 
   linestyle = op~([[solid, dash, dot] $ n]), thickness = 3
); 

You may want to include a legend, if you can come up with some succinct names for each of the nine curves.

The easiest way is to do this in a single execution group:

st:= time():
# Code that you want to test...
# ....
time() - st;

In other words, you mark the starting CPU time and subtract it from the finishing CPU time.

If your code can be expressed as the evaluation of a single expression---which can always be achieved by putting the code into a procedure---then you can use the simpler

CodeTools:-Usage(expression);

This command returns the value of the expression and prints timing and memory usage data as a side effect.

From some preliminary plot experimentation, I concluded that for real x and y, the eigenvalues are all real in the interval [0,7]. Then an Explore command lets you plot the eigenvalues while using sliders to control the values of x and y. I included code so that imaginary eigenvalues or those outside the given real range would, if any are found, would be reported with print statements.

CP:= (x,y)-> 
   -(lambda-2)^2*(544-lambda^9-328*lambda^7-16*cos(x-y)+6*cos(x-y)*lambda+
   6*cos(x+y)*lambda-408*cos(y)*lambda^2-408*cos(x)*lambda^2+
   540*cos(y)*lambda+540*cos(x)*lambda-28*cos(y)*lambda^4-28*cos(x)*lambda^4+
   152*cos(y)*lambda^3+152*cos(x)*lambda^3+2*cos(y)*lambda^5+2*cos(x)*lambda^5-
   256*cos(y)+17232*lambda^2-256*cos(x)-7852*lambda^5+17768*lambda^4+
   2088*lambda^6+28*lambda^8-16*cos(x+y)-23632*lambda^3-5844*lambda)
:
EV:= proc(x,y)
local r;
   if evalf([x,y])::'list(numeric)' then
      r:= [fsolve(CP(x,y), 'complex')];
      if not r::['realcons' $ 11] or min(r) < -.1 or max(r) > 7 then
         print("Deviant eigenvalue detected:", r, "at", [x,y]) 
      end if;
      r
   else
      [%fsolve(CP(x,y), 'complex')]
   end if
end proc:

Explore(
   plot(
      `[]`~(EV(x,y), 0), 
      style= point, symbol= diamond, symbolsize= 16, 
      axes= box, view= [-1..7, -.1..0.1], size= [1500,200]
   ), parameters= [x= -Pi..Pi, y= -Pi..Pi]
);

 

The root of your problem is the failure to use unapply and really has nothing to do with piecewise, as detailed in Kitonum's Answer. I just want to point out a simpler way to write piecewise expressions: Any piecewise of the form

piecewise(c, e1, not c, e2)

can be expressed as

piecewise(c, e1, e2).

And more generally, any piecewise of the form

piecewise(c[1], e1, not c[1] and c[2], e2, ....,  not `or`(c[1], ..., c[k-1]) and c[k], ek, ...)

can be expressed as

piecewise(c[1], e1, c[2], e2, ..., c[k], ek, ...).

In other words, they are processed left to right such that every condition already includes the negation of all conditions to the left of it.

You have

Sol[1]:= [fsolve([...] union {...})];

That needs to be

Sol[1]:= [fsolve({...} union {...})];

You need to pay attention to whether the interval of integration crosses vertical asymptotes and restrict x accordingly:

int((s^3-5*s^2+1)/(s+2)^2, s = 0 .. x) assuming x > -2;

Have a look at ?Statistics,KernelDensity.

The instructions don't say to replace solve with evalf , they just say to use evalf. The intention was that you first get exact expressions for the critical points with solve. This involves solving some quadratic equations, so there are some square roots in these answers if you input the equations with exact fraction coefficients rather than decimals. Then you can get some decimals for these with evalf. Try this

EquationSet:= {
   diff(x(t),t) = -y(t) - z(t), 
   diff(y(t),t) = x(t) + y(t)/5, 
   diff(z(t),t) = 1/5 + (x(t) - 5/2)*z(t)
};
Solut:= [solve(rhs~(EquationSet), {x,y,z}(t), explicit)];
evalf(%);

 

Your matrix essentially specifies a function from R^2 to R^4. So there are 6 dimensions. One possible way to represent this is as four surfaces---one for each coordinate function. These can be shown as a single 3D plot of four surfaces or as four separate frames arranged as a 2 x 2 array. No matter how you represent it as a plot, you'll need ranges for x and y.

Somewhere in your input expression---likely in several places---you have used square brackets [.] were you should've used round parentheses (.). All algebraic grouping in Maple, no matter how deeply nested, is done with parentheses.

The Explore command seems to not work directly with matrices. I get around this using a procedure M to access the matrix.

M:= (i,j)-> m[i,j]:
Explore(
   plots:-pointplot([seq([M(a,k), .1*k], k= 1..op([1,2], m))]), 
   parameters= [a= 1..op([1,1], m)]
); 

 

The domain is given as (x,t) in (-infinity, infinity). Since that interval is given with rounded brackets () rather than square brackets [], the endpoints are not included. Thus, there's no need for you to be able to evaluate your function at infinity.


 

restart:

The following fsolve technique works because one equation is linear and the other polynomial. The linear equation is used to eliminate a variable, then fsolve will return all real roots for a univariate polynomial.

P1:= y^2 = x^3+x^2:
P2:= y = 2*x+1:
Sys:= (lhs-rhs)~({P1,P2}); #Put into equal-to-zero form.
V:= [indets(Sys, name)[]];
E:= eliminate({P1,P2}, V[2]);
#Could've just as well eliminated V[1] above.
map2(eval, eval(V, E[1]), [fsolve(E[2])]);

{y-2*x-1, -x^3-x^2+y^2}

 

[x, y]

 

[{x = (1/2)*y-1/2}, {y^3-9*y^2-y+1}]

 

[[-.6920214716, -.3840429433], [-.3568958679, .2862082642], [4.048917340, 9.097834679]]

(1)

Here's another (easier) way to find all roots for a polynomial system. This one doesn't rely on being able to eliminate a variable.

RootFinding:-Isolate(Sys, V);

[[x = -.6920214716, y = -.3840429433], [x = -.3568958679, y = .2862082642], [x = 4.048917340, y = 9.097834679]]

(2)

Here's another way to plot systems of bivariate polynomials.

algcurves:-plot_real_curve(mul(Sys), V[], gridlines= false);

 

The great thing about plot_real_curve is that it automatically figures out how big to make the viewing window to capture all the intersections.

 

``


 

Download BivarPoly.mw

No, there's no such library command, but it's trivial to write one. It took me two minutes and nine lines of code.

Okay, I fixed it. The problem is the line

F:= (q,x,alpha)-> expand(eval(u, Solu[1]));

This needs to be changed to

F:= unapply(eval(u, Solu[1]), q, x, alpha);

Then you need to remove the assignment to alpha at the beginning of the worksheet and change the colon after the plot command to a semicolon. That's all there is to it!

First 184 185 186 187 188 189 190 Last Page 186 of 395