Carl Love

Carl Love

28070 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

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:

 

Motivated by Axel's analysis, I looked more closely for solutions for the situations that RootFinding:-NextZero rejected. I used a "microscope", searching very close to the origin. By that I mean that I used semilogplot and applied fsolve to numer(f(10^d)) rather than to f(d). I plotted in all cases, and the sequence of plots really shows what's happening.

The first point remains a mystery because the limit(f(d), d=0, right) = -infinity (as Axel noted) where one would expect 0. The limit for the other points is in fact 0, and the plots seem like a continuous progression.

 

restart:

L := convert(
     [[1.0, 0.75e-1], [2.0, .1], [3.0, .12], [4.0, .14], [5.0, .16],
     [6.0, .18], [7.0, .2], [8.0, .22], [9.0, .24], [10.0, .26]],
     rational
):

NN := -N+(N0B-NB)*(erf((1/2)*x/(sqrt(t)*sqrt(d)))
     -sqrt(erf((1/2)*alpha/d)))/sqrt(erfc((1/2)*alpha/d))+NB:

 

alpha:= 2*10^(-12):  NB:= 75/1000:  N0B:= 2/10:  t:= 360000:

 

NNlog:= eval(NN, d= 10^d):

Digits:= 50:

for k to nops(L) do
     f:= numer(simplify(eval(NN, [x,N]=~ L[k])));
     f_log:= numer(simplify(eval(NNlog, [x,N]=~ L[k])));
     printf("\nTrying x= %f, N= %f\n", evalf[5](L[k])[]);
     dd:= fsolve(f_log, d= -6..-3); #10^(-6) .. 10^(-3)
     if dd::numeric then
          printf("Solution found: d= %a\n", evalf[15](10^dd));
     else
          printf("No solution found.\n");
     end if;
     print(plots:-semilogplot(f, d= 1e-14..1e-2, labels= [d,'NN']))
end do:


Trying x= 1.000000, N= 0.075000

No solution found.


Trying x= 2.000000, N= 0.100000
Solution found: d= .864547473017420e-4


Trying x= 3.000000, N= 0.120000
Solution found: d= .570969017295855e-4


Trying x= 4.000000, N= 0.140000
Solution found: d= .445134288859349e-4


Trying x= 5.000000, N= 0.160000
Solution found: d= .350843030752839e-4


Trying x= 6.000000, N= 0.180000
Solution found: d= .253007839385319e-4


Trying x= 7.000000, N= 0.200000

No solution found.


Trying x= 8.000000, N= 0.220000

No solution found.


Trying x= 9.000000, N= 0.240000

No solution found.


Trying x= 10.000000, N= 0.260000

No solution found.

 

Download erf_solve_2.mw


restart:

OA,OB,OC:= 3$3:  AB:= 3*sqrt(2):  BC:= 2*sqrt(2):

Law of cosines:

LoC:= c^2 = a^2 + b^2 - 2*a*b*cos(C):

eval(LoC, [c= AB, a= OA, b= OB, C= AOB]):

AOB:= solve(%, AOB);

(1/2)*Pi

eval(LoC, [c= BC, a= OB, b= OC, C= BOC]):

BOC:= solve(%, BOC);

arccos(5/9)

eval(LoC, [c= AC, a= OC, b= OA, C= 2*Pi-AOB-BOC]):

solve(%, AC);

14^(1/2)+2, -14^(1/2)-2

Take the positive value. So the answer is

%[1];

14^(1/2)+2

 


Download triangle.mw

In order to get a numeric result, you need two numeric limits of integration. Use Int instead of Intat, and then apply evalf.

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