Kitonum

21435 Reputation

26 Badges

17 years, 29 days

MaplePrimes Activity


These are answers submitted by Kitonum

The procedure  InSphere  for any 4 points returns the center of the inscribed sphere and its radius. If the vertices of the tetrahedron are symbolic, then the result is also symbolic. Unfortunately, it takes quite a lot of time to do this calculation (see examples below). If the initial data (procedure arguments) are specified in float format, then the time is significantly reduced. You can play with this procedure for your own.


 

restart;
InSphere:=proc(P1::list,P2::list,P3::list,P4::list)
local Det, P, Var, Eq, V1, V2, V3, V4, Sys, Sol, sol;
uses LinearAlgebra;
Det:=Determinant(Matrix([P1-P2,P1-P3,P1-P4]));
if is(Det=0) then return  "Points P1, P2, P3, P4 should not lie in the same plane" fi;
P:=(P1+P2+P3+P4)/4;
Var:=[x,y,z];
Eq[1]:=Determinant(Matrix([Var-P1, P2-P1, P3-P1]));
Eq[2]:=Determinant(Matrix([Var-P1, P2-P1, P4-P1]));
Eq[3]:=Determinant(Matrix([Var-P1, P3-P1, P4-P1]));
Eq[4]:=Determinant(Matrix([Var-P2, P3-P2, P4-P2]));
V1:=[seq(coeff(Eq[1], t), t=Var)];
V2:=[seq(coeff(Eq[2], t), t=Var)];
V3:=[seq(coeff(Eq[3], t), t=Var)];
V4:=[seq(coeff(Eq[4], t), t=Var)];
Sys:=[abs(Eq[1])/sqrt(add(V1^~2))=abs(Eq[2])/sqrt(add(V2^~2)),
abs(Eq[1])/sqrt(add(V1^~2))=abs(Eq[3])/sqrt(add(V3^~2)),
abs(Eq[1])/sqrt(add(V1^~2))=abs(Eq[4])/sqrt(add(V4^~2))];
Sol:=[solve(Sys)];
sol:=select(p->`and`(seq(is(sign(evalf(eval(Eq[i],p)))=sign(evalf(eval(Eq[i],Var=~P)))), i=1..4)), Sol)[];
eval([x,y,z],sol), eval(abs(Eq[1])/sqrt(add(V1^~2)),sol);
end proc:
 

Examples

InSphere([1,2,3],[-2, 8, 9],[5, 0, 7],[3, 4, 2]); # Check of your example

[2, 3, 4], 1

(1)

ts:=time():
InSphere([10,0,0],[1,2,3],[5,0,7],[4,5,14]);  # An example of a bulky symbolic result
time()-ts;

[(2834549/2887773928)*12922^(1/2)*626^(1/2)+(5/55534114)*26^(1/2)*12922^(1/2)*2634^(1/2)*626^(1/2)+(13510265/2887773928)*26^(1/2)*2634^(1/2)-(213965/222136456)*26^(1/2)*12922^(1/2)-(138178/360971741)*12922^(1/2)*2634^(1/2)-(53177/222136456)*2634^(1/2)*626^(1/2)-(2933405/360971741)*626^(1/2)*26^(1/2)+139662527/27767057, -(30765/11551095712)*26^(1/2)*12922^(1/2)*2634^(1/2)*626^(1/2)+(8376135/5775547856)*26^(1/2)*12922^(1/2)-(813041/5775547856)*12922^(1/2)*2634^(1/2)-(4036289/5775547856)*12922^(1/2)*626^(1/2)+(19013165/5775547856)*26^(1/2)*2634^(1/2)+(743217/444272912)*2634^(1/2)*626^(1/2)+(64128125/5775547856)*626^(1/2)*26^(1/2)+192968797/222136456, (25019905/2887773928)*26^(1/2)*12922^(1/2)-(69606/360971741)*12922^(1/2)*2634^(1/2)+(219177/222136456)*2634^(1/2)*626^(1/2)-(2814605/2887773928)*12922^(1/2)*626^(1/2)+(2075/1443886964)*26^(1/2)*12922^(1/2)*2634^(1/2)*626^(1/2)-(24647225/2887773928)*26^(1/2)*2634^(1/2)+179806397/27767057-(8206215/721943482)*626^(1/2)*26^(1/2)], (1/130)*(511882075/27767057-(1641025/111068228)*12922^(1/2)*626^(1/2)-(40505/721943482)*26^(1/2)*12922^(1/2)*2634^(1/2)*626^(1/2)+(7672835/111068228)*26^(1/2)*2634^(1/2)+(103071165/1443886964)*26^(1/2)*12922^(1/2)-(389975/55534114)*12922^(1/2)*2634^(1/2)+(4821125/111068228)*2634^(1/2)*626^(1/2)+(4241755/27767057)*626^(1/2)*26^(1/2))*26^(1/2)

 

