Kitonum

21525 Reputation

26 Badges

17 years, 75 days

MaplePrimes Activity


These are answers submitted by Kitonum


 

restart;
ex7 := x->abs(x^2-3*x)+4*x-6;
solve(ex7(x)); # Easy way

proc (x) options operator, arrow; abs(x^2-3*x)+4*x-6 end proc

 

1, -3

(1)

solve({x^2-3*x<0, -(x^2-3*x)+4*x-6=0}) union solve({x^2-3*x>=0, x^2-3*x+4*x-6=0});  # A longer way without the abs command

{x = -3, x = 1}

(2)

 


 

Download abs.mw

In those cases when  isolve  does not cope with the problem, brute force method (i.e. the method of enumerating all possible options) can often be successfully used. In your 4-squares example, assuming the variables are positive, it is obvious that each of the variables can vary in the range of 1 .. 12 . Nested for-loops are often used for this method, but I like nested sequences more. We get  76  solutions, but many of them are obtained simply by rearranging one from the other. But a slight modification of this method allows you to immediately get  5  unique solutions.


 

restart;

seq(seq(seq(seq(`if`(169 = w^2 + x^2 + y^2 + z^2,[w,x,y,z],NULL),w=1..12),x=1..12),y=1..12),z=1..12);
nops([%]);

[10, 8, 2, 1], [8, 10, 2, 1], [10, 2, 8, 1], [2, 10, 8, 1], [8, 2, 10, 1], [2, 8, 10, 1], [10, 8, 1, 2], [8, 10, 1, 2], [10, 7, 4, 2], [7, 10, 4, 2], [10, 4, 7, 2], [4, 10, 7, 2], [10, 1, 8, 2], [1, 10, 8, 2], [8, 1, 10, 2], [7, 4, 10, 2], [4, 7, 10, 2], [1, 8, 10, 2], [10, 7, 2, 4], [7, 10, 2, 4], [11, 4, 4, 4], [4, 11, 4, 4], [8, 8, 5, 4], [9, 6, 6, 4], [6, 9, 6, 4], [10, 2, 7, 4], [2, 10, 7, 4], [8, 5, 8, 4], [5, 8, 8, 4], [6, 6, 9, 4], [7, 2, 10, 4], [2, 7, 10, 4], [4, 4, 11, 4], [8, 8, 4, 5], [8, 4, 8, 5], [4, 8, 8, 5], [9, 6, 4, 6], [6, 9, 4, 6], [9, 4, 6, 6], [4, 9, 6, 6], [6, 4, 9, 6], [4, 6, 9, 6], [10, 4, 2, 7], [4, 10, 2, 7], [10, 2, 4, 7], [2, 10, 4, 7], [4, 2, 10, 7], [2, 4, 10, 7], [10, 2, 1, 8], [2, 10, 1, 8], [10, 1, 2, 8], [1, 10, 2, 8], [8, 5, 4, 8], [5, 8, 4, 8], [8, 4, 5, 8], [4, 8, 5, 8], [5, 4, 8, 8], [4, 5, 8, 8], [2, 1, 10, 8], [1, 2, 10, 8], [6, 6, 4, 9], [6, 4, 6, 9], [4, 6, 6, 9], [8, 2, 1, 10], [2, 8, 1, 10], [8, 1, 2, 10], [7, 4, 2, 10], [4, 7, 2, 10], [1, 8, 2, 10], [7, 2, 4, 10], [2, 7, 4, 10], [4, 2, 7, 10], [2, 4, 7, 10], [2, 1, 8, 10], [1, 2, 8, 10], [4, 4, 4, 11]

 

76

(1)

seq(seq(seq(seq(`if`(169 = w^2 + x^2 + y^2 + z^2,[w,x,y,z],NULL),w=1..x),x=1..y),y=1..z),z=1..12);

[4, 5, 8, 8], [4, 6, 6, 9], [2, 4, 7, 10], [1, 2, 8, 10], [4, 4, 4, 11]

(2)

 


 

Download 4_squares.mw
 

 

restart;
A := [[1, 0, 9], [5, 0, 6], [4, 0, 0]]; 
remove~(has, A, 0);

                                  [[1, 9], [5, 6], [4]]


Here is a procedure for this:

