Ronan

1331 Reputation

14 Badges

13 years, 44 days
East Grinstead, United Kingdom

MaplePrimes Activity


These are questions asked by Ronan

It is not that this a terribly difficult to work out, but I feel I am probably missing something. I need to check if a 3D point lies on a 3D line. What is a good approach here. I started of with the idea all alpha's are equal. but there are exceptions. See P3 and P4

restart

NULL

l := `<,>`(3+2*alpha, 1+6*alpha, 4-5*alpha)

Vector[column](%id = 36893489809910741940)

(1)

NULL

P := [9, 19, -11]

[9, 19, -11]

(2)

seq(solve({l[i] = P[i]}, alpha), i = 1 .. 3)

{alpha = 3}, {alpha = 3}, {alpha = 3}

(3)

l1 := `<,>`(3+2*alpha, 1+0*alpha, 4-5*alpha)

Vector[column](%id = 36893489809910721460)

(4)

P1 := [9, 1, -11]

[9, 1, -11]

(5)

seq(solve({l1[i] = P1[i]}, alpha), i = 1 .. 3)

{alpha = 3}, {alpha = alpha}, {alpha = 3}

(6)

l2 := `<,>`(3+2*alpha, 1+0*alpha, 4-0*alpha)

Vector[column](%id = 36893489809910705556)

(7)

P2 := [9, 1, 4]

[9, 1, 4]

(8)

seq(solve({l2[i] = P2[i]}, alpha), i = 1 .. 3)

{alpha = 3}, {alpha = alpha}, {alpha = alpha}

(9)

l3 := `<,>`(3+2*alpha, 0+0*alpha, 4-0*alpha)

Vector[column](%id = 36893489809963852012)

(10)

P3 := [9, 0, 4]

[9, 0, 4]

(11)

seq(solve({l3[i] = P3[i]}, alpha), i = 1 .. 3)

{alpha = 3}, {alpha = alpha}

(12)

P4 := [9, 0, -2]

[9, 0, -2]

(13)

seq(solve({l3[i] = P4[i]}, alpha), i = 1 .. 3)

{alpha = 3}, {alpha = alpha}

(14)

 

Download 2024-12-21_Q_3D_point_lies_on_3D_line.mw

2024-12-20_Q_simplification_Question.mw
Solve the general cubic. Apply values and simplify. 

Could someone show how Maple simplifies to the value of X=3? I tried doing it manually and I could not figure it out. 

Also is there a Help assistant to see the setps?

restart

 

 

X^3+a*X=b

X^3+X*a = b

(1)

 

 

sol:=solve(X^3+a*X=b,[X])

[[X = (1/6)*(108*b+12*(12*a^3+81*b^2)^(1/2))^(1/3)-2*a/(108*b+12*(12*a^3+81*b^2)^(1/2))^(1/3)], [X = -(1/12)*(108*b+12*(12*a^3+81*b^2)^(1/2))^(1/3)+a/(108*b+12*(12*a^3+81*b^2)^(1/2))^(1/3)+((1/2)*I)*3^(1/2)*((1/6)*(108*b+12*(12*a^3+81*b^2)^(1/2))^(1/3)+2*a/(108*b+12*(12*a^3+81*b^2)^(1/2))^(1/3))], [X = -(1/12)*(108*b+12*(12*a^3+81*b^2)^(1/2))^(1/3)+a/(108*b+12*(12*a^3+81*b^2)^(1/2))^(1/3)-((1/2)*I)*3^(1/2)*((1/6)*(108*b+12*(12*a^3+81*b^2)^(1/2))^(1/3)+2*a/(108*b+12*(12*a^3+81*b^2)^(1/2))^(1/3))]]

(2)

vals:=[a=6,b=45]

[a = 6, b = 45]

(3)

Nans:=(map(eval,sol,vals))

