Carl Love

Carl Love

28050 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Erik wrote:

I need to declare a parameter, which is a vector of lists.

Usually there's no actual "need" to declare a parameter to have a very specific type, but doing so can help with debugging.

Example of element:

< [3,7,2,4], [-3,6,8,0], [-5,8,4,2]>

There is a quirk (bug perhaps?) with the `<,>` Vector constructor such that the above creates a 3x1 Matrix with list entries rather than a Vector. It can be converted to a Vector with convert(..., Vector).

Vector has n components and each list has k components. I tried declaring it like:

boxVector:=Vector(n,datatype=list());

When you create it like that you need to subvert the default fill, 0, because 0 is not a list. Like this:

boxVector:= Vector(n, fill= [], datatype= list);
or
boxVector:= Vector(n, fill= [0], datatype= list(integer));
or
boxVector:= Vector(n, fill= [0$k], datatype= [integer$k]);

To do type checking, you can compare against the type 'Vector'(list)'Vector'(list(integer)), or 'Vector'([integer$k]).

Pass the remaining equations to fsolve. It will probably use something like Newton's Method, but if it uses something else... so what? as long as you get the solution.

Assign your output to a variable, let's say out.

out:= %:

Then

sprintf("%q", out)[1..1000];

will show the first 1000 characters of the output.

I don't see any problem with the existence of commands to make plots look exactly like you want. You don't have to use them if you don't want to.

Just replace * with `&ast;`. If you want to see it clearly, you can increase the font size with axesfont= [TIMES, ROMAN, 14], or any point size that you want.

plot(x^2, x= -1..1, tickmarks= [[1/2=x^`&ast;`], [1='a']], axesfont= [TIMES,ROMAN,14]);

If you don't want to see a symbol attached to assumed variables, then issue the command:

interface(showassumed= 0);

Regarding your differential equation, it would be best if you did not use I as a variable, as it is reserved for the imaginary unit. (If you really want to use I, there is a way around that.) Here, I use J.

diffeq:= diff(J(b), b) - 2*J(b)*b = -sqrt(Pi)*exp(-2*a*b);

Differential equations are solved in Maple with dsolve, which handles this one quite readily:

dsolve(diffeq);

You wrote:

When I first tried the integration w.r.t. the parameter b (with the assumptions), I could not get the solution shown above. Should I take away the assumptions (which is only logical when differentiang wrt it)? Actually, I got the solution above only after I started formulating this question for this newsgroup. The reason why I started with the assumption is that I did not want any compex solutions (which I got for another problem). So, the question is really if it is possibe to relax the assumptions just for the sake of differentiating the integral?

As far as I can tell, the assumptions make no difference.

The mathematical constant Pi is spelled with a capital P in Maple. If you use a lowercase p, then you get an ordinary variable that prints as the Greek letter. (So there is often no way to visually determine from the output whether the Pi was entered correctly.)

ex:= sqrt(x*y*z)/(x*y*z):
simplify(ex, symbolic);

applyrule(1/sqrt(a::algebraic)*1/sqrt(b::algebraic)= 1/sqrt(a*b), %);

 

For the first problem, I'd do

L:= [[1,3], [5,8], [9,2], [5,12]]:
[seq](x[2], x in L);

For the second problem

L:= [4,2,-1,9,5,6,2,0,14,7]:
['L[2*k]' $ k= 1..iquo(nops(L),2)];

I cut and paste your 6 lines of Cyrillic text into a Windows Notepad document. Then I saved it using encoding scheme UTF-8 (the Save As dialog offers four encoding schemes: ANSI, Unicode, Unicode big endian, and UTF-8). Then I was able to read the entire file in Maple using FileTools:-Text:-ReadLine.

Change y'k':= to y||k:=


You wrote:

I know how to solve this problem in fortran....

I am curious, How do you solve it in fortran? I am somewhat surprised that any third-generation compiled language allows for variable variable names.

For b < 0, it is not true that -b + sqrt(b^2) = 0. But if we make sufficient assumptions on beta and z, Maple will simplify it to 0.

restart:
assume(z>0, beta>0);
b:= 3*beta*Pi*(3-4*cos(z)+cos(2*z))/(16*z):
-b+sqrt(b^2);
                               0

I think that it's fairly impressive that Maple proves, without further prompting (via e.g. simplify or is), that 3 - 4*cos(z) + cos(2*z) >= 0 for all z > 0.

You asked:

which package in maple can I use to solve nonlinear ODEs

Since your next question is about Newton's method, I am guessing that you mean numerical solution. Is that right? There is no separate package for it; it is all handled by command ?dsolve . See also ?dsolve,numeric .

Also, can I use the Newtons Method?

You cannot use it directly, but it can be a component of the solution method. There are 15 solution algorithms for IVPs, four for BVPs, and three for DAE/IVPs. Many of those allow for an implicit option, which is, I guess, like using Newton's method to solve the system for the numeric derivatives.

If you have an object and a procedure that you want to apply to all of its subobjects of a given type, the command for that is subsindets or evalindets.

Round2:= proc(x, n::nonnegint:= 1)
     if x::float then
          parse~(sprintf~(cat("%.",n,"f"), x))
     else
          subsindets(x, float, thisproc, n)
     end if
end proc;

Just guessing here, because I don't have time to test this right now. I think that you need to divide each color number by 256, and possibly do an evalf also, to put it in the 0..1 floating-point form that Maple plots expect.

Code occuring inside procedure or function definitions is not evaluated until the procedure is called. In your case, the i is not being evaluated at the time you create the arror (->) expressions. The way around this is to use ?unapply , which evaluates the expression first and then makes it into a procedure.

procVec3:= proc(U::~Vector(realcons))::list(procedure);
local i::posint, u::symbol;
 
     [seq](unapply(piecewise(u < U[i-1], 0, u < U[i], 1), u), i= 2..numelems(U));
end proc;

Some other pointers:

  1. It is a bad practice (very inefficient) to assign to list entries, although Maple will begrudingly allow it for lists with fewer than 101 elements. The alternative is to assign to a Vector, table, or Array. These can be easily converted to a list when you're done assigning.
  2. There is no need to contruct a list or to initialize its entries to 0 before assigning it or to its entries. Vectors and Arrays need to be constructed (and are automatically initialized to 0). It's a good idea to construct a table before assigning, though not strictly necesary. Tables are not initialized to 0 unless sparse is specified in the constructor.
  3. There is no need to return something which was the last expression evaluated; it is automatically returned.
  4. It is a bad idea to use explicit compound conditions (e.g. conditions with and or or) directly in piecewise. Compound conditions can be expressed in inert form, And(..., ...), or just use the natural left-to-right number-line order like I did above (see ?piecewise ).
  5. There is no need to declare the type of every variable, although it will help with debugging. In the above procedure, I went a bit overboard with the type declarations just to show what is possible.

How about a single command rather than a do loop?

f||(1..99):= 'randpoly([y||(1..99)])+`+`(y||(1..99))' $ 99:

Now your functions are named f1, f2, ..., f99.

As Markiyan said, these variables are not subscripted, strictly speaking.

First 354 355 356 357 358 359 360 Last Page 356 of 395