Quantcast
Channel: MaplePrimes - Questions and Posts tagged with 2dmath
Viewing all articles
Browse latest Browse all 296

Why are procedures behaving differently in package?

$
0
0

The procedures "getCP" which uses "cpsub" (not exported) acts differently inside the package as opposed to them outside it.
In the package it returns a column matrix which is incorrect. Should return a 2 row matrix. They dismantle a polynomial into it's powers and coefficients. I know one cant run the package here. Included are the two procedures and the text of the notepad file to make the package.

restart

NULL

with(AlgCalc)

[`⊕`, FundThrm, SignedArea, diag, diftab, faulD, faulS, getCP]

f := sort(2+x^7+5*x^2-7*x^a+k*x^2, [x], ascending)

2-7*x^a+5*x^2+k*x^2+x^7

getCP(f, x)

Matrix(%id = 36893490212391698668)

NULL

g := sort(5*x^8+k*x^2-7*x^3+x+2, [x], ascending)

2+x+k*x^2-7*x^3+5*x^8

CP := getCP(g, x)

Matrix(%id = 36893490212391688180)

NULL

restart

with(AlgCalc)

[`⊕`, FundThrm, SignedArea, diag, diftab, faulD, faulS, getCP]

NULL

f := sort(2+x^7+5*x^2-7*x^a+k*x^2, [x], ascending)

2-7*x^a+5*x^2+k*x^2+x^7

getCP(f, x)

Matrix(%id = 36893490212390043884)

g := sort(5*x^8+k*x^2-7*x^3+x+2, [x], ascending)

2+x+k*x^2-7*x^3+5*x^8

getCP(g, x)

Matrix(%id = 36893490212390032796)

 

restart

 

Dismantlimg a polynomial  uses the following 2 procedures

" cpsub:= proc(t, var:=alpha)  description "used by getCP";       local i,cf,varpwr;                   if   not has(t, var)                  then return < 0,t>:               elif whattype(t)=`^` then return <op(t)[2],1>;                  else varpwr,cf:= selectremove(has,[op(t)],var);                       if op(varpwr)=var then                        return <1, `*`(op(cf))> ;                   end if;                     for i from 1 to nops(varpwr) do                    if numer(varpwr[i])=1  then if op((1)/(varpwr[i]))=alpha then varpwr[i]:=-1 else  varpwr[i] :=-op((1)/(varpwr[i]))[2] end if else  varpwr[i]:=op(varpwr[i])[2]end if                        end do;                   return <`+`(op(varpwr)),`*`(op(cf))>;                   #print(op(t));                                   end if ;            end proc:"

NULL

``

getCP := proc (f, var := alpha) local t; description "Dissmantles a polynomial into powers and coefficients"; if not has(f, var) then return `<,>`(0, f) elif whattype(f) = `^` then return `<,>`(op(f)[2], 1) elif whattype(f) = `*` then return `<|>`(`~`[cpsub]([f], var)[]) else `<|>`(`~`[cpsub]([op(f)], var)[]) end if end proc

NULL

f := sort(2+x^7+5*x^2-7*x^a+k*x^2, [x], ascending)

2-7*x^a+5*x^2+k*x^2+x^7

cp := getCP(f, x)

Matrix(%id = 36893490212391322676)

whattype(cp)

Matrix

NULL

Notepad file to Create AlgCalc.

 

AlgCalc := module ()
export SignedArea,
           `&oplus;`,

             getCP,

             diag,
             diftab,
             faulD,
             faulS,
             FundThrm;
        

 option package;

$include "SignedArea.mm"
$include "`&oplus;`.mm"
$include "cpsub.mm"
$include "getCP.mm"
$include "diag.mm"
$include "diftab.mm"
$include "faulD.mm"
$include "faulS.mm"
$include "FundThrm.mm"

end module;

Download 6-11-22_Procedures_acting_differently_in_Package.mw


Viewing all articles
Browse latest Browse all 296

Trending Articles