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

I don't know what the ultimate goal is, so I am not sure that this is correct. But surely ormap is a better way to add a Vector to an Array of Vectors iff it is not already in the Array. This code increases the size of the Array by 1 each time a new entry is added.

proc_cerny1:= proc(A::Matrix, B::Matrix, C::Vector[row], N::nonnegint)
local x:= 2^N, S:= Array(0..0, fill= C), i, j:= 1, T, R;
     for i from 0 to x-1 while i <> j do
          T:= S[i].A;
          if not ormap(LinearAlgebra:-Equal, S, T) then
               j:= j+1;
               S(j):= T #not S[j]
          end if;

          R:= S[i].B;
          if not ormap(LinearAlgebra:-Equal, S, R) then
               j:= j+1;
               S(j):= R
          end if
     end do;
     S
end proc:

My solution allows you to create, display, and assign the sequence all in one step. It also works for lists and sets. You only need to append a ! to the object. I chose ! because it is reminiscent of a column. This does not affect the usage of ! for factorials.

This version only works in Maple 17. If you need it for earlier Maple, I can make some slight modifications.


restart:

local `!`:= overload([
     proc(a::anything, b::anything)
     option overload;
     local x:= b; #Force a check for a second argument
          seq(print(x, ``), x= [args[1..-2]]);
          print(args[-1]);
          args
     end proc,

     proc(L::{list, set})
     option overload;
     local x;
          seq(print(x, ``), x= L[1..-2]);
          print(L[-1]);
          L
     end proc,

     factorial
]):
          

S:= (A,B,C)!:

A, ``

B, ``

C

S;

A, B, C

S:= [a,b,c]!:

a, ``

b, ``

c

S;

[a, b, c]

S:= {a,b,c}!:

a, ``

b, ``

c

S;

{a, b, c}

Factorials still work.

n!, 4!;

factorial(n), 24

 


Download overload_!.mw

You have a first-order ODE, so dsolve will only allow one condition, even though the presence of the a should allow for another condition. We can fool dsolve into accepting a second condition by making a a constant function, i.e. a function whose derivative is 0, and then treating the system as a BVP.

restart:
fx:= diff(n(x),x)-a(x), diff(a(x),x) :
eval(n(x), dsolve({fx, n(0) = 1, n(1) = 2}, {a(x), n(x)}));

constants:= ({constants} minus {gamma})[];

A procedure is a mutable data structure, just like a table, Array, or module.

Use applyrule instead of algsubs:

applyrule(P^q + R_(n+1)^q = B, %);

a) f:= x-> x^3;  g:= x^3;

b) f(2);  eval(g, x= 2);

c) f(y);  eval(g, x= y);

d) x:= 2:  eval(f);  eval(g);

is(5 in {seq(13 &^ k mod 100, k= 1..1000)});

sqrt(`*`(select(isprime, [$1..99])[]));

If you want a for loop to count down instead of up, then you need to include the phrase by -1:

for i from n-1 by -1 to 1 do ...

If you want your output to show what is happening in the loop, then you need to increase printlevel:

printlevel:= 10:
for i from n-1 by -1 to 1 do
...

In your int command, include the option method= _d01ajc. The answer will be returned nearly instantly.

E_clear:=int(I_real, t= t_rise..t_set, numeric=true, method= _d01ajc);
                                       

See ?evalf,int for details.

Replace both lines with the single command

remove(type, identify(d), float);

Matrix multiplication is associative, so grouping in different ways with parentheses is worthless.

If B is invertible, then it is trivial to prove that your expression equals A. So choose a B that is not square but such that B.B' is invertible. (Make B m x n with m < n.)

What your purpose in doing the exercise? That is, Is the goal to perform an exercise of writing the most robust numeric code possible? Or is the goal simply to get the answers? What is the form of the coefficients? Are they exact rational numbers? floating-point numbers? or something more complicated?

If the goal is simply to get the answers, the best option is to use the command solve; it will handle any type of coefficient. Example:

solve(2*x^2 + 3*x + 4 = 0, x);

If you know that you want floating-point answers, then use fsolve:

fsolve(2*x^2 + 3*x + 4 = 0, x);

If your goal is the robust-code-writing exercise, then you need to write a procedure, the skeleton of which looks like this:

SolveQuadratic:= proc(A::float, B::float, C::float)
# Solve A*x^2 + B*x + C = 0
numerically
local ... 
#Any other variables in the procedure go here

... #Body of procedure

end proc;

Feel free to ask for more details. All of the above will work in Maple 5.

Here's a start. I have a feeling that this can be improved. I can't test without having your procedure elem.

restart:
Elem:= proc(i,j)
option remember;
     Elem(j,i):= elem(i,j)
end proc:

N:= 2^10:
A:= Matrix(N, N, shape= symmetric);
for i to N do
     A[i,..]:= < Threads:-Seq(Elem(i,j), j= 1..N) >
end do:

 

First 322 323 324 325 326 327 328 Last Page 324 of 395