Carl Love

Carl Love

27291 Reputation

25 Badges

11 years, 360 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

It seems like the seventh and eighth rows of your Matrix are being converted to lists by CodeGeneration:-Matlab. I have no idea why this is (there are no lists in your input Matrix), but here is a workaround: Change your last command to

Matlab(
     subsop([-1,1]= J, eval([codegen:-optimize](tmp, tryhard), pow= `^`)),
     output = string, defaulttype = numeric
);

I don't have Matlab to test this, so please let me know how this works for you.

y(seq(x[k], k= 1..n))

If x is actually a list, you can do y(x[]).

If you make assumptions such as assume(m>0, m<1), assume(m>2, m<3), etc., that place m between two consecutive integers, then MultiSeries:-multiseries will work.

You need to use one section per slide. So, if you have a section that is too long to fit on one slide, then you need to divide it into multiple sections.

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

First 347 348 349 350 351 352 353 Last Page 349 of 390