[squeak-dev] Re: problem face with plugin

Ang Beepeng beepeng86 at yahoo.com
Mon Oct 6 16:27:16 UTC 2008


primSolveGauss":bVector :xVector" 
	"primitive performs gaussian elimination"
	| mat1 bVec xVec result |

	self export: true.
	self inline: false.
	
	self var: #mat1 type:'float *'.
	self var: #bVec type:'float *'.
	self var: #xVec type:'float *'.
	
	xVec := self loadArgumentVector: (result := interpreterProxy
stackObjectValue: 0).
	bVec := self loadArgumentVector: (interpreterProxy stackObjectValue: 1).
	mat1 := self loadArgumentMatrix: (interpreterProxy stackObjectValue: 2).
			
	self solveGauss: mat1 with: bVec into: xVec.
		
	interpreterProxy pop:3 thenPush: result.



solveGauss: mat1 with: bVec into: xVec
	"perform gaussian elimination"
	| ratio temp a13 a12 a11|
	
	self var: #mat1 type:'const float *'.
	self var: #bVec type:'const float *'.
	self var: #xVec type:'float *'.
	
	self var: #a11 type:'double '.
	self var: #a12 type:'double '.
	self var: #a13 type:'double '.
	
	ratio := ((mat1 at: 3) / (mat1 at: 0)).
		mat1 at: 3 put: ((mat1 at: 3) - ((mat1 at: 0) * ratio)).
 		mat1 at: 4 put: ((mat1 at: 4) - ((mat1 at: 1) * ratio)).
		mat1 at: 5 put: ((mat1 at: 5) - ((mat1 at: 2) * ratio)).
		
	bVec at: 1 put: ((bVec at: 1) - (ratio * (bVec at: 0))).
	
	ratio := ((mat1 at: 6) / (mat1 at: 0)).
		mat1 at: 6 put: ((mat1 at: 6) - ((mat1 at: 0) * ratio)).
 		mat1 at: 7 put: ((mat1 at: 7) - ((mat1 at: 1) * ratio)).
		mat1 at: 8 put: ((mat1 at: 8) - ((mat1 at: 2) * ratio)).
	bVec at: 2 put: ((bVec at: 2) - (ratio * (bVec at: 0))).
	
	ratio := ((mat1 at: 7) / (mat1 at: 4)).
		mat1 at: 7 put: ((mat1 at: 7) - ((mat1 at: 4) * ratio)).
 		mat1 at: 8 put: ((mat1 at: 8) - ((mat1 at: 5) * ratio)).
	bVec at: 2 put: ((bVec at: 2) - (ratio * (bVec at: 1))).
	

	"Back substitution"
	a13 := (bVec at: 2) / (mat1 at: 8).
	
	temp := bVec at: 1.
	temp := temp - ((mat1 at: 5) * a13).
	a12 := temp / (mat1 at: 4).
	
	temp := bVec at: 0.
	temp := temp - ((mat1 at: 2) * a13).
	temp := temp - ((mat1 at: 1) * a12).
	a11 := (temp / (mat1 at: 0)).
	
	xVec at:0 put: (self cCoerce: a11 to: 'float').
	xVec at:1 put: (self cCoerce: a12 to: 'float').
	xVec at:2 put: (self cCoerce: a13 to: 'float').


About the coding, I'm trying to perform the gauss elimination row by row,
before coding it in loop. It takes in a 3x3 matrix along with two 3x1
vectors. 




askoh wrote:
> 
> Please show us your code. Aik-Siong Koh
> 
> 
> Ang Beepeng wrote:
>> 
>> I've wrote a simple plugin to perform Gaussian elimination on matrix.
>> Before compiling it, I test it with the simulator, 
>> MyPlugin doPrimitive: 'primGauss'.
>> 
>> The answer returned correctly. But after I compile it into an external
>> plugin, the plugin return different answer, wrong answer. Can anyone tell
>> me what are the possible mistakes I've make, where should I look into to
>> correct this.
>> 
>> Thanks.
>> 
>> Ang Beepeng
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/problem-face-with-plugin-tp19835169p19841331.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.




More information about the Squeak-dev mailing list