Ronan

1341 Reputation

15 Badges

13 years, 139 days
East Grinstead, United Kingdom

MaplePrimes Activity


These are questions asked by Ronan

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

What is the relationship between font size and screen pixels on plots? My screen are 2560 x1440 and 1920 x1200. Is for exanple size 12 font 12 pixels high?

Also when a diplay plot is say 800 x 600 pixels in size does the plot  does it use the max horizontal or vertical number of pixels? I know it may not fill the plot area in both directions. Or are some pixels trimmed of around the sides. Is it that the bounding box is the 800 x 600? I know when a caption is added the plot area is reduced in size vertically. 

I have angled some test to be parallel to the slope of a line. It tuns out that the text is only parallel if scaling = constrained is used. That is not necasserily pratical for many plots. In prcttice I have a nice proedure for this. Is there any way to pickup the plot x-y scaling factor that maple decides on so I could built that into the procedure. I have manually rescaled her to demonstrate.

mmm...I see the website viewer does not rotate the text.

restart

with(plots):

P1:=[1,2]:P2:=[5/2,3]:

vec:=P2-P1

[3/2, 1]

(1)

ang:=arctan(vec[2],vec[1])

arctan(2/3)

(2)

plt1:=textplot([((P1+P2+[.2,.2])/2)[],"parallel piece of text",rotation=ang]):

plt2:=plottools:-line(P1,P2):

display(plt1,plt2)

 

display(plt1,plt2,scaling=constrained)

 

#scaling factor looks to be 1.5 i.e.delta(x)/delta(y) (2.5-1)/{3/2)

ang1:=arctan(1.5*vec[2],vec[1])

.7853981634

(3)

plt3:=textplot([((P1+P2+[.2,.2])/2)[],"parallel piece of text",rotation=ang1]):

display(plt3,plt2)

 
 

 

Download 2024-10-15_text_not_always_parallel.mw

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