3.093

(2)

ts:=time():
InSphere(evalf~([[10,0,0],[1,2,3],[5, 0, 7],[4, 5, 14]])[]); # The same example in float format
time()-ts;

[4.977144054, 1.344206048, 6.253316149], 1.112666237

 

0.94e-1

(3)

 


 

Download InSphere.mw

restart;
Eq1:=-T*sin(theta(t)) = m*(diff(X(t), t, t)+L*(diff(theta(t), t, t))*cos(theta(t))-L*(diff(theta(t), t))^2*sin(theta(t))):

Eq2:= T*cos(theta(t))-m*g = m*(diff(Y(t), t, t)+L*(diff(theta(t), t, t))*sin(theta(t))+L*(diff(theta(t), t))^2*cos(theta(t))):

numer(solve(Eq1, m)-solve(Eq2, m)):
simplify(-%/T)=0;
               
      

When plotting replace  Im  with  'Im' .

plotmp_new.mw

 

No. For your case you need  unapply  command. An example:

a^2+b*c-c;
f:=unapply(%, a,b,c);
f(1,2,3);

plots:-display(plots:-implicitplot(y^4=y^2-x^2, x = 0.1 .. 0.3, y = 0.1 .. 0.3, color=blue), plot([[0.2, 0.2043096437]], style=point, symbol=solidcircle, color=red), view=[-0.5..0.5, -0.5..0.5]);
                 


Full view of the curve:

plots:-display(plots:-implicitplot(y^4=y^2-x^2, x = -1..1, y = -1..1, color=blue, gridrefine=3), plot([[0.2, 0.2043096437]], style=point, symbol=solidcircle, color=red), view=[-1..1, -1..1]);

 

Edit.
 

Since the probability density function is given explicitly, then all calculations are easy to make, simply by calculating the corresponding integrals without calling  Statistics  package. The code for the plottings can also be slightly simplified. 


 

NULL

restart

f := proc (x) options operator, arrow; (1/2)*sqrt(2)*exp(-(1/2)*x^2)/sqrt(Pi) end proc

proc (x) options operator, arrow; (1/2)*sqrt(2)*exp(-(1/2)*x^2)/sqrt(Pi) end proc

(1)

p1 := int(f(x), x = 0 .. .5)

.1914624613

(2)

p2 := int(f(x), x = -2.24 .. 1.12)

.8560976575

(3)

fsolve(int(f(x), x = -k .. k) = .847)

1.429014729

(4)

int(f(x), x = -% .. %)

.8469999999

(5)

P1 := plot(f(x), x = 0 .. .5, filled = [color = "Blue", transparency = .5])

P2 := plot(f(x), x = -3.5 .. 3.5)``

P4 := plots:-display(P1, P2)

 

P11 := plot(f(x), x = -2.24 .. 1.12, filled = [color = "Blue", transparency = .5])

P21 := plot(f(x), x = -3.5 .. 3.5)``

P31 := plots:-display(P11, P21)

 

 

   

NULL``

``

NULL

``

NULL

 

``

``


 

Download NormaleVisualizationCourbe_new.mw

There are so many errors in the point (5) of your code that it is much easier to completely rewrite it. Of course the proposed version is particular. For example, it may happen that  M2[j, j]=0  or the system may be inconsistent or the equations may be dependent. For the general case, the code will be significantly more complicated.

NULL

restart

with(LinearAlgebra)

M1 := Matrix(4, 4, {(1, 1) = 1, (1, 2) = 3, (1, 3) = -5, (1, 4) = 7, (2, 1) = 2, (2, 2) = -4, (2, 3) = 3, (2, 4) = -4, (3, 1) = 1, (3, 2) = 7, (3, 3) = 8, (3, 4) = -8, (4, 1) = 2, (4, 2) = -3, (4, 3) = -9, (4, 4) = -9})

Matrix(%id = 18446746330487566078)

(1)

b := Vector(4, {(1) = 7, (2) = 11, (3) = 2, (4) = 3})

Vector[column](%id = 18446746330487561862)

(2)

x := LinearSolve(M1, b)

Vector[column](%id = 18446746330487556566)

(3)

M2 := `<|>`(M1, b)

Matrix(%id = 18446746330487538862)

(4)

S := {`$`(1 .. 4)}; for j to 4 do for k in `minus`(S, {j}) do RowOperation(M2, j, 1/M2[j, j], inplace); RowOperation(M2, [k, j], -M2[k, j], inplace) end do end do; M2

S := {1, 2, 3, 4}

 

Matrix(%id = 18446746330487538862)

(5)

``


 

Download LGS_Gauss-Jordan_new.mw

