Uhm sorry, I havent learnt this at school so i dont have the right define about it.
Updated:
require "cas" require "string" require "table" function residue(num,den,var) local temp_equation,temp_equation2,ret,i,j,k,ic if not var then var="x" end statusbar("Now simplifying...") temp_equation=cas("simplify(("..cas(num)..")".."/".."("..cas(den).."))") num=tostring(cas("numerator("..temp_equation..")")) den=tostring(cas("denominator("..temp_equation..")")) temp_equation2=den while cas.diff(temp_equation2..","..var)~=cas("0") do temp_equation2=cas("expand(1/"..var.."*("..temp_equation2.."-("..temp_equation2.."|"..var.."=0") end num=cas("1/("..temp_equation2..")*("..num..")") den=cas("1/("..temp_equation2..")*("..den..")") statusbar("Now factoring...") temp_equation2=tostring(cas("factor("..den)) ret={} j=1 if string.sub(temp_equation2,1,1)=="(" then i=nil else i=1 end repeat if string.sub(temp_equation2,j,j)=="(" then if i~=nil then ret[#(ret)+1]="("..cas(string.sub(temp_equation2,i,j-3))..")" end i=j end j=j+1 until j>string.len(temp_equation2) ret[#(ret)+1]="("..cas(string.sub(temp_equation2,i,string.len(temp_equation2)))..")" local degree_of=function(f,v) local ret=0 while(f~="0") do ret=ret+1 f=tostring(cas.diff(f..","..v)) end return ret end statusbar("Now calculating...") local var_name="nouse" temp_equation=temp_equation.."-(" k=string.len(temp_equation) local num_eq=function(s1,s2,i1,i2) local ret=s2..i1 while i2>1 do i2=i2-1 i1=i1+1 ret=ret.."+"..s2..i1.."*"..s1.."^"..i2 end return ret end ic=0 for i=1,#(ret),1 do if string.find(ret[i],"%^")==nil then j=degree_of(ret[i],var)-1 temp_equation=temp_equation.."+("..num_eq(var,var_name,ic,j)..")/("..ret[i]..")" ic=ic+j else local inpower="" local tmpchar="" local i2=2 repeat inpower=inpower..tmpchar tmpchar=string.sub(ret[i],i2,i2) i2=i2+1 until tmpchar=="^" while ret[i]~="(1)" do j=1 temp_equation=temp_equation.."+("..num_eq(var,var_name,ic,j)..")/("..ret[i]..")" ic=ic+j ret[i]="("..tostring(cas(ret[i].."/"..inpower))..")" end end end local retsize=ic ret=string.sub(temp_equation,k+1) temp_equation=tostring(cas("collect(numerator(combine("..temp_equation)) temp_equation2="{" i=0 while temp_equation~="0" and i<retsize do j=tostring(cas(temp_equation.."|"..var.."=0")) temp_equation2=temp_equation2..cas(j).."," temp_equation=tostring(cas.diff(temp_equation..","..var)) i=i+1 end if(i<retsize) then for j=i+1,retsize,1 do temp_equation2=temp_equation2.."0," end end temp_equation2=string.sub(temp_equation2,1,string.len(temp_equation2)-1).."}" temp_equation="" for i=1,retsize,1 do temp_equation=temp_equation..var_name..(i-1).."," end temp_equation=string.sub(temp_equation,1,string.len(temp_equation)-1) ret=tostring(cas(ret.."|solve("..temp_equation2..",{"..temp_equation.."}")) statusbar("") return ret end export{residue=residue}--(c) vanhoa 2007
I think that's okey, let me enjoy my vacation