Carl Love

Carl Love

28020 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Does n have a definite integer value equal to the number of rows of the Matrix? So the Matrix should be n x J. It is probably i rather than j that is causing the problem.

Also, you should use add instead of sum, and then you don't need the quotes on A[i,j]. Use sum for symbolic summation.

If that doesn't fix the problem, then you'll need to post more of the code.

I think that in general what you are trying to do is impossible. The limit command, unlike int, does not have a procedure option. But if you could rethink your procedure and express it in terms of sum or product then you may be able to use limit.



 

(**)

restart:

(**)

eqn:= arctan(x) + arccos(y/sqrt(y^2+1)) - arctan(4):

(**)

f:= numer(simplify(expand(tan(eqn)))) assuming x>=0, y>=0;

x*y+4*x-4*y+1

(**)

Sol:= [isolve](f);

[{x = -13, y = -3}, {x = 3, y = 13}, {x = 5, y = -21}, {x = 21, y = -5}]

(**)

remove(hastype, Sol, negative);

[{x = 3, y = 13}]

I am somewhat skeptical about isolve's ability to return all the solutions. So, investigating further,

(**)

solve(f,x);

(4*y-1)/(y+4)

(**)

convert(%, parfrac);

4-17/(y+4)

Now it is clear that y = 13 is the only positive integer solution.

 



Download tan_eqn.mw

 

nops([StringTools:-SearchAll("0", sprintf("%d", 2014!))]);

964

Anything between (* and *) is commented out, even if it is multiple lines.