[[X = (1/6)*(4860+12*166617^(1/2))^(1/3)-12/(4860+12*166617^(1/2))^(1/3)], [X = -(1/12)*(4860+12*166617^(1/2))^(1/3)+6/(4860+12*166617^(1/2))^(1/3)+((1/2)*I)*3^(1/2)*((1/6)*(4860+12*166617^(1/2))^(1/3)+12/(4860+12*166617^(1/2))^(1/3))], [X = -(1/12)*(4860+12*166617^(1/2))^(1/3)+6/(4860+12*166617^(1/2))^(1/3)-((1/2)*I)*3^(1/2)*((1/6)*(4860+12*166617^(1/2))^(1/3)+12/(4860+12*166617^(1/2))^(1/3))]]

(4)

simplify(Nans)

[[X = 3], [X = (1/4)*(I*3^(1/2)*(180+44*17^(1/2))^(2/3)+(8*I)*3^(1/2)-(180+44*17^(1/2))^(2/3)+8)/(180+44*17^(1/2))^(1/3)], [X = -3/2-((1/2)*I)*51^(1/2)]]

(5)
 

 

Download 2024-12-20_Q_simplification_Question.mw

How do I get alpha to display as the Greek letter in DataFrame Row column?

restart

#varp:=alpha

QQFProj := proc(q12::algebraic, q23::algebraic,
                q34::algebraic, q14::algebraic,{varp:=:-alpha},
                  prnt::boolean:=true) #{columns:=[QQFproj,Q13proj,Q24proj]}
  description "Projective quadruple quad formula and intermediate 13 and 24 quads. Useful for cyclic quadrilaterals";
  local qqf,q13,q24, sub1,sub2,sub3, R,values,DF,lens;
  uses   DocumentTools;
  sub1:= (q12 + q23 + q34 + q14);
  sub2:=-4*(q12*q23*q34);
  sub3:=64*q12*q23;
  qqf:=(sub1+sub2)^2-sub3;
  q13:=(q12-q23)^2;
  q24:=varp*(q23-q34)^2;
  if prnt then
  
   values:=<qqf,q13,q24>;
   DF:=DataFrame(<values>, columns=[`"Values Equations"`],rows=[`#1  QQF`,`#2  Q13`,cat(`#3  Q24 (`,varp,`)`)]);
   lens := [4 +8* max(op(length~(RowLabels(DF)))),4+ min(max( 10*(length~(values))),1000)];#op(length~(ColumnLabels(DF)0)
   Tabulate(DF,width=add(lens),widthmode = pixels,weights = lens);
  return qqf,q13,q24
  end if;
  return qqf,q13,q24
end proc:

 q12:=1/2:q23:=9/10:q34:=25/26:q41:=9/130:#Cyclic quadrilateral
q12:=sqrt(17+a)/2:q23:=(r^2+t^2)^2/10:q34:=((a+b+c)^4/26):q41:=sqrt(17+b)/130:

Q:=QQFProj(q12,q23,q34,q41,true):

Download 2024-12-01_Q_Data_Table_alpha_as_Greek_Letter.mw

I am experimenting using the this format of  Vector( [Vector] ) to make projective vectors a different data type to Vectors. I don't want to use 1 x 3 or 3 x 1 matrices. The format holds some promise.
I would like to be able to copy the Maple format of Vector or Vector[column]    and Vector[row] for my varaition. 

ProjVectoC and ProjVectorR    so ProjVector or ProjVector[column]   and ProjVector[row]
A secondary question  is on type checking (see previous question How to setup special type check in a procedure? - MaplePrimes  ). Would it be possible to have the type check return ProjVector[column] or ProjVector[row]?
The attached worksheet contains a procedure for factor reducing the vectors to to a minimal format of <x,y,z>. Also   Cross product and Dot product procedures to suit.

I am open to any efficiency improvements.

restart

interface(rtablesize=50)

[10, 10]

(1)

with(LinearAlgebra):

 

