Kitonum

21830 Reputation

26 Badges

17 years, 219 days

MaplePrimes Activity


These are answers submitted by Kitonum

If one solution is enough, then you can do so

restart;
FourSquares:=proc(n)
local a, b, c, d;
for a from 1 to floor(sqrt(n/4)) do
for b from a to floor(sqrt((n-a^2)/3)) do
for c from b to floor(sqrt((n-a^2-b^2)/2)) do
for d from c to floor(sqrt(n-a^2-b^2-c^2)) do
if n=a^2+b^2+c^2+d^2 then return [a,b,c,d] fi;
od: od: od: od:
end proc:


Example of use:

FourSquares(100000);
                                             
 [4, 8, 8, 316]

It is not recommended to use some variable and indexed variable with the same name in the same code. Therefore, I replaced, for example, t[n]  by  t||n  and so on. Some other corrections and additions were also made. The resulting approximate solution is quite accurate.

restart;
f:=t->y(t)-t^2+1;
eqn:=diff(y(t),t)=f(t):
ex:=dsolve({eqn,y(0)=0.5},y(t));
t||0:=0: w||0:=0.5: h:=0.2: ex||0:=0.5: e||0:=0:
Dy||0:=eval(f(t),[t=t||0,y(t)=w||0]);

for n from 1 to 10 do
t||n:=n*h; ex||n:=eval(rhs(ex),t=t||n);
w||n:=w||(n-1)+h*Dy||(n-1)+h^2/2!*(Dy||(n-1)-2*t||(n-1));
e||n:=abs(ex||n-w||n);
Dy||n:=eval(f(t),[t=t||n,y(t)=w||n]);
od:

printf(" i | t[i] |(Taylor)w[i] |(exact)y[i] |Error | \n ");
for i from 0 to 10 do
printf("%2.2f| %5.2f  | %5.6f| %5.6f  |  %5.6f | \n", i, t||i, w||i ,ex||i,e||i) ;
od;

A:=plot(rhs(ex), t=0..2, color=red):
B:=plot([seq([h*k,w||k], k=0..10)], style=point,color=blue):
plots:-display(A,B, legend=["Exact solution","Approximate solution"], view=0..6);

The final results as a table and a plot:

 

Unfortunately, it is not possible to obtain an explicit parameterization of the intersection curve, since finding x1,y1,z1 coordinates as functions of the parameter  theta  leads to the solution of an equation of a high degree. But we can get a numerical solution in the form of a procedure. This procedure  Curve  returns the coordinates of the point on the intersection curve for the specified values  theta, x, y, z :


 

restart;

R1 := 3: R2 := 1: DR := 4: g := R2 + DR:

f1 := h -> sqrt(R1^2 - h^2);
f2 := h -> sqrt(g^2 - h^2);
f3 := h -> (1 - h/g)*f1(h*R1/g) + h*f2(h)/g;
f4 := h -> sqrt(1/2*g - 1/2*h);
f5 := h -> (1 - h/g)*f3(h) + h*f4(h)/g;
gg := h -> piecewise(h < 0, f1(h), 0 <= h, f5(h)); # Radius depending on the z-position h
cir := (h, phi, R) -> <sin(phi)*R, cos(phi)*R, h>; # a circle at the hight h with radius R
#The plane is placed inside the drop.
n := (x, y, z) -> <x, y, z>/sqrt(x^2 + y^2 + z^2);

# the following lines show, how it looks like:
with(plots):
with(plottools):
dro1 := plot3d(cir(h, phi, gg(h)), h = -R1 .. g, phi = 0 .. 2*Pi, scaling = constrained, orientation = [-60, 72, 0]);
plotDropWithPlane := (x, y, z) -> display(dro1, arrow(Vector([0, 0, 0]), 2*R1*n(x, y, z), 0.2, 0.4, 0.1, cylindrical_arrow, fringe = blue, color = "Green"), implicitplot3d(x*x1 + y*y1 + z*z1 = 0, x1 = -R1 .. R1, y1 = -R1 .. R1, z1 = -R1 .. g, color = blue));
Plot1:=plotDropWithPlane(3, 1, 2);

