Kitonum

21830 Reputation

26 Badges

17 years, 219 days

MaplePrimes Activity


These are answers submitted by Kitonum

You have some pretty complicated code. Here is a simple recursive procedure that returns all the fractions obtained in the nth step:

T:=proc(n)
local P;
option remember;
P:=proc(p)
local p1, p2;
p1:=numer(p); p2:=denom(p);
p1/(p1+p2), (p1+p2)/p2;
end proc;
if n=1 then return [1] else
[seq(P(T(n-1)[i]), i=1..nops(T(n-1)))] fi;
end proc:

Examples of use:
T(4);
sort(T(4));
sort([seq(T(i)[],i=1..4)]);
  # Sorted list of all the fractions obtained in the first 4 steps 
                             


Addition. Similarly, we can write a procedure using the formula from wiki  q[i+1]=1/(2*floor(q[i])-q[i]+1) :

T1:=proc(n)
option remember;
if n=1 then return 1 else
1/(2*floor(T1(n-1))-T1(n-1)+1) fi;
end proc:

sort([seq(T1(n), n=1..100)]);

 

I rewrote the original code, simplifying it a bit. We can reduce the number of unknowns by 2 times if we write  C1 := <cos(s), sin(s))> , C2 := <cos(t), sin(t)> . Then the conditions  eq1  and  eq2  are satisfied automatically. We get that the vectors  C1  and  C2  either coincide or differ from each other by turning by an angle multiple of  90  degrees.
 

``

restart; with(LinearAlgebra)

C1 := `<,>`(cos(s), sin(s)); C2 := `<,>`(cos(t), sin(t)); A := C1.C1^%T; B := C2.C2^%T; D1 := A.B; D2 := B.A

Vector(2, {(1) = cos(s), (2) = sin(s)})

 

Vector(2, {(1) = cos(t), (2) = sin(t)})

 

Matrix(2, 2, {(1, 1) = cos(s)^2, (1, 2) = cos(s)*sin(s), (2, 1) = cos(s)*sin(s), (2, 2) = sin(s)^2})

 

Matrix(2, 2, {(1, 1) = cos(t)^2, (1, 2) = cos(t)*sin(t), (2, 1) = cos(t)*sin(t), (2, 2) = sin(t)^2})

 

Matrix(2, 2, {(1, 1) = cos(s)^2*cos(t)^2+cos(s)*sin(s)*cos(t)*sin(t), (1, 2) = cos(s)^2*cos(t)*sin(t)+cos(s)*sin(s)*sin(t)^2, (2, 1) = cos(s)*sin(s)*cos(t)^2+sin(s)^2*cos(t)*sin(t), (2, 2) = cos(s)*sin(s)*cos(t)*sin(t)+sin(s)^2*sin(t)^2})

 

Matrix(%id = 18446746338043240566)

(1)

eqns:=Equate(D1,D2);
solve(eqns, allsolutions);
about(_Z1);

[cos(s)^2*cos(t)^2+cos(s)*sin(s)*cos(t)*sin(t) = cos(s)^2*cos(t)^2+cos(s)*sin(s)*cos(t)*sin(t), cos(s)^2*cos(t)*sin(t)+cos(s)*sin(s)*sin(t)^2 = cos(s)*sin(s)*cos(t)^2+sin(s)^2*cos(t)*sin(t), cos(s)*sin(s)*cos(t)^2+sin(s)^2*cos(t)*sin(t) = cos(s)^2*cos(t)*sin(t)+cos(s)*sin(s)*sin(t)^2, cos(s)*sin(s)*cos(t)*sin(t)+sin(s)^2*sin(t)^2 = cos(s)*sin(s)*cos(t)*sin(t)+sin(s)^2*sin(t)^2]

 

{s = s, t = Pi*_Z1+s}, {s = s, t = -(1/2)*Pi+s+Pi*_Z1}

 

Originally _Z1, renamed _Z1~:
  is assumed to be: integer

 

``


Edit.

Download Sol_edit.mw

I converted your 2D math input code to 1D code and replaced  `a__10 `  with a__10  and so on. Now everything works properly:
 

a__10 := (1-u__2)*(u__2-m)-q*(u__2+c)+u__2*(1+m-2*u__2);

(1-u__2)*(u__2-m)-q*(u__2+c)+u__2*(1+m-2*u__2)

(1)

a__01 := -u__2*q;

-u__2*q

(2)

a__20 := 1/2*(-6*u__2+2*m+2);

-3*u__2+m+1

(3)

a__11 := -q;

-q

(4)

a__02 := 0;

0

(5)

b__10 := s;

s

(6)

b__01 := -s;

-s

(7)

b__20 := -s/(u__2+c);

-s/(u__2+c)

(8)

b__11 := 2*s/(u__2+c);

2*s/(u__2+c)

(9)

b__02 := -s/(u__2+c);

-s/(u__2+c)

(10)

b__03 := 0;

0

(11)

a__30 := -1;

-1

(12)

a__21 := 0;

0

(13)

b__12 := s/(u__2+c)^2;

s/(u__2+c)^2

(14)

a__12 := 0;

0

(15)

b__21 := (-2*(u__2+c)^2-s)/(2*(u__2+c)^3);

(1/2)*(-2*(u__2+c)^2-s)/(u__2+c)^3

(16)

l__1 := ((-3*Pi)*(1/(2*a__01*(q*s*u__2-s^2))))*(a__10*b__10*(a__02*b__11+a__11^2+a__11*b__02)+a__10*a__01*(a__11*b__02+a__20*b__11+b__11^2)+b__10^2*(a__02*a__11+2*a__02*b__02)-2*a__10*b__10*(-a__02*a__20+b__02^2)-2*a__10*a__01*(a__20^2-b__02*b__20)-a__01^2*(2*a__20*b__20+b__11*b__20)+(a__01*b__10-2*a__10^2)*(-a__11*a__20+b__02*b__11)-(a__01*b__10+a__10^2)*(3*(-a__01*a__30+b__03*b__10)+2*a__10*(a__21+b__12)+b__10*a__12-a__01*b__21));

(3/2)*Pi*(((1-u__2)*(u__2-m)-q*(u__2+c)+u__2*(1+m-2*u__2))*s*(q^2+q*s/(u__2+c))-((1-u__2)*(u__2-m)-q*(u__2+c)+u__2*(1+m-2*u__2))*u__2*q*(q*s/(u__2+c)+2*(-3*u__2+m+1)*s/(u__2+c)+4*s^2/(u__2+c)^2)-2*((1-u__2)*(u__2-m)-q*(u__2+c)+u__2*(1+m-2*u__2))*s^3/(u__2+c)^2+2*((1-u__2)*(u__2-m)-q*(u__2+c)+u__2*(1+m-2*u__2))*u__2*q*((-3*u__2+m+1)^2-s^2/(u__2+c)^2)-u__2^2*q^2*(-2*(-3*u__2+m+1)*s/(u__2+c)-2*s^2/(u__2+c)^2)+(-q*s*u__2-2*((1-u__2)*(u__2-m)-q*(u__2+c)+u__2*(1+m-2*u__2))^2)*(q*(-3*u__2+m+1)-2*s^2/(u__2+c)^2)-(-q*s*u__2+((1-u__2)*(u__2-m)-q*(u__2+c)+u__2*(1+m-2*u__2))^2)*(-3*u__2*q+2*((1-u__2)*(u__2-m)-q*(u__2+c)+u__2*(1+m-2*u__2))*s/(u__2+c)^2+(1/2)*u__2*q*(-2*(u__2+c)^2-s)/(u__2+c)^3))/(u__2*q*(q*s*u__2-s^2))

(17)

 



I advise you to immediately write code in 1D math input. It will be faster and much easier to track possible errors, as all characters are clearly visible.

 

Download coeff_new.mw

 

The syntax for this is  log[2](6) . Maple automatically translates this into the natural logarithm (with base e). For numerical calculation use the  evalf  command:

log[2](6);
evalf(%);

 

Here is another method that immediately provides expansions for  cos(6*t)  and  sin(6*t) . If you need to check it manually, then equate the results from the application of de Moivre's formula and Newton binomial:

evalc((cos(t)+I*sin(t))^6);
Re(%) assuming real;

 

Look at this question and the answer to it.

This is a well-known bug in some versions of Maple <= 2018. As a workaround, besides the depthlimit option, you need to increase  Digits :

restart;
kernelopts(version);
Digits:=20:
Optimization:-LPSolve(4*x1+5*x2+5*x3+2*x4,
                      {33*x1 + 49*x2 + 51*x3 + 22*x4 <= 120},
                      maximize, assume ={nonnegint}, depthlimit=10);

        Maple 2018.2, X86 64 WINDOWS, Oct 23 2018, Build ID 1356656             
                            [13, [x1 = 2, x2 = 1, x3 = 0, x4 = 0]]

 

It works:

Mat:=module()
    description "My Package";
    option package;
    uses Statistics;
    export LinModel; 
    LinModel :=proc(xliste::list, yliste::list,x::algebraic, $)
        return Fit(a*x+b,xliste,yliste,x)
        end proc; # LinModel 

    end module; #Mat

xliste:=[1,2,3]: yliste:=[2,4,5]:
Mat:-LinModel(xliste,yliste, x);

 

Only numerically:

f:=x->x^5 + 2*x^3:
g:=y->fsolve(y = x^5 + 2*x^3, x);  # This is the inverse function for f


Examples of use:

g(1);
plot([f, g], -3..3, -3..3, color=[red,blue], scaling=constrained);
evalf(Int(g, 0..2));
D(g)(2);

                                    

                                                                           

 

`/`(a, b); 
                       
a/b

A simple procedure  LongSum  solves your problem. Formal parameters:  f  -  procedure for the common term, n0 - number of terms before the ellipsis,  n - position of the last term.

LongSum:=proc(f,n0,n)
`%+`(seq(f(k),k=1..n0))+`...`+f(n);
end proc:

Examples of use:
LongSum(n->x[n], 2, n);
LongSum(n->n/(n+1), 3, k);
LongSum(n->n/(n+1), 3, 100);


                           


If there is no any formula for the common term, then you can simply write (without a procedure) as in the example below:

a+b+c+`...`+f;

It is easy to modify this procedure to display not one, but several last terms or some intermediate terms, etc.


 

restart:
 with(Student:-MultivariateCalculus):
 A := [0, 0];
B := [5, 0];
C := [3, 4];
DD := [a, 2];
solve([Distance(B, A)*Distance(C, DD) = Distance(B, C)*Distance(A, DD)], [a]);
DD:=eval(DD,%[1]);
X:=[x,y];
DDA:=<op(A-DD)>; DDX:=<op(X-DD)>; BX:=<op(X-B)>; BC:=<op(C-B)>;
AB:=<op(B-A)>; AX:=<op(X-A)>; CDD:=<op(DD-C)>; CX:=<op(X-C)>;
solve({DotProduct(DDA,DDX)/Norm(DDA)/Norm(DDX)=DotProduct(BX,BC)/Norm(BX)/Norm(BC), DotProduct(AB,AX)/Norm(AB)/Norm(AX)=DotProduct(CDD,CX)/Norm(CDD)/Norm(CX)});
X:=eval(X,%[1]);
XA:=<op(A-X)>: XB:=<op(B-X)>: XC:=<op(C-X)>: XDD:=<op(DD-X)>:
is(DotProduct(XA,XB)/Norm(XA)/Norm(XB)=-DotProduct(XC,XDD)/Norm(XC)/Norm(XDD));

A := [0, 0]

 

B := [5, 0]

 

C := [3, 4]

 

DD := [a, 2]

 

[[a = 15-4*sqrt(11)], [a = 15+4*sqrt(11)]]

 

DD := [15-4*sqrt(11), 2]

 

X := [x, y]

 

Vector(2, {(1) = -15+4*sqrt(11), (2) = -2})

 

Vector(2, {(1) = -15+4*sqrt(11)+x, (2) = -2+y})

 

Vector(2, {(1) = -5+x, (2) = y})

 

Vector(2, {(1) = -2, (2) = 4})

 

Vector(2, {(1) = 5, (2) = 0})

 

Vector(2, {(1) = x, (2) = y})

 

Vector(2, {(1) = 12-4*sqrt(11), (2) = -2})

 

Vector[column](%id = 18446745371972441022)

 

{x = -(44/181)*11^(1/2)+511/181, y = 478/181-(112/181)*11^(1/2)}, {x = -(8*11^(1/2)*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 1)^2-31*11^(1/2)*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 1)+24*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 1)^2+75*11^(1/2)-131*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 1)+75)/(-23*11^(1/2)+32*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 1)-103), y = RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 1)}, {x = -(8*11^(1/2)*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 2)^2-31*11^(1/2)*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 2)+24*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 2)^2+75*11^(1/2)-131*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 2)+75)/(-23*11^(1/2)+32*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 2)-103), y = RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 2)}, {x = -(8*11^(1/2)*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 3)^2-31*11^(1/2)*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 3)+24*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 3)^2+75*11^(1/2)-131*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 3)+75)/(-23*11^(1/2)+32*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 3)-103), y = RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 3)}, {x = -(8*11^(1/2)*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 4)^2-31*11^(1/2)*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 4)+24*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 4)^2+75*11^(1/2)-131*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 4)+75)/(-23*11^(1/2)+32*RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 4)-103), y = RootOf(192*_Z^4+(240*11^(1/2)-2208)*_Z^3+(-3440*11^(1/2)+13880)*_Z^2+(10840*11^(1/2)-36535)*_Z-7200*11^(1/2)+28050, index = 4)}, {x = -(8*11^(1/2)*RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 3)^2+230*11^(1/2)*RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 3)-36*RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 3)^2-660*11^(1/2)-850*RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 3)+2415)/(-100*11^(1/2)+37*RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 3)+265), y = RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 3)}, {x = -(8*11^(1/2)*RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 4)^2+230*11^(1/2)*RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 4)-36*RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 4)^2-660*11^(1/2)-850*RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 4)+2415)/(-100*11^(1/2)+37*RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 4)+265), y = RootOf(5*_Z^4+(-30*11^(1/2)+60)*_Z^3+(206*11^(1/2)-561)*_Z^2+(6420*11^(1/2)-21495)*_Z-24000*11^(1/2)+79750, index = 4)}, {x = RootOf(1225*_Z^4+(4760*11^(1/2)-26915)*_Z^3+(-28062*11^(1/2)+134853)*_Z^2+(47038*11^(1/2)-244772)*_Z-4920*11^(1/2)+108855, index = 3), y = (1/7)*(4*11^(1/2)*RootOf(1225*_Z^4+(4760*11^(1/2)-26915)*_Z^3+(-28062*11^(1/2)+134853)*_Z^2+(47038*11^(1/2)-244772)*_Z-4920*11^(1/2)+108855, index = 3)-60*11^(1/2)+41*RootOf(1225*_Z^4+(4760*11^(1/2)-26915)*_Z^3+(-28062*11^(1/2)+134853)*_Z^2+(47038*11^(1/2)-244772)*_Z-4920*11^(1/2)+108855, index = 3)+15)/(-2*11^(1/2)+5*RootOf(1225*_Z^4+(4760*11^(1/2)-26915)*_Z^3+(-28062*11^(1/2)+134853)*_Z^2+(47038*11^(1/2)-244772)*_Z-4920*11^(1/2)+108855, index = 3)-10)}, {x = RootOf(1225*_Z^4+(4760*11^(1/2)-26915)*_Z^3+(-28062*11^(1/2)+134853)*_Z^2+(47038*11^(1/2)-244772)*_Z-4920*11^(1/2)+108855, index = 4), y = (1/7)*(4*11^(1/2)*RootOf(1225*_Z^4+(4760*11^(1/2)-26915)*_Z^3+(-28062*11^(1/2)+134853)*_Z^2+(47038*11^(1/2)-244772)*_Z-4920*11^(1/2)+108855, index = 4)-60*11^(1/2)+41*RootOf(1225*_Z^4+(4760*11^(1/2)-26915)*_Z^3+(-28062*11^(1/2)+134853)*_Z^2+(47038*11^(1/2)-244772)*_Z-4920*11^(1/2)+108855, index = 4)+15)/(-2*11^(1/2)+5*RootOf(1225*_Z^4+(4760*11^(1/2)-26915)*_Z^3+(-28062*11^(1/2)+134853)*_Z^2+(47038*11^(1/2)-244772)*_Z-4920*11^(1/2)+108855, index = 4)-10)}

 

[-(44/181)*11^(1/2)+511/181, 478/181-(112/181)*11^(1/2)]

 

true

(1)

 


 

Download Check.mw

f2:=cos(y-Pi/3):
is(expand(f1/f2)=1);

                         true


Formally, the expressions  f1  and  f2  do not coincide for all values x and y. For example we get an undefined expression  0/0  for x=0, y=0 :
 

eval([numer(f1),denom(f1)],[x=0,y=0]);

                         [0, 0]
 

m := n->piecewise(type(n,even),0, 1):
f := proc(a,b)
if type(a*b,integer) then return m(a*b) else FAIL fi;
end:

 
f(a,b);
f(2,3);
f(1,3);
f(a,3);

sin(30*Pi/180);
30^`&deg;`;

                                                 

 

 

                                      

First 79 80 81 82 83 84 85 Last Page 81 of 292