FactReduce:=overload([
     proc(v::{list,Vector})
          option overload;
          description " removes linear factor from",
                      " a list, vector, matrix or expression";
          uses LinearAlgebra;
          local i, num,tgdc,dnm, V1;
          num:=`ifelse`(type(v,Vector),numelems(v),nops(v));
          dnm:=frontend(lcm, [seq(denom(v[i]),i=1..num)]);
          V1:=radnormal(v*~dnm);
          tgdc:=V1[1];

          for i from 2 to num do
               tgdc:=frontend(gcd, [tgdc, V1[i]]);
          end do;

          return  simplify(V1/~tgdc);
     end proc,

     proc(M::{Matrix})
          option overload;
          uses LinearAlgebra;
          local i, num,r,c, tgdc,dnm, V1, Ml;
          r,c:=Dimension(M);
          num:=r*c;
          V1:=convert(M,list);
          dnm:=frontend(lcm, [seq(denom(V1[i]),i=1..num)]);
          Ml:=radnormal(dnm*~M);
          V1:=convert(Ml,list);#print((dnm,V1));
          tgdc:=V1[1];#print("xx")

          for i from 2 to num do
               tgdc:=frontend(gcd, [tgdc, V1[i]])
          end do;

          return  simplify(Ml/~tgdc);   
     end proc,

     proc(l::{`+`,`*`,`=`, `symbol`,procedure},  {vars::list:=[:-x,:-y]})
          option overload;
          uses LinearAlgebra;
          local i, num,f1,f1a,lv,lr, tgdc,dnm, V1,Vs;
          f1 := `if`(l::procedure, l(vars[]), l);
               f1a:=`if`(f1::`=`,lhs(f1)-rhs(f1),f1)  ; # Remequal(f1);
          lr:=primpart(f1a,vars);
          return lr
end proc

]):

ProjVectorC := proc(a, b, c)
local cfs, vectr;
description " A Projective Column (Line) Vector in Reduced format";
cfs := FactReduce([a, b, c]);
vectr := <[<cfs>]>;
end proc:

 

ProjVectorR := proc(a, b, c)
local cfs, vectr;
description " A Projective Row (Point) Vector";
cfs := sign(c)*FactReduce([a, b, c]);
vectr := <[<cfs>^%T]>^%T;
end proc:

 

`&otimes;` := proc(A, B)
local cp;
description "Cross Product of Projective Vectors in Reduced format";
cp :=sign(c)* FactReduce(LinearAlgebra:-`&x`(A[1], B[1]))^%T;
cp := ifelse(cp[3] <> 0, <[sign(cp[3]) *~ cp]>, cp); #makes sure format is [x,y,z] and not [x,y-z]
end proc:

 

`&odot;` := proc(A, B)
description "Dot Product of Projective Vectors";
(A[1]) . (B[1]);
end proc:

 

V := ProjVectorR(2, 4, -6); W := ProjVectorR(11, 7, 5); S := ProjVectorC(6, -18, 24)

Vector[column](%id = 36893490982610361748)

(2)

whattype(V); `~`[whattype](V)

Vector[row](%id = 36893490982610825812)

(3)

whattype(S); `~`[whattype](S)

Vector[column](%id = 36893490982626471436)

(4)

`~`[whattype](V[1])

Vector[row](%id = 36893490982558545668)

(5)

V[1] . V[1]

14

(6)

`&odot;`(V, V)

14

(7)

R := `&otimes;`(W, V)

Vector[column](%id = 36893490982630825980)

(8)

R := `&otimes;`(V, W)

Vector[column](%id = 36893490982630903548)

(9)

whattype(R)

Vector[column]

(10)

`~`[whattype](R)

Vector[column](%id = 36893490982598861396)

(11)

`~`[whattype](R[1])

Vector[column](%id = 36893490982598866092)

(12)

`&otimes;`(R, S)

Vector[column](%id = 36893490982624872076)

