Jean-Marc Roy

15 Reputation

One Badge

15 years, 242 days

MaplePrimes Activity


These are questions asked by

Hi - High school teacher 

I'm using the with(Physics): Setup(mathematicalnotation=true):with(Physics[Vector]): libraries which gives elegant answers to some of the questions of elementary vector algebra. 

But I become stuck when I try to simplify a simple expression like

Equa[01]:=AC_ = AB_ + BC_:Equa[01];                            #AC_ = AB_ + BC_
Equa[02]:={AB_=2*DB_,BC_=2*BE_}:Equa[02];
Equa[03]:=subs(Equa[02],Equa[01]):Equa[03];                
#AC_ = 2*DB_ + 2*BE_
simplify(Equa[03]);                                                              #also try combine

which gives

AC_ = 2*DB_ + 2*BE_

rather than what I was hoping for

AC_ = 2*DE_

I have define a type and build a clumsy addition procedure - with no hope of overloading '+'

###########################
# TYPE VecPos (Vecteurs liés)
#
###########################
`type/VecPos`:=proc(Exp)
    local LstExp:
    LstExp:=convert(Exp,string):
   if length(LstExp)=3 and LstExp[-1]="_" then
     true
   else
     false
   fi:
 end proc:
###########################
# TYPE AddVecSub (addition de vecteur subsécants)
#
###########################
AddVectSubs:=proc(Exp)
local va,vb,a,b:
  if patmatch(2*Exp,a::realcons*va::VecPos+b::realcons*vb::VecPos,'Corr') then
    a:=subs(Corr,a)/2:                  b:=subs(Corr,b)/2:
    va:=convert(subs(Corr,va),string):  vb:=convert(subs(Corr,vb),string):
    if a < 0 then
      va:=convert(cat(va[2],va[1],va[3]),string);
      a:= -a;
    fi;
    if b < 0 then
      vb:=convert(cat(vb[2],vb[1],vb[3]),string);
      b:= -b;
    fi;  
  fi;
 
  if va[2]=vb[1] then
    if a > b then
      return b*convert(cat(va[1],vb[2..3]),symbol)
         + (a-b)*convert(va,symbol);
    elif b > a then
      return a*convert(cat(va[1],vb[2..3]),symbol)
         + (b-a)*convert(vb,symbol);
    else
      return a*convert(cat(va[1],vb[2..3]),symbol)
    fi
  elif vb[2]=va[1]  then
    if a > b then
      return b*convert(cat(vb[1],va[2..3]),symbol)
          + (a-b)*convert(va,symbol);
    elif b > a then
      return a*convert(cat(vb[1],va[2..3]),symbol)
         + (b-a)*convert(vb,symbol);
    else
      return a*convert(cat(vb[1],va[2..3]),symbol)
    fi
  else
    return Exp
  fi
end proc:

 

But I am sure that their exist a better solution - which if possible should remain within the Physics[Vector] library. It is hard enough to convince high school student to use maple. Maybe adding rule in the setep... I just don't have the required time to look around.

Any help would be appreciated.

Thank

Jean-Marc Roy

Note:

patmatch(2*AB_ + 2*BC_,a::realcons*va::VecPos+b::realcons*vb::VecPos,'Corr');Corr;Corr:='Corr':

work, but neither

patmatch(AB_ + BC_,a::realcons*va::VecPos+b::realcons*vb::VecPos,'Corr');Corr;Corr:='Corr':
patmatch(AB_ + BC_,va::VecPos+vb::VecPos,'Corr');Corr;Corr:='Corr':


return results. Which explain why I mutiply 2*Exp in the addition function.
 

 


 

Page 1 of 1