Anything can be a ?symbol (a variable's name) in Maple if you enclose it in back quotes (``), aka accent grave. And symbols can be multiplied with `*`. The multiplication appears as simple juxtaposition when it is printed.

Your original expression is not mathematically correct. It should have a factor of "delta x" on the left side of the equation. Putting it all together, we get this:



(**)

f := x-> x^2; a := 0; b := 1;
for i to 5 do
     print(

          `The answer is `*'f'(x[i])*Delta*x

          = f(a+i*(b-a)/5)*(b-a)/5

     )
end do:

proc (x) options operator, arrow; x^2 end proc

0

1

`The answer is `*f(x[1])*Delta*x = 1/125

`The answer is `*f(x[2])*Delta*x = 4/125

`The answer is `*f(x[3])*Delta*x = 9/125

`The answer is `*f(x[4])*Delta*x = 16/125

`The answer is `*f(x[5])*Delta*x = 1/5

(**)

 



Download fake_mult.mw

printf (and lprint) produce only 1d output. Perhaps you can acheive what you want by using the unevaluated form of fi.e., by enclosing it in forward single quotes 'f'.



(**)

f := x-> x^2; a := 0; b := 1;
for i to 5 do  

     print('f'(x[i])=f(a+i*(b-a)/5)*(b-a)/5)

end do;

proc (x) options operator, arrow; x^2 end proc

0

1

f(x[1]) = 1/125

f(x[2]) = 4/125

f(x[3]) = 9/125

f(x[4]) = 16/125

f(x[5]) = 1/5

(**)

 



Download unevaluated.mw

Is that what you want?

 

a(0) = 1

a(n) = 3*2^(n-1), n > 0

Here is the final evalhf/module version of your program. It runs in about 7 seconds; so, about a factor-of-8 improvement over the regular version.

Combi:= module()
export
    probVector::Vector(realcons),  #probability vector
    lambdaVector::Vector(realcons)
;
local
    Combi:= proc(
        k::integer,
        boxContent::Vector,
        activeBox::integer,
        marblesRemaining::integer,
        Output::Matrix,
        Index::Vector,
        p::Vector
    )       
    local j::integer;
        
        if activeBox < k then
            for j from 0 to marblesRemaining do
                boxContent[activeBox]:= j;
                thisproc(k, boxContent, activeBox+1, marblesRemaining-j, Output, Index, p)
            end do
        else
            boxContent[activeBox]:= marblesRemaining;
            Index[1]:= Index[1] + 1;
            Output[1, Index[1]]:= n!*mul(p[j]^boxContent[j], j= 1..k)/mul(boxContent[j]!, j= 1..k);
            Output[2, Index[1]]:= `if`(
                mul(boxContent[j], j= 1..k) = 0,
                undefined,
                -2*add(boxContent[j]*ln(n*p[j]/boxContent[j]), j= 1..k)
            )    
        end if
    end proc,

    ModuleApply:= proc(n::posint, k::posint, p::~Vector(realcons))::identical();
    local
        Index::Vector(realcons), Output::Vector(realcons),
        boxContent::Vector(realcons)  #A vector whose i'th entry holds the number of marbles in the i'th box
    ;
        boxContent:= Vector(k, datatype= float[8]);
        Output:= Matrix(2, binomial(n+k-1, k-1), datatype= float[8]);
        Index:= Vector(1);
        evalhf(Combi(k, boxContent, 1, n, Output, Index, p));
        probVector:= Output[1, ..];
        lambdaVector:= Output[2, ..];
        [][]
    end proc
;
end module;


A recursive procedure

restart

with(Statistics):

n := 40:

k := 6:

p := Vector(k, proc (i) options operator, arrow; 1/k end proc):

(**)

 

Combi:= module()

module () local Combi, ModuleApply; export probVector::(Vector(realcons)), lambdaVector::(Vector(realcons)); end module

``

B := CodeTools[Usage](Combi(n, k, p));

``

Combi:-probVector[1221759];

HFloat(7.480833428389761e-32)

Combi:-lambdaVector[1221759];

HFloat(HFloat(undefined))

NULL


Download A_recursive_procedu.mw


(**)

restart:

(**)

d:= proc(s)  option remember;  parse(s)  end proc:
d("0"):= 1:

(**)

p:= n-> `*`(map(d, StringTools:-Explode(sprintf("%d", n)))[]):

(**)

add(p(n), n= 1..2014);

194785

(**)

 


Download product_digits.mw


1.

(**)

restart:

(**)

B:= 2*A:  C:= 4*A:

(**)

solve(A+B+C = Pi, A);

(1/7)*Pi

(**)

A:= %:

By law of sines:

(**)

b:= sin(B)*a/sin(A):  c:= sin(C)*a/sin(A):

(**)

simplify(1/b + 1/c);

1/a

2.

(**)

simplify(cos(A)^2 + cos(B)^2 + cos(C)^2);

5/4

(**)

 


Download Geometry.mw


(**)

x:= 2014!/5^20:

(**)

d:= 0:

(**)

while d=0 do x:= iquo(x,10,'d') end do:

(**)

d;

6

(**)

 


Download 2014.mw


(**)

restart:

(**)

solve(t^2-2016*t-1, t);

1008+1016065^(1/2), 1008-1016065^(1/2)

(**)

lambda:= %[1]:

(**)

x:= proc(n::posint)
option remember;
     floor(lambda*thisproc(n-1))
end proc;
x(0):= 1;

proc (n::posint) option remember; floor(lambda*thisproc(n-1)) end proc

1

(**)

x(2016) mod 2016;

1009

(**)

 


Download 2016.mw


x:= 4/mul(5^(1/2^k)+1, k= 1..4);

4/((5^(1/2)+1)*(5^(1/4)+1)*(5^(1/8)+1)*(5^(1/16)+1))

(**)

rationalize(%);

`[Length of output exceeds limit of 100000]`

(**)

expand(%);

-1+5^(1/16)

(**)

(%+1)^48;

125

(**)

 


Download 125.mw

Here is an example of multivariate Newton's method. I didn't have access to your equations, so I made some random similar examples.


F:= ['randpoly([y[k] $ k= 1..5], degree= 3) +
      randpoly([y[k] $ k= 1..5], degree= 1, dense)'
    $ 5];

[57*y[1]^2*y[3]-49*y[1]*y[2]*y[5]+31*y[2]^3+73*y[2]*y[5]^2-84*y[1]*y[3]+95*y[1]+148*y[2]-29*y[3]+5*y[4]-26*y[5]-51, 80*y[1]*y[2]*y[5]+90*y[1]*y[3]*y[5]-57*y[1]*y[3]+85*y[4]^2+74*y[1]+27*y[2]+9*y[3]-127*y[4]+81*y[5]+70, 36*y[1]^2*y[3]-8*y[2]^3+30*y[2]*y[3]^2-3*y[3]^2*y[5]-56*y[3]*y[4]^2-5*y[2]^2-91*y[1]-70*y[2]+42*y[3]+9*y[4]-21*y[5]-27, 49*y[1]*y[2]*y[4]-58*y[3]^2*y[5]+49*y[3]*y[5]^2-44*y[2]*y[4]-31*y[2]*y[5]+45*y[5]^2+y[1]-95*y[2]+86*y[3]-97*y[4]-14*y[5]+83, 96*y[1]^2*y[3]-51*y[1]*y[2]*y[3]+89*y[1]*y[3]*y[5]+14*y[2]*y[5]^2-79*y[3]*y[4]^2-58*y[1]-95*y[2]+123*y[3]-2*y[4]+86*y[5]+57]

(**)

fsolve(F);

{y[1] = -1.52634660833751, y[2] = 1.14614000845494, y[3] = -0.912884720559115e-1, y[4] = -.156870015505402, y[5] = 0.268564748179879e-1}

(**)

J:= VectorCalculus:-Jacobian(F, [y[k] $ k= 1..5]):

(**)

Y:= <[1$5]>:  #Dummy first iteration.

(**)

Y1:= <[0$5]>:  #Initial guess

(**)

for n to 100 while LinearAlgebra:-Norm(Y-Y1) > 1e-15 do
     Y:= evalf(Y1);
     Y1:= Y - LinearAlgebra:-LinearSolve(
          eval(J, [seq](y[k]= Y[k], k= 1..5)),
          <eval(F, [seq](y[k]= Y[k], k= 1..5))>
     )
end do:

(**)

n;

7

(**)

Y1;

Vector(5, {(1) = -.937327749126478, (2) = .819756118294004, (3) = -0.193900192863524e-1, (4) = .123223922590096, (5) = -.340268950372420})

Note that we obtained a different solution than fsolve. There are multiple solutions.

(**)

eval(F, [seq](y[k]= Y[k], k= 1..5));

[HFloat(1.4210854715202004e-14), HFloat(0.0), HFloat(0.0), HFloat(0.0), HFloat(7.105427357601002e-15)]

(**)

 


Download MVNewton.mw

First 352 353 354 355 356 357 358 Last Page 354 of 395