Carl Love

Carl Love

28095 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

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.

fun_coeff:= proc(p::algebraic, ux::function(name), n::nonnegint)
local P:= convert(p, :-D), u:= op(0,ux), x:= op(ux), k;
     [seq(coeff(P, (D@@k)(u)(x)), k= 0..n)]
end proc:    

fun_coeff(P, u(x), 4);

Use the arrow operator -> to define functions. By combining this with `if`, the definition can be specialized to the first argument being 0.5:

g:= (x,y)-> `if`(x=0.5, 200*y, 'procname'(args)):

y:= 4:
g(0.5, 4);

     800

g(x,y);

     g(x, 4)

You simply need the elementwise operator ~:

EQ=~0;

If you end your intermediary commands with a semicolon rather than a colon, you'll be able to track down the error more easily. Upon doing this, I quickly see that at least one of the intermediary results, the one that you called s[2], contains the value Float(infinity). This indicates some invalid operation, akin to dividing by 0, was attempted.

Regarding the use of colon or semicolon inside loops: All that matters is which is after the end do (or equivalent) of the whole loop. So you might as well use semicolons for the statements inside loops because it's easier to type.

You can't treat a variable (aka a symbol or a name), such as s, and its indexed subscripted forms, such as s[2], as if they were separate and independent variables. This can cause trouble if you assign to the subscripted form and then attempt to use the unsubscripted form as a free variable (which is exactly what you do here), and it'll definitely cause trouble if you assign to both of them. I'm not sure if this is the source of all or any of your trouble, but it must be corrected before we can move forward.

This caution about subscripted names only applies to indexed subscripted names, i.e., those formed with square brackets. If you form the subscript by using double underscore __ or double vertical bar || or a combination of those, then you can treat the resulting names as separate and independent variables.

 

Okay, after letting it rest in my mind for a few days, I understand what you're trying to do. I think that I have some vastly simplified procedures for it. Let me know if these do the job for you.

The first thing is to simplify F and Finv. This is what I got:

restart:

(a,b):= (4,1):

Fp:= x-> (U-> x+2*U*b-a*U^2)(1+floor((2*b-a+sqrt((2*b-a)^2+8*a*x))/2/a)):
Fm:= x-> (U-> x+2*U*b+a*U^2)(ceil((-2*b-a+sqrt((2*b+a)^2-8*a*x))/2/a)):
F:= proc(x) option remember; Fm(Fp(x)) end proc:

Fpinv:= x-> (U-> x+2*U*(a-b)-a*U^2)(1+floor((a-2*b+sqrt((2*b-a)^2+8*a*x))/2/a)):
Fminv:= x-> (U-> x+2*U*(a-b)+a*U^2)(ceil((-3*a+2*b+sqrt((3*a-2*b)^2-8*a*x))/2/a)):
Finv:= proc(x) option remember; Fminv(Fpinv(x)) end proc:  

I do believe, as you do, that Finv is the inverse of F. However, I didn't need to use it to write procedure MEC.

MEC:= proc(n::nonnegint)
local N:= {$0..n}, ic, Escape, Capture;
     for ic from 0 to n do
          if F(ic) > ic then Escape[F(ic)]:= true
          elif F(ic) < ic then Capture[ic]:= true
          end if
     end do;
     Escape:= {indices(Escape, 'nolist')};
     Capture:= {indices(Capture, 'nolist')};
     N minus Escape minus Capture, Escape intersect N, Capture
end proc:

Using it on your example:

MEC(12);

The key to understanding the above procedure is that Escape and Capture are Maple tables rather than Boolean arrays. The true that I used is just a dummy; an assignment of anything would do. The Boolean information is conveyed simply by the fact that an entry is assigned. Then the indices command is used to extract all assigned entries.

Let me know if the above does the job for you.

You do it by using x(t) instead of x and y(t) instead of y:

f:= x(t)^2 + y(t)^2:
diff(f, t);

The option maxmesh is an option for the dsolve command, not for the odeplot command. So, if you do

sol:= dsolve({ode,ics}, numeric, maxmesh= 1000):
plots:-odeplot(sol, [x, y(x)], x=0..1);

then it'll work.

You say that you increased the precision in the Options menu. What did you increase it to? If I increase it to 40, then I get accurate results (for the plot in question). Rather than using the options menu, it is better to use the Digits environment variable.

Digits:= 40:

You can test the accuracy of the computation by using the shake command. For example, let's apply it to the last point in your plot. The second argument to shake is the number of Digits of precision.

expr:= eval(m(450, (1/250)*x, 250), x= 100): #Make sure to use exact rationals in this line.
shake(expr, 10);

     INTERVAL(-3.44691114182*10^28 .. 3.45185884337*10^28)

shake(expr, 40);

    INTERVAL(1.96553109914429154721697440528449547786023 ..
    2.03451842008920754181567678008881546299414)

shake(expr, 50);

     INTERVAL(2.000000043280774985094379521387152201289707358740187 ..  
     2.000000043287679818113471795018001692671257692766963)

The above indicates that at 10 digits precision (the default), the computation is total garbage; at 40 digits precision, there are two accurate digits; and at 50 digits precision, there are 11 accurate digits.

In Maple's 2D input, it's illegal to put a space between a function's name and its arguments. You have, for example, printf ("*"). That needs to be changed to printf("*")

After you correct that, you still have a small logic error that prevents the first line from being printed. I'll let you figure that out. Let me know if you can't.

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