f1 := proc (h) options operator, arrow; sqrt(R1^2-h^2) end proc

 

f2 := proc (h) options operator, arrow; sqrt(g^2-h^2) end proc

 

f3 := proc (h) options operator, arrow; (1-h/g)*f1(h*R1/g)+h*f2(h)/g end proc

 

f4 := proc (h) options operator, arrow; sqrt((1/2)*g-(1/2)*h) end proc

 

f5 := proc (h) options operator, arrow; (1-h/g)*f3(h)+h*f4(h)/g end proc

 

proc (h) options operator, arrow; piecewise(h < 0, f1(h), 0 <= h, f5(h)) end proc

 

proc (h, phi, R) options operator, arrow; `<,>`(sin(phi)*R, cos(phi)*R, h) end proc

 

proc (x, y, z) options operator, arrow; `<,>`(x, y, z)/sqrt(x^2+y^2+z^2) end proc

 

 

proc (x, y, z) options operator, arrow; plots:-display(dro1, plottools:-arrow(Vector([0, 0, 0]), 2*R1*n(x, y, z), .2, .4, .1, cylindrical_arrow, fringe = blue, color = "Green"), plots:-implicitplot3d(x*x1+y*y1+z*z1 = 0, x1 = -R1 .. R1, y1 = -R1 .. R1, z1 = -R1 .. g, color = blue)) end proc

 

 

gg1 := h -> f1(h): # for h<0
gg2 := h -> f5(h): # for h>=0

Curve:=proc(theta,x,y,z)
local hPlane, theta1, theta2, theta0, h0, Sol1, Sol2, R1, R2, h1, h2;
hPlane:=(x1,y1)->solve(x*x1 + y*y1 + z*z1, z1);
theta1,theta2:=sort([arctan(x,-y), arctan(-x,y)])[];
theta0:=(theta1+theta2)/2;
h0:=evalf(hPlane(cos(theta0),sin(theta0)));
Sol1:=fsolve({gg1(h)=R, x*R*cos(theta)+y*R*sin(theta)+z*h=0}, {R=0..5,h=-5..5});
Sol2:=fsolve({gg2(h)=R, x*R*cos(theta)+y*R*sin(theta)+z*h=0}, {R=0..5,h=-5..5});
R1:=eval(R,Sol1); R2:=eval(R,Sol2); h1:=eval(h,Sol1); h2:=eval(h,Sol2);
if h0<=0 then return
piecewise(theta>=theta1 and theta<=theta2,[R1*cos(theta),R1*sin(theta),h1], [R2*cos(theta),R2*sin(theta),h2]) else
piecewise(theta>=theta1 and theta<=theta2,[R2*cos(theta),R2*sin(theta),h2],[R1*cos(theta),R1*sin(theta),h1]) fi;
end proc:

# Example of calculating the coordinates of a point on this curve
evalf(Curve(Pi/3,3,1,2));

[.9683428665, 1.677219044, -2.291123822]

(1)

# The plotting of this curve
Plot2:=plots:-display(plottools:-curve([seq(Curve(t,3,1,2), t=-evalf(Pi)..evalf(Pi),0.05)]), color=red, thickness=4, scaling=constrained);

 

plots:-display(Plot1,Plot2);

 

 


 

Download Curve1.mw

Maple does not implement the solution of irrational inequalities with parameters. Here is a simpler example:

solve(sqrt(x-a)<x, x);

              Warning, solutions may have been lost

To calculate the values of derivatives of any order at a point, use  D  instead of  diff :

f:=x->x^2:
sum((D@@k)(f)(0), k=1..2);

 

As a workaround, use exact arifmetic:

answer := 5*exp(15/2*t);
response := subs(a = exp(1), 5*a^(15/2*t));
a := subs(t = Pi, answer);
b := subs(t = Pi, response);
simplify(a-b);

 

In order for Maple to solve this example step by step, we need to help it a little. To do this, first make the change  x=sin(t) . Maple shows a step-by-step solution, and in the end we do the inverse change and final simplification for a multiple argument:

A:=Int(x^2 * sqrt(1-x^2), x):
B:=IntegrationTools:-Change(A, x=sin(t));
Student:-Calculus1:-ShowSolution(B);
subs(t=arcsin(x), -(1/32)*sin(4*t)+(1/8)*t);
expand(%);

 

U:={1,2,3,4,5,6,7,8,9,10}:
A:={1,2,3,4}:
B:={4,5,6,7}:
C:={8,9,10}:
U minus C;

# Or in prefix notation
`minus`(U,C);


See the help page  Sets and Lists

If you already know the desired final result, then the easiest way is:

simplify(sin(4*Pi*w)/sin(2*Pi*w) - 2*cos(2*Pi*w));

Output :            0


The commands proposed in other answers are selected based on the already known result.
            

As an alternative you can use a  for-loop .

In the example below - the simplest way to plot the Pascal triangle:

N:=10:
for n from 0 to N do seq(binomial(n,k), k=0..n) od;


Acer's method does the same but the code is shorter a little:

N:=10:
seq(print(seq(binomial(n,k), k=0..n)), n=0..N);


 

 

plots:-intersectplot(x^2+y^2+z^2=1,x+y+z=0, x=-1..1, y=-1..1, z=-1..1);

This behavior seems like a bug. Here is a workaround:

sol_2:=subs(_C1=C[1], sol_1):
simplify(eval(ode, [sol_2, sol_2^2])) ;
                               
 0=0

restart;
A:=((y*sqrt(3) + 3)*sqrt(3))/(6*sqrt(y^2 + 1));
B:=(y + sqrt(3))/(2*sqrt(y^2 + 1));
	
expand(arctanh(A)-arctanh(B));

Output:        
                              0


 

I understood the  "identify"  word as the need to collect identical objects into separate groups (lists). The code below does this:

restart;
Eq1:=5.09295817894067*`&tau;u`[1, 1]-30.5577490736439*`&tau;u`[2, 1]+178.253536262923*`&tau;u`[3, 1]-30.5577490736439*`&tau;u`[1, 2]+183.346494441862*`&tau;u`[2, 2]-1069.52121757753*`&tau;u`[3, 2]+178.253536262923*`&tau;u`[1, 3]-1069.52121757753*`&tau;u`[2, 3]+6238.87376920228*`&tau;u`[3, 3]:
Eq2:=5.09295817894067*`&tau;u`[1, 1]+10.1859163578814*`&tau;u`[2, 1]+15.2788745368241*`&tau;u`[3, 1]-30.5577490736439*`&tau;u`[1, 2]-61.1154981472883*`&tau;u`[2, 2]-91.6732472209439*`&tau;u`[3, 2]+178.253536262923*`&tau;u`[1, 3]+356.507072525849*`&tau;u`[2, 3]+534.760608788841*`&tau;u`[3, 3]-3/7:
Eq3:=5.09295817894067*`&tau;u`[1, 1]-30.5577490736439*`&tau;u`[2, 1]+178.253536262923*`&tau;u`[3, 1]+10.1859163578814*`&tau;u`[1, 2]-61.1154981472883*`&tau;u`[2, 2]+356.507072525849*`&tau;u`[3, 2]+15.2788745368241*`&tau;u`[1, 3]-91.6732472209439*`&tau;u`[2, 3]+534.760608788841*`&tau;u`[3, 3]-9/7:
Eq4:=5.09295817894067*`&tau;u`[1, 1]+10.1859163578814*`&tau;u`[2, 1]+15.2788745368241*`&tau;u`[3, 1]+10.1859163578814*`&tau;u`[1, 2]+20.3718327157631*`&tau;u`[2, 2]+30.5577490736484*`&tau;u`[3, 2]+15.2788745368241*`&tau;u`[1, 3]+30.5577490736484*`&tau;u`[2, 3]+45.8366236104784*`&tau;u`[3, 3]-12/7:
Eq5:=5.09295817894067*`&tau;u`[1, 1]-30.5577490736439*`&tau;u`[2, 1]+178.253536262923*`&tau;u`[3, 1]+50.9295817894067*`&tau;u`[1, 2]-305.577490736439*`&tau;u`[2, 2]+1782.53536262923*`&tau;u`[3, 2]+504.202859715131*`&tau;u`[1, 3]-3025.21715829077*`&tau;u`[2, 3]+17647.1000900295*`&tau;u`[3, 3]-18/7:
Eq6:=5.09295817894067*`&tau;u`[1, 1]+10.1859163578814*`&tau;u`[2, 1]+15.2788745368241*`&tau;u`[3, 1]+50.9295817894067*`&tau;u`[1, 2]+101.859163578814*`&tau;u`[2, 2]+152.788745368241*`&tau;u`[3, 2]+504.202859715131*`&tau;u`[1, 3]+1008.40571943027*`&tau;u`[2, 3]+1512.60857914560*`&tau;u`[3, 3]-3:
Eq7:=5.09295817894067*`&tau;u`[1, 1]+10.1859163578814*`&tau;u`[2, 1]+15.2788745368241*`&tau;u`[3, 1]-30.5577490736439*`&tau;u`[1, 2]-61.1154981472883*`&tau;u`[2, 2]-91.6732472209439*`&tau;u`[3, 2]+178.253536262923*`&tau;u`[1, 3]+356.507072525849*`&tau;u`[2, 3]+534.760608788841*`&tau;u`[3, 3]-3/7:
Eq8:=5.09295817894067*`&tau;u`[1, 1]+10.1859163578814*`&tau;u`[2, 1]+15.2788745368241*`&tau;u`[3, 1]+10.1859163578814*`&tau;u`[1, 2]+20.3718327157631*`&tau;u`[2, 2]+30.5577490736484*`&tau;u`[3, 2]+15.2788745368241*`&tau;u`[1, 3]+30.5577490736484*`&tau;u`[2, 3]+45.8366236104784*`&tau;u`[3, 3]-12/7:
Eq9:=41.7622570673196*`&tau;u`[3, 1]+41.7622570673196*`&tau;u`[1, 3]+15.2788745368220*`&tau;u`[1, 1]+83.5245141346398*`&tau;u`[2, 3]+30.5577490736443*`&tau;u`[2, 1]+113.063671572516*`&tau;u`[3, 3]+83.5245141346398*`&tau;u`[3, 2]+30.5577490736443*`&tau;u`[1, 2]+61.1154981472892*`&tau;u`[2, 2]:

S:=[seq([i,Eq||i], i=1..9)];
S1:=[ListTools:-Categorize((u,v)->u[2]=v[2], S)];
map(t->op~(1,t), S1);
op(select(t->nops(t)>1, %));

The final result:     
                                    [2, 7], [4, 8]


If you just need to remove duplicates, then do

{seq(Eq||i, i=1..9)};

 

If we divide the total area of all the necessary pieces of plywood into the area of 1 standard plywood sheet  48*96=4608, we get about 2.56. Thus, at least 3 standard sheets are required. I just cut out proportional sized pieces of paper and in 10 minutes I found the right solution. Thus, 3 standard sheets are needed. All calculations and visualization are below. For ease of identification, pieces of the same size are painted in the same color. All sizes are in inches.

restart;

4 - "40.625 x 20" - green
2 - "36 x 20" - blue
2 - "34.75 x 20" - khaki
3 - "33.75 x 12" - cyan
6 - "18.825 x 12" - red
3 - "32.5 x 12" - pink
3 - "33.75 x 19.5" - gold

S[0]:=48*96; S[1]:=40.625*20; S[2]:=36*20; S[3]:=34.75*20; S[4]:=33.75*12; S[5]:=18.825*12; S[6]:=32.5*12; S[7]:=33.75*19.5;
L:=[4,2,2,3,6,3,3];
add(L[i]*S[i], i=1..7)/S[0];

4608

 

812.500

 

720

 

695.00

 

405.00

 

225.900

 

390.0

 

658.125

 

[4, 2, 2, 3, 6, 3, 3]

 

2.559629991

(1)


Code for a visualization

with(plottools): with(plots):
Colors:=[green,blue,khaki,cyan,red,pink,gold,yellow]:

A1:=rectangle([0,20],[40.625,0], color=Colors[1]):
A2:=rectangle([0,20+20],[40.625,20], color=Colors[1]):
A3:=rectangle([0,20+40],[40.625,40], color=Colors[1]):
A4:=rectangle([0,20+60],[40.625,60], color=Colors[1]):
A5:=rectangle([0,20*4+12],[33.75,0], color=Colors[4]):
A:=polygon([[40.625,0],[48,0],[48,96],[0,96],[0,92],[33.75,92],[33.75,80],[40.625,80]], color=Colors[8]):
T1:=textplot([[20,10,"40.625 x 20"],[20,30,"40.625 x 20"],[20,50,"40.625 x 20"],[20,70,"40.625 x 20"],[17,85,"33.75 x 12"]], font=[times,14]):
A11:=display(seq(A||k,k=1..5),A,T1):

B1:=rectangle([0,34.75],[20,0], color=Colors[3]):
B2:=rectangle([20,34.75],[32,1], color=Colors[4]):
B3:=rectangle([32,34.75],[44,1], color=Colors[4]):
B4:=rectangle([0,34.75+33.75],[19.5,34.75], color=Colors[7]):
B5:=rectangle([19.5,34.75+33.75],[19.5*2,34.75], color=Colors[7]):
B6:=rectangle([0,34.75+33.75+19.5],[33.75,34.75+33.75], color=Colors[7]):
B7:=rectangle([33.75,34.75+33.75+18.825],[33.75+12,34.75+33.75], color=Colors[5]):
B:=polygon([[20,0],[48,0],[48,96],[0,96],[0,34.75+33.75+19.5],[33.75,34.75+33.75+19.5],[33.75,34.75+33.75+18.825],[33.75+12,34.75+33.75+18.825],[33.75+12,34.75+33.75],[19.5*2,34.75+33.75],[19.5*2,34.75],[44,34.75],[44,1],[20,1]], color=Colors[8]):
T2:=textplot([[70,18,"34.75 x 20",'rotation' = (1/2)*Pi],[70,50,"33.75 x 19.5",'rotation' = (1/2)*Pi],[85,50,"33.75 x 19.5",'rotation' = (1/2)*Pi],[77,80,"33.75 x 19.5"],[86,18,"33.75 x 12",'rotation' = (1/2)*Pi],[97,18,"33.75 x 12",'rotation' = (1/2)*Pi],[100,77,"18.825 x 12",'rotation' = (1/2)*Pi]], font=[times,14]):
B11:=display(translate(display(seq(B||k,k=1..7),B),60,0),T2):

C1:=rectangle([0,32.5],[12,0], color=Colors[6]):
C2:=translate(C1,12,0):
C3:=translate(C1,24,0):
C4:=rectangle([36,18.825],[48,0], color=Colors[5]):
C5:=seq(translate(C4,0,18.825*k), k=1..4):
C6:=rectangle([0,52.5],[36,32.5], color=Colors[2]):
C7:=translate(C6,0,20):
C8:=rectangle([0,92.5],[34.75,72.5], color=Colors[3]):
C:=polygon([[0,92.5],[34.75,92.5],[34.75,72.5],[36,72.5],[36,96-18.825*5],[48,96-18.825*5],[48,96],[0,96]], color=Colors[8]):
T3:=textplot([[126,16,"32.5 x 12",'rotation' = (1/2)*Pi],[138,16,"32.5 x 12",'rotation' = (1/2)*Pi],[150,16,"32.5 x 12",'rotation' = (1/2)*Pi],seq([164,9+18.825*k,"18.825 x 12",'rotation' = (1/2)*Pi],k=0..4),[138,42,"36 x 20"],[138,62,"36 x 20"],[138,84,"34.75 x 20"]], font=[times,14]):
C11:=display(translate(display(seq(C||k,k=1..8),C), 120,0),T3):

display(A11,B11,C11, scaling=constrained, size=[950,540], axes=none);

 

 

 

                 

Plywood1.mw  

First 82 83 84 85 86 87 88 Last Page 84 of 292