restart;
P:=proc(k)
local n, k1, k2;
n:=2; k1:=0; k2:=0;
while n<10^k do
if isprime(10*n+1) then k2:=k2+1 else k1:=k1+1 fi;
n:=nextprime(n);
od;
[k1,k2];
end proc:

Examples of use

seq(P(k), k=1..6);

[2, 2], [18, 7], [131, 37], [1021, 208], [8240, 1352], [69231, 9267]

(1)

plot([[seq([k,P(k)[1]],k=1..5)],[seq([k,P(k)[2]],k=1..5)]], color=[red,blue]);

 

 

 

Addition. It is interesting that if we set the logarithmic scale along the vertical axis, then we get 2 lines close to straight lines:

plots:-logplot([[seq([k,P(k)[1]],k=1..5)],[seq([k,P(k)[2]],k=1..5)]], color=[red,blue]);

Edit.

Download count1.mw

The appearance of extraneous roots when squaring both sides of the equation is in no way related to the presence of square roots in the original equation. Consider the simplest equation  x = 2  with an obvious root  2 . But if you square it, you get an equation  x^2 = 4  that has 2 roots  2  and  -2 .  In the general case, let us have the equation  f(x) = g(x)  and square it. Obviously, the resulting equation  f(x)^2  = g(x)^2  is equivalent to the equation  (f(x) - g(x))*(f(x) + g(x)) = 0 .  The roots of the last equation are the union of the sets of the roots of the original equation  f(x) = g(x) and the roots of the equation  f(x) = - g(x) , which may have roots that are not the roots of the original equation.

The function  f , by means of which the equation of the blue line is specifed, is given incorrectly. Below is the corrected version:

restart;
with(plots):
unprotect(O);
H := [84/37, 14/37]:
f := x-> -6*x+14:
a := 3: A := [a, f(a)]:
O:=[0,0]: zo := [8/3+I*f(8/3)];
ze := [2+I^(eval(diff(f(x), x), x = 2))];
Zo := [8/3, f(8/3)]; Ze := [2, f(2)];
ex := -6*x+14; V := `<,>`(ze-zo);
V := plottools:-arrow(Zo, Ze, .2, .4, .2, color = "Red"):
DR := plot(ex, x = -1 .. 3, color = blue):
Points := pointplot([A[],Zo[],Ze[],H[]], symbol = solidcircle, color = red, symbolsize = 10):
T := textplot([[A[], "A"],[H[],"H"],[O[],"O"]], font = [times, 18], align = {below, right}):
display([DR,V,Points, T], scaling = constrained, size=[800,800]);

zo := [8/3-2*I]

 

ze := [1]

 

Zo := [8/3, -2]

 

Ze := [2, 2]

 

ex := -6*x+14

 

Vector[column](%id = 18446746163433603070)

 

 

 


Explanation. The direction vector for the blue line is  <-2/3, 4> (in fact, you specified it with a complex number  v = -2/3+4*I ). Therefore, the slope of this line is  k = 4 / (- 2/3) = - 6  and the equation of this line is  y=-4 - 6*(x-3)  or  y=-6*x + 14

Download 1.mw

I made 3 corrections in your procedure. Now it is working properly. It is only important to note that this construction  List1 := [op(List1), p]  and so on  is extremely inefficient. Below is the same procedure  (named  FF ), but much faster (of course for large ):

restart;
F := proc(N)
local p, List1, List3, List5, List7;
List1 := [];
List3 := [];
List5 := [];
List7 := [];
for p from 1 to N do
if isprime(p) and p mod 8 = 1 then List1 := [op(List1), p]; end if;
if isprime(p) and p mod 8 = 3 then List3 := [op(List3), p]; end if;
if isprime(p) and p mod 8 = 5 then List5 := [op(List5), p]; end if;
if isprime(p) and p mod 8 = 7 then List7 := [op(List7), p]; end if;
[nops(List1), nops(List3), nops(List5), nops(List7)];
end do;
end proc:

  F(100);
                          [5, 7, 6, 6]
 

restart;
FF := proc(N)
local p, k1, k3, k5, k7;
k1:=0; k3:=0; k5:=0; k7:=0;
for p from 1 to N do
if isprime(p) then if p mod 8 = 1 then k1:=k1+1  elif
p mod 8 = 3 then k3:=k3+1  elif
p mod 8 = 5 then k5:=k5+1  elif
p mod 8 = 7 then k7:=k7+1 fi; fi;
[k1,k3,k5,k7];
end do;
end proc:

FF(100);
                                [5, 7, 6, 6]


Edit.
 

In the  seq  command, index is  local  and therefore independent of the previously assigned value:

i:=1: ii:=2:
seq(i, i=1..5);
seq(ii, ii=1..5)

                                     1, 2, 3, 4, 5
                                     1, 2, 3, 4, 5


A workaround:

a:=50:
seq(a,ii=1..5);

 

Example:

i:=3: n:=8:
mul(`if`(k<>i,lambda[i]-lambda[k],1), k=1 .. n);

           

 


 

with(plots):
fprime_expr:=x^sin(x)*(cos(x)*ln(x)+sin(x)/x);
RootFinding:-Analytic(diff(fprime_expr,x,x)=0, re=0..10, im=-1..1);
L:=sort(select(type,[%],realcons));
A:=plot(fprime_expr, x=0..10, color=blue):
B:=pointplot([seq([l,eval(fprime_expr,x=l)],l=L)], symbol=solidcircle, symbolsize=12, color=red):
display(A,B);

x^sin(x)*(cos(x)*ln(x)+sin(x)/x)

 

4.78206109907178, 3.48122397295652, 2.16436178885414, .748344075670115-.240667154995571*I, .748344075670115+.240667154995571*I, 9.04887132811185, 6.77657190535075, 7.93089684792655

 

[2.16436178885414, 3.48122397295652, 4.78206109907178, 6.77657190535075, 7.93089684792655, 9.04887132811185]

 

 

 


 

Download inflection.mw


 

restart;
f:=t->[3*t,4*t^2+1]:  # Law of movement
P:=eliminate([x=f(t)[1],y=f(t)[2]],t);  # Elimination of the parameter t
P[2][]=0;  # Implicit equation of trajectory
solve(P[2],y)[]; # Explicit equation of trajectory
M:=f(1/2); # Position of the point at t=1/2

[{t = (1/3)*x}, {4*x^2-9*y+9}]

 

4*x^2-9*y+9 = 0

 

y = (4/9)*x^2+1

 

[3/2, 2]

(1)

V:=eval(diff(f(t),t),t=1/2); # Velocity of the point at t=1/2 as a vector
sqrt(inner(V,V));  # Magnitude of velocity

[3, 4]

 

5

(2)

and so on


 

Download CM.mw

It's easier and faster to specify your array  A  through a procedure  (i,j) -> a[i,j] :

A:=Array(1..3,1..4,(i,j)->i^j);

 

Use  ListTools  instead of  ArrayTools :

restart;
A:=[[0, 4], [1, 3], [2, 2], [3, 1], [4, 0], [0, 3], [1, 2], [2, 1], [3, 0], [0, 2], [1, 1], [2, 0], [0, 1], [1, 0], [0, 0]];
ListTools:-Reverse(A); 

   

A := [[0, 4], [1, 3], [2, 2], [3, 1], [4, 0], [0, 3], [1, 2], [2, 1], [3, 0], [0, 2], [1, 1], [2, 0], [0, 1], [1, 0], [0, 0]]

  [[0, 0], [1, 0], [0, 1], [2, 0], [1, 1], [0, 2], [3, 0], [2, 1], [1, 2], [0, 3], [4, 0], [3, 1], [2, 2], [1, 3], [0, 4]]
 


 

restart;
alpha:=Pi/6: V[A]:=1: l:=3: f:=0.2: d:=2.5:
# The movement of the body along the segment AB
de:=m*diff(x1(t),t,t)=G*sin(alpha)-F[fr]:
G:=m*g: F[fr]:=m*g*f*cos(alpha): g:=9.81:
ics:=x1(0)=0, D(x1)(0)=V[A]:
de:=evalf(de/m);
B:=rhs(de);
sol:=dsolve({de,ics}, x1(t)); # The solution of de
x1:=unapply(evalf(rhs(sol)),t);
fsolve(x1(t)=l);
tau:=%[2];
V['B']:=D(x1)(tau);
tau:=evalf[3](tau);
 

diff(diff(x1(t), t), t) = 3.205858157

 

3.205858157

 

x1(t) = (3205858157/2000000000)*t^2+t

 

proc (t) options operator, arrow; 1.602929078*t^2+t end proc

 

-1.715094465, 1.091236545

 

1.091236545

 

4.498349578

 

1.09

(1)

# The movement of the body along the curve BC
sys:=m*diff(x(t),t,t)=0, m*diff(y(t),t,t)=m*g;
ics_sys:=x(0)=0, y(0)=0, D(x)(0)=V['B']*cos(alpha), D(y)(0)=V['B']*sin(alpha):
Sol:=evalf(dsolve({sys, ics_sys},{x(t),y(t)})); # The solution of sys
x:=unapply(eval(x(t),Sol),t); y:=unapply(eval(y(t),Sol),t);
T:=evalf(solve(x(t)=d));
h:=evalf(y(T));
T:=evalf[2](T);
h:=evalf[3](h);   
 

m*(diff(diff(x(t), t), t)) = 0, m*(diff(diff(y(t), t), t)) = 9.81*m

 

{x(t) = 3.895685011*t, y(t) = 4.905000000*t^2+2.249174789*t}

 

proc (t) options operator, arrow; 3.895685011*t end proc

 

proc (t) options operator, arrow; 4.905000000*t^2+2.249174789*t end proc

 

.6417356621

 

3.463375629

 

.64

 

3.46

(2)


Visualization

with(plots): with(plottools):
bg:=display(curve([[-2.6,-1],[-2.6,-4],[0,-4],[0,-0.1],[3,3*tan(Pi/6)-0.1]], color=black, thickness=2)):
P:=s->piecewise(s>=0 and s<=tau,[(3-x1(s))*cos(Pi/6),(3-x1(s))*sin(Pi/6)],[-x(s-tau),-y(s-tau)]):
Trajectory:=t->display(plot([P(s)[1],P(s)[2],s=0..t],linestyle=3,color=red), pointplot(`if`(t>=0 and t<=tau,[(3-x1(t))*cos(Pi/6),(3-x1(t))*sin(Pi/6)], [-x(t-tau),-y(t-tau)]),symbol=solidcircle, symbolsize=20, color=red)):
animate(Trajectory,[t], t=0..tau+T, background=bg, scaling=constrained, size=[500,500], axes=none);

 

 


Edit.

Download sol_Maple_new1.mw

All calculations are made with 10 significant digits (by default). In the final answers, the number of digits is left as in your document:


 

restart;
alpha:=Pi/6: V[A]:=1: l:=3: f:=0.2: d:=2.5:
# The movement of the body along the segment AB
de:=m*diff(x1(t),t,t)=G*sin(alpha)-F[fr]:
G:=m*g: F[fr]:=m*g*f*cos(alpha): g:=9.81:
ics:=x1(0)=0, D(x1)(0)=V[A]:
de:=evalf(de/m);
B:=rhs(de);
sol:=dsolve({de,ics}, x1(t)); # The solution of de
fsolve(rhs(sol)=l);
tau:=evalf[3](%[2]);
V['B']:=B*tau+V[A];
 

diff(diff(x1(t), t), t) = 3.205858157

 

3.205858157

 

x1(t) = (3205858157/2000000000)*t^2+t

 

-1.715094465, 1.091236545

 

1.09

 

4.494385391

(1)

# The movement of the body along the curve BC
sys:=m*diff(x(t),t,t)=0, m*diff(y(t),t,t)=m*g;
ics_sys:=x(0)=0, y(0)=0, D(x)(0)=V['B']*cos(alpha), D(y)(0)=V['B']*sin(alpha):
Sol:=evalf(dsolve({sys, ics_sys})); # The solution of sys
T:=evalf(solve(eval(x(t),Sol)=d));
h:=evalf(eval(eval(y(t),Sol),t=T));
T:=evalf[2](T);
h:=evalf[3](h);   
 

m*(diff(diff(x(t), t), t)) = 0, m*(diff(diff(y(t), t), t)) = 9.81*m

 

{x(t) = 3.892251925*t, y(t) = 4.905000000*t^2+2.247192696*t}

 

.6423016927

 

3.466940605

 

.64

 

3.47

(2)

 


 

Download sol_Maple.mw

First 57 58 59 60 61 62 63 Last Page 59 of 290