We can use  sum  instead of  add , then no problem:

sum(sum(1, i=1..j), j=1..4);    
S:=%sum(%sum(1, i=1..j), j=1..4);
value(S); 


Also in the general case:

sum(sum(1, i=1..j), j=1..n);
simplify(%);


 

Note that Maple automatically sorts the elements of your sets in the first list in ascending order. ListTools:-MakeUnique function removes duplicate elements from a list, keeping the order of the elements. Here is Ronan's example:

L1 := [{3, 5}, {4, 5}, {4, 8, 9}, {-7, 2, 3}]:
L2 := ListTools:-MakeUnique(op~(L1));


For your example, use the same commands. 

You should use 2D math Maple Notation (not LaTeX notation) for this. See  Help  ?plot,typesetting

You forgot to put a multiplication sign between 2 parentheses. In addition, it is not clear where  c+cos(x)  should stand, in the numerator or denominator. Maple has the same priority for division and multiplication. Therefore, for example, A/B*C  is understood as  (A*C)/B , and not as  A/(B*C) . Here are the calculations for both cases:

Expr1:=sin(x)/(a*b+a^2*sin(x)^2-d^2*cos(x)^2)*(c+cos(x));
Expr2:=sin(x)/((a*b+a^2*sin(x)^2-d^2*cos(x)^2)*(c+cos(x)));
int(Expr1, x);
int(Expr2, x);
                


Here the indefinite integrals are calculated. To calculate definite integrals, certain restrictions on the parameters are necessary, since a singularity can occur, i.e. zero in the denominator for your range of the integration.

A direct calculation (simbolic and numeric):

restart;
A:=simplify(int(ln(1+x)^3/(x+I), x = 0 .. 1));
B:=simplify(int(ln(1+x)^3/(x-I), x = 0 .. 1));
(A+B)/2;

simplify(evalf(%), zero);
 

The imagenary unit should be coded in Maple as  I  (not  i ).
Here is an example of solving the equation  f(w,B,V,k)=0  for  w  for specified values  B, V, k :

gm:=V->1/sqrt(1-V^2): T:=w-k*V: S:=w*V-k:
f:=unapply(I*B*gm(V)^3*T^3+gm(V)^2*T^2-I*gm(V)^3*T*S^2-1/3*I*B*gm(V)^3*S^3*T-1/3*gm(V)^2*S^2, w,B,V,k);
F:=(B,V,k)->fsolve(f(w,B,V,k), w, complex);
F(1, 0.5, 2);


 

If I understand correctly, you have an equation with several parameters and you want to plot a graph that shows how the roots change depending on the change of parameters. To do this, you need to solve the equation numerically using  fsolve  command. Since the roots are not one, but several, then the number of plots should be the same as the number of roots. In the example below, we explore how the imaginary part of the roots of a quadratic equation changes depending on the change in parameters  p  and  q :

f:=(x,p,q)->x^2+p*x+q:
F:=(p,q)->fsolve(f(x,p,q), complex);
P1:=plot3d(Im('F'(p,q)[1]), p=-10..10, q=-10..10, color=grey, numpoints=10000, axes=normal):
P2:=plot3d(Im('F'(p,q)[2]), p=-10..10, q=-10..10, color=grey, numpoints=10000, axes=normal):
plots:-display(<P1 | P2>);


The graphs clearly show that the region where the imaginary part is 0, i.e. the roots are real, separated by the parabola  p^2-4*q=0  (i.e. the discriminant is 0), and the values of the complex roots are conjugate.


 

restart

sombrea2 := proc (f, g, a, b, paso) local z, m, result; m := a; result := [NULL]; while evalf(m <= b) do z := plot([g(m)+t*(f(m)-g(m)), m, t = 0 .. 1]); result := [op(result), z]; m := m+paso end do; result end proc

f := proc (t) options operator, arrow; -t^2+10 end proc

proc (t) options operator, arrow; -t^2+10 end proc

(1)

g := proc (t) options operator, arrow; t^2-t-3 end proc

proc (t) options operator, arrow; t^2-t-3 end proc

(2)

solve(f(t) = g(t), t)

1/4-(1/4)*105^(1/2), 1/4+(1/4)*105^(1/2)

(3)

with(plots)

plot([f(t), g(t)], t = -10 .. 10, -10 .. 10, color = ["blue", "green"])

 

a := plot({[-t^2+10, t, t = -5 .. 5], [t^2-t-3, t, t = -4 .. 4]})

b := sombrea2(f, g, 1/4-(1/4)*sqrt(105), 1/4+(1/4)*sqrt(105), .1)

display(a, b, scaling = constrained, size = [900, 300])

 

``

 

NULL

NULL


Edit.

Download maple17_new.mw

First 99 100 101 102 103 104 105 Last Page 101 of 289