(13)

`&odot;`(R, S)

-85

(14)

`&odot;`(W, R)

0

(15)

`&odot;`(R, `<,>`([`<,>`(x, y, 1)]))

15-31*x+38*y

(16)
 

 

Download 2024-11-21_Q_Projective_Vector_Format.mw

 About 2 years ago I asked this question Application of how to test types in a module? - MaplePrimes on type checking and @CarlLove provided a great answer for inputs to a procedure in that package.

In the package I have a procdure to plot/draw lines. They require sorting out when there is a list of them The procedure recognises the different possible input formats. Could the types be defined in the procdure body. It would make sorting out a lot easier. I could possibly add them to Module load at the start of the package.

restart

 

# Line type
#type _TNL1  expression type {`+`,`*`,`=`, `symbol`,procedure}                         2D line or any expression function equation

#type _TNL2  listlist [[a,b],[c,d]] or [[a,b,c],[d,e,f]]                               2D  line just draws a line between the 2 points

#type _TNL4  listlist [[a,b,c],[d,e,f]]                                                3D line just draws a line between the 2 points

#type _TNL4  list of list & vector 2D [[a,b],<c,d>]  or possibly  [<c,d>,[a,b]]        2D generates line A*x+B*y+C                        

#type _TNL5  list of list & vector 3D [[a,b,c],<d,e,f>] or possibly [<d,e,f>,[a,b,c]]  3D line <a+alpha*d, b+alpha*e, c+alpha*f>

#type _TNL6  vector 3D <a+alpha*d, b+alpha*e, c+alpha*f>                               3D line <a+alpha*d, b+alpha*e, c+alpha*f> checks indets to know

#type _TNL7  list of vector[row] and vector[row]  [<a|b|c>, <d|e|f>]                   projective points are converted to [a/c,b/c] and [d/f,e/f] and line drawn between the points

 

 

 

sorts:=proc(l1::{list,set,Vector[column],`+`,`*`,`=`, `symbol`,procedure},
{range::list:=[-5,5,-4,4]},
{vars::list:=[':-x',':-y']},
{rangep::list:=[-3,3]},
{plopts::list:=[':-colour'=':-blue,magenta']})

description " sort the list of line formats and converts to plotable format  ";

local i,n,Listsystem,subplt, subL, tmp, vv,ll,subpltemp;

      #single line;
if l1::{'Vector[column]',`+`,`*`,`=`, `symbol`,procedure} then
   n:=1;
   subplt:=[{}];
   if l1::'Vector[column]'(3) and indets(l1)={} then
      subL:=[l1[1]*vars[1]+l1[2]*vars[2]+l1[3]];
    else
      subL:=[l1];
   end if;
 elif l1::list and nops(l1)= 2 and not(hastype(l1,set))then
    #for j to 2 do
    #   if  l1[j][1]::listlist or l1[j][2]::listlist  then

                                                        # this section not finished supposed
                                                        # to detect is the list is two line without extra plopts, range, rangexy                                                  
   #   end if;
   # end do;
   n:=1;
   subplt:=[{}];
    #print("here now");
   if hastype(l1,'Vector[column]'(3)) and hastype(l1,list) then  
      #print("in  here");
      vv:=(select(type,l1,('Vector[column]'(3)))[]);
      ll:=select(type,l1,list)[];
      #print("vv " ,vv, "ll",ll);
      subL:=[ll+~alpha*vv];  
    elif hastype(l1,'Vector[column]'(2)) and hastype(l1,list)  then
      vv:=(select(type,l1,('Vector[column]'(2)))[]);
      ll:=select(type,l1,list)[];
      subL:=[ (ll[2] - vars[2])*vv[1] - vv[2]*(ll[1] - vars[1])];    
    else
      subL:=[l1];
  end if;
  
      #single line with own sub-options plopts range rangep bundled as a set
