Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Your first line is x:= x0. That should be x0:= x.

Then you'll have a problem because your last two break statements are not in a loop. I suggest that you change your procedure to something like this:

proc_r:= proc(x :: realcons)
local x0;
     x0:= evalf(x);

     #reducing the value to between -Pi and Pi
     while x0 > evalf(Pi) do  x0:= x0 - 2*evalf(Pi)  end do;
     while x0 < evalf(-Pi) do  x0:= x0 + 2*evalf(Pi)  end do;

     #using the symmetry of sin to reduce to between -Pi/2 and Pi/2
     if x0 > evalf(Pi/2) then  x0:= evalf(Pi) - x0
     elif x0 < evalf(-Pi/2) then  x0:= evalf(-Pi) - x0
     end if;

     return x0
end proc:

proc_r(7);  
                                   0.71681469282042

If M is your Matrix, then do

ArrayTools:-AddAlongDimension(M,2);

@Andriy Here is your file with my modifications. All I did was change q and Np from globals into parameters. Please check that this generates the correct matrix, and compare the time to sequential code on a reasonably sized example. The Grid option will no doubt take longer on an example that is too small.

MatrElems_Carl1.mw

plot([cosh(x), x^2], x= -2..2);
f:= x-> x^2:
r:= fsolve(cosh(x)=x^2, x);
[r, f(r)], [-r, f(-r)];

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.

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