Jump to content



Photo

Fraction Descomposition


  • Please log in to reply
8 replies to this topic

#1 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 01 June 2007 - 04:26 PM

This any form to calculate the constants and the poles of the fraction descomposition in CPLua (whit complex number too)?, can someone make some easy code please? I don't dominate the cas function.

The thing that I refere is something like this in matlab (or octave):
if you have this: 2/(x^2-5x+6)

B=[2]																		
B = 2
>> A=[1,-5,6]
A =

		 1		-5		 6

>> [c,r,k]=residue(B,A) 
c =

   2.00000
  -2.00000

r =

  3.00000
  2.00000

k = []

this, but if it suports complex numbers, it will be cool.

very thanks if someone can do that.

#2 vanhoa

vanhoa

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 854 posts
  • Gender:Male
  • Location:Vietnam

  • Calculators:
    AFX 2.0, CP 300, CP 330, nSpire, TI 89, FX 5800

Posted 02 June 2007 - 09:16 AM

Can u explain more?

#3 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 02 June 2007 - 11:43 AM

Can u explain more?


2		2	  -2		  _  C
________ = _____ + _____	 = \ _____
x^2-5x+6	(x-3)   (x-2)	  /_ (x-r)

(descomposici?n de fracciones de toda la vida)

#4 vanhoa

vanhoa

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 854 posts
  • Gender:Male
  • Location:Vietnam

  • Calculators:
    AFX 2.0, CP 300, CP 330, nSpire, TI 89, FX 5800

Posted 02 June 2007 - 04:09 PM

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 j=degree_of(ret[i],var)-1 temp_equation=temp_equation.."+("..num_eq(var,var_name,ic,j)..")/("..ret[i]..")" ic=ic+j 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 e
nd 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}

How to use:

residue ( numerator , denominator , [varible])

Examples:

Posted Image



#5 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 03 June 2007 - 07:56 PM

Thank you very much vanhoa ;)
(I think it doesn't function correctly when there are roots simply and composed (ex: 1, 2, 2), but it's the same thanks)

Other two thing: in LNA can I find numericly the imaginary roots of an equation? Can I write an imaginary number in CPLua?

#6 Guest_Guest_vanhoa_*_*

Guest_Guest_vanhoa_*_*
  • Guests

Posted 03 June 2007 - 10:18 PM

(I think it doesn't function correctly when there are roots simply and composed (ex: 1, 2, 2), but it's the same thanks)

Example? (Hungry up, I have a vacation)

Other two thing: in LNA can I find numericly the imaginary roots of an equation? Can I write an imaginary number in CPLua?

Ask PAP;)

#7 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 05 June 2007 - 01:51 PM

Ok in the numerator have to be none x.

for example: 1/(x^3-9x^2+24x-16)
denominator=0 -> x= 4, 4, 1

in your program appears: -(x/9-7/9)/(x-4)^2+1/9/(x-1) whit x in the numerator
and it has to show: -1/9/(x-4)+1/3/(x-4)^2+1/9/(x-1)

I know that is the same result numericly, but the method must be like the last one.
Can you do something?? thanks

#8 vanhoa

vanhoa

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 854 posts
  • Gender:Male
  • Location:Vietnam

  • Calculators:
    AFX 2.0, CP 300, CP 330, nSpire, TI 89, FX 5800

Posted 05 June 2007 - 03:41 PM

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 ;)

#9 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 05 June 2007 - 06:41 PM

oooo :o thank you vanhoa, enjoy your vacation.


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users