elif l1::set then
   n:=1;
   subpltemp,tmp:=selectremove(has,l1,{':-rangep',':-range',':-plopts',':-rangep'});
   #print("00",subpltemp,tmp);
   subplt:=`if`(has(subpltemp,{':-plopts',':-range',':-rangep'}),[subpltemp],[{}]);
   tmp:=op(tmp);
   #print("TMP ",tmp ,nops(tmp));
   if tmp::{'Vector[column]',`+`,`*`,`=`, `symbol`,procedure} then
  
     if tmp::'Vector[column]'(3) and indets(tmp)={} then
        subL:=[tmp[1]*vars[1]+tmp[2]*vars[2]+tmp[3]];
      elif hastype(tmp,'Vector[column]'(2)) and hastype(tmp,list)  then
        vv:=select(type,tmp,'Vector[column]'(2))[];
        ll:=select(type,tmp,list)[];
        subL:= [(ll[2] - vars[2])*vv[1] - vv[2]*(ll[1] - vars[1])];  
     else
       subL:=[tmp];
   end if;
 elif nops(tmp)= 2  then
   #print("0th nops(tmp)",nops(tmp),tmp);
   # print("here here now");
   if hastype(tmp,'Vector[column]'(3)) and hastype(tmp,list) then  
      #print("in  here here");
      vv:=(select(type,tmp,('Vector[column]'(3)))[]);
      ll:=select(type,tmp,list)[];
      #print("vv " ,vv, "ll",ll);
      subL:=[ll+~alpha*vv];
     elif hastype(tmp,'Vector[column]'(2)) and hastype(tmp,list)  then
      vv:=(select(type,tmp,('Vector[column]'(2)))[]);
      ll:=select(type,tmp,list)[];
      subL:=[ (ll[2] - vars[2])*vv[1] - vv[2]*(ll[1] - vars[1])];         
    else
      subL:=[tmp];
   end if;
   end if;

    #a list of lines with possible sub-options if
 else
   n:=nops(l1);
   subplt:=[];
   subL:=[];
   for i to n do
     subpltemp:=select(has,l1[i],{':-plopts',':-range',':-rangep'});
     #print("subpltemp",subpltemp);
     #print("subpltemp",has(subpltemp,{':-plopts',':-range',':-rangep'}));
     if has(subpltemp,{':-plopts',':-range',':-rangep'})then subplt:=  [subplt[],subpltemp]else subplt:=[subplt[],{}] end if;
     tmp:=select(not(has),l1[i],{':-plopts',':-range',':-rangep'});
     if type(tmp,set)then tmp:=op(tmp)end if;
     #print("TMP ",tmp ,nops(tmp));
     #print("1st nops(tmp)",nops(tmp),tmp);
     if tmp::{'Vector[column]',`+`,`*`,`=`, `symbol`,procedure} then
  
     if tmp::'Vector[column]'(3) and indets(tmp)={} then
        subL:=[subL[],tmp[1]*vars[1]+tmp[2]*vars[2]+tmp[3]];
      else
        subL:=[subL[],tmp];
     end if;
 elif nops(tmp)= 2  then
   #print("nops(tmp)",nops(tmp),tmp);
   #print("2nd here here now");
   if hastype(tmp,'Vector[column]'(3)) and hastype(tmp,list) then  
      #print("in  here here");
      vv:=(select(type,tmp,('Vector[column]'(3)))[]);
      ll:=select(type,tmp,list)[];
      #print(tmp,"vv " ,vv, "ll",ll);
      subL:=[subL[],ll+~alpha*vv];
    elif hastype(tmp,'Vector[column]'(2)) and hastype(tmp,list)  then
      vv:=(select(type,tmp,('Vector[column]'(2)))[]);
      ll:=select(type,tmp,list)[];
      #print(tmp,"vv " ,vv, "ll",ll);
      subL:= [subL[],(ll[2] - vars[2])*vv[1] - vv[2]*(ll[1] - vars[1])];           
    else
      subL:=[subL[],tmp];
  end if;
