Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 358 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

You asked:

[I]s there other way to solve functions with several real and imaginary solutions?

Yes. Assuming that solve can return a solution that contains expressions of the form RootOf(f(_Z)) where f(_Z) is a polynomial in _Z (this is true in your case) and that you can supply numeric values for all parameters and for x, then you can use a combination of evalf and allvalues to return all real and imaginary values for y.

Your usage of the word "function" is nonstandard here. Your Fun is an expression, and since it is presumed to be set equal to 0, it is also implicitly an equation; but it is not a function. Anyway, one solves equations, not functions.

In my revision of your code below, I changed D to DD because is used for derivatives in Maple. Your use of wasn't causing any problem, but it's best to avoid potential problems later by not using now.

Note that the code below executes in a few seconds and uses minimal memory.

 

 

 

restart:

Fun:= (1/8)*x^2*Y0*sqrt(Zt^2+((3/8)*A*y^2-(1/2)*x+1+(1/4)*G*y^2+(1/4)*DD)^2)/(((1/4)*G*y^2+(1/4)*DD)^2-((3/8)*A*y^2-(1/2)*x+1)^2-Zt^2)-y;

(1/64)*x^2*Y0*(9*A^2*y^4+12*A*G*y^4+4*G^2*y^4+12*A*DD*y^2-24*A*x*y^2+8*DD*G*y^2-16*G*x*y^2+48*A*y^2+32*G*y^2+4*DD^2-16*DD*x+64*Zt^2+16*x^2+32*DD-64*x+64)^(1/2)/(((1/4)*G*y^2+(1/4)*DD)^2-((3/8)*A*y^2-(1/2)*x+1)^2-Zt^2)-y

solveValue:= solve(eval(Fun, [G= 0]), y);  

RootOf(81*A^4*_Z^10+(-432*A^3*x+864*A^3)*_Z^8+(-72*A^2*DD^2+1152*A^2*Zt^2+864*A^2*x^2-3456*A^2*x+3456*A^2)*_Z^6+(-9*A^2*Y0^2*x^4+192*A*DD^2*x-3072*A*Zt^2*x-768*A*x^3-384*A*DD^2+6144*A*Zt^2+4608*A*x^2-9216*A*x+6144*A)*_Z^4+(-12*A*DD*Y0^2*x^4+24*A*Y0^2*x^5-48*A*Y0^2*x^4+16*DD^4-512*DD^2*Zt^2-128*DD^2*x^2+4096*Zt^4+2048*Zt^2*x^2+256*x^4+512*DD^2*x-8192*Zt^2*x-2048*x^3-512*DD^2+8192*Zt^2+6144*x^2-8192*x+4096)*_Z^2-4*DD^2*Y0^2*x^4+16*x^5*DD*Y0^2-64*Zt^2*Y0^2*x^4-16*x^6*Y0^2-32*DD*Y0^2*x^4+64*Y0^2*x^5-64*Y0^2*x^4)

evalf([allvalues(eval(solveValue, [A= 2, x= 3, DD= 5, Y0= 7, Zt= 11]))]);

[.729156354449306, 2.80900869584687+2.70574777512511*I, 2.68464259020886+2.59022505377347*I, -2.68464259020886+2.59022505377347*I, -2.80900869584687+2.70574777512511*I, -.729156354449306, -2.80900869584687-2.70574777512511*I, -2.68464259020886-2.59022505377347*I, 2.68464259020886-2.59022505377347*I, 2.80900869584687-2.70574777512511*I]

``

 Baharm32.mw

Maplesoft conducts several webinars each month. A significant percentage of those are about application development. In Maple, go to the Help menu, then "On the web", then "Stay informed", then "Subscribe to Newsletter".

What I see are three planes plotted in the unit cube: -x+y+z = 1, x-y+z = 1, and x+y-z = 1. It seems logical to me.

max is simply a commutative and associative n-ary arithmetic operation like addition or multiplication. An explanation of max(...) = constant would be as banal as an explanation of a sum of expressions being contant.

Yes, restart should always be in a separate execution group. Various somewhat unpredictable things can happen if it is not. The help page ?restart says that it should always be on a separate "line". This vague concept of a "line" of code is utter nonsense---the parser treats line breaks as white space. The word "line" needs to be replaced with "execution group".

PS: The command with should never be used inside a procedure (unless you really understand how it works). The results are predictable, but usually unexpected and undesirable. Use uses instead of with inside a procedure. It is because of the with that you need to execute twice. The global names used in a procedure need to be bound at the time that the procedure is invoked; they can't be dynamically rebound with with as the procedure executes. Your first execution rebinds the names. Your second execution uses the newly corrected package-bound names.

Take the logarithm of the function and the contour levels. This causes no change in the shape of the plot. It only rescales the colors.

plots:-contourplot(
     ln(exp(2*x/(x^2+y^2))), x= -2..2, y= -2..2, grid= [100$2],
     coloring= [blue, red], contours= ln~([.1, .3, .5, 1, 2]), filledregions
);

All that you need is

D(p)(v);

I'd be amazed if there weren't an easy one-line way to do it in Mathematica also.

 

This is an annoying, but documented, feature of assuming. Specifically, assuming doesn't work on variables that only appear inside functions. It is mentioned on the help pages ?assuming and ?assuming,details. Since it seems to have been designed that way, perhaps there are situations where this behavior is desirable. I can't think of any right now. To work around:

A:= mmFun(t);
simplify(A) assuming g__1::positive;

This works because g__1 appears at the top level in expression rather than inside a function.

In your "this works sometimes" addendum, the map is insignificant. It works because the resultMatrix contains the already-evaluated function call.

 

z:= x+I*y:
plots:-intersectplot(
     abs(z^2/2+3*z-1), 1, x= 0..1, y= -0.5..0.5,
     axes= frame, orientation= [270,0]
);

An empty matrix can be created with simply Matrix(), or, if you want to be more explicit, Matrix(0).

Your construction, [][], is equivalent to NULL, which is a valid expression sequence but not a Matrix. Nonetheless, your procedure does work exactly as you wrote it. Why do you say that it doesn't work? Perhaps your function_coeffs is wrong. 

Your procedure can be simplified to

Initial_Matrix:= proc(BC::list, n, BP::list)
local bc;
     <seq(function_coeffs(bc, n, BP), bc= BC)>
end proc;

You don't need a loop to define indexed procedures. A procedure can "see" the index with which it's called by using op(procname). Do this:

u:= t-> L/2*cos(w*t);
v:= t-> H*sin(w*t+phi[op(procname)])

Braces can't be used as an "outer level" of parentheses. Only parentheses can be used for algebraic grouping. Braces have a highly specialized meaning: enclosing the elements of a set. I'm not aware of any practical computer language that allows anything other than plain round parentheses for algebraic grouping, although such usage is standard in mathematical writing.

Unfortunately, I can't find a help page that says this. However, I'm absolutely sure that it's true for Maple's Maple Input (aka 1D input). 

According to the Fundamental Theorem of Linear Algebra, the null space of a matrix is the orthogonal complement of the row space. So, use command LinearAlgebra:-NullSpace, like this:

A:=<4,1,0,0; 0,0,4,1>:
A1:= <A, `<|>`(LinearAlgebra:-NullSpace(A)[])^+>;

Now A1 will be the matrix that you want, with the new rows added at the bottom.

You need to distinguish between equations (made with the equals sign =) and assignment statements (made with the := operator). What you want in this case are equations. Use seq instead of for for the looping:

Eqs:= [seq(
     u[i, j] = (u[i-1, j] + u[i+1, j] + lambda*(u[i, j-1]+u[i, j+1]) +
                 sigma(h, r[i+1])*(u[i+1, j]-u[i-1, j]))/mu,
     i= 1..6
)];

An equation is an object which can later be solved or otherwise manipulated. An assignment is a command---an action---which has no existence after it is performed.

Both in math and in Maple, matrix indices start at 1. However, if you want to start at 0, you can use an Array, which is very much like a Matrix:

N:= 3:
K:= Array((0..N)$2, (i,j)-> D[1$i,2$j](k)(0,0)/i!/j!);

N needs to be defined before the Array, but does not.

One advantage of a Matrix is that it'll show up on screen as a matrix, in the ordinary fashion, if it's sufficiently small. We can shift the indices to make this a Matrix:

N:= 9:
k:= (x,y)-> exp(x)*sin(y):
K:= Matrix((N+1)$2, (i,j)-> D[1$(i-1),2$(j-1)](k)(0,0)/(i-1)!/(j-1)!);

Use sprintf, not cat, to convert Maple expressions to strings:

r:= sprintf("dsolve(%q,y(x))", eq);

Or use fprintf to send the string directly to a file.

If you use the %q format, then the strings will always be rereadable as Maple code.

First 237 238 239 240 241 242 243 Last Page 239 of 395