end if;
    
end do;
end if:
return subplt, subL, n
end proc:

 

L1:=2*x+3*y-4;
L1ext:={L1, range=[-5,2,-4,4],plopts=[colour=red ,linestyle=dot] };
L2:=<5,-1,3>:
L2ext:={L2,plopts=[linestyle=dash, thickness=4]}:
L3:=[[2,1],[4,-5]]:
L3ext:={L3,plopts=[color=red,thickness=1]}:
L4:=[[2,1,-3],[4,-5,-2]]:
L4ext:={L4,plopts=[color=green]}:
L5:=[[2,3],<-1,4>]:
L5ext:={L5,plopts=[color=green,thickness=2],range=[-6,6,-6,6]}:
L6:=[[1,2,-3],<-3,1,4>]:
L6ext:={L6,rangep=[-4,1],plopts[linestyle=dash]}:
L7:=<1+3*alpha,4-1*alpha,-1+2*alpha>:
L7ext:={L7,rangep=[-4,1],plopts=[colour=purlpe,thickness=3]}:
L8:=[<2|3|1>,<4|7|2>]:
L8ext:={L8,plopts=[colour=red]}:

2*x+3*y-4

 

{2*x+3*y-4, plopts = [colour = red, linestyle = dot], range = [-5, 2, -4, 4]}

(1)

 

Lst:=[L1,L1ext,L2,L2ext,L3,L3ext,x^2+2*y^2+3-4*x*y,L4,L4ext,L5,L5ext,L6,L6ext,L7,L7ext,L8,L8ext]:

A,B,c:=sorts(Lst):

for i to c do
print(i,"  A= ",A[i],"    B= ",B[i]);
end do

1, "  A= ", {}, "    B= ", 2*x+3*y-4

 

2, "  A= ", {plopts = [colour = red, linestyle = dot], range = [-5, 2, -4, 4]}, "    B= ", 2*x+3*y-4

 

3, "  A= ", {}, "    B= ", 5*x-y+3

 

4, "  A= ", {plopts = [linestyle = dash, thickness = 4]}, "    B= ", 5*x-y+3

 

5, "  A= ", {}, "    B= ", [[2, 1], [4, -5]]

 

6, "  A= ", {plopts = [color = red, thickness = 1]}, "    B= ", [[2, 1], [4, -5]]

 

7, "  A= ", {}, "    B= ", x^2-4*x*y+2*y^2+3

 

8, "  A= ", {}, "    B= ", [[2, 1, -3], [4, -5, -2]]

 

9, "  A= ", {plopts = [color = green]}, "    B= ", [[2, 1, -3], [4, -5, -2]]

 

10, "  A= ", {}, "    B= ", -11+y+4*x

 

11, "  A= ", {plopts = [color = green, thickness = 2], range = [-6, 6, -6, 6]}, "    B= ", -11+y+4*x

 

12, "  A= ", {}, "    B= ", Vector[column](%id = 36893490129638901388)

 

13, "  A= ", {plopts[linestyle = dash], rangep = [-4, 1]}, "    B= ", Vector[column](%id = 36893490129638901628)

 

14, "  A= ", {}, "    B= ", Vector[column](%id = 36893490129638901988)

 

15, "  A= ", {plopts = [colour = purlpe, thickness = 3], rangep = [-4, 1]}, "    B= ", Vector[column](%id = 36893490129661594308)

 

16, "  A= ", {}, "    B= ", [Vector[row](%id = 36893490129661594428), Vector[row](%id = 36893490129661594548)]

 

17, "  A= ", {plopts = [colour = red]}, "    B= ", [Vector[row](%id = 36893490129661594428), Vector[row](%id = 36893490129661594548)]

(2)
 

 

Download 2024-11-09_A_Line_Type.mw

1 2 3 4 5 6 7 Last Page 2 of 35