CFLib.org – Common Function Library Project

ComplexNumMultiply(Multiplicand, Multiplier)

Last updated November 15, 2001

author

Matthew Walker

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Multiply two complex numbers, or a real and a complex number, or two real numbers and return the result stored as a structure.

Return Values:
Returns a structure.

Example:

<cfset a = ComplexNum(3,4)>
<cfset b = ComplexNum(1,-10)>
<cfset c = ComplexNumMultiply(a,b)>
<cfset d = ComplexNumMultiply(a,3)>
<cfoutput>
	(#ComplexNumToString(a)#) * (#ComplexNumToString(b)#) = #ComplexNumToString(c)#<br>
	(#ComplexNumToString(a)#) * 3 = (#ComplexNumToString(d)#)
</cfoutput>

Parameters:

Name Description Required
Multiplicand Structure containing a complex number or a real number. Yes
Multiplier Structure containing a complex number or a real number. Yes

Full UDF Source:

/**
 * Multiply two complex numbers.
 * Note that this function uses complex numbers stored as structures by the ComplexNum() UDF also available in this library.  The ComplexNum() function is also required for this UDF to function.
 * 
 * @param Multiplicand 	 Structure containing a complex number or a real number. 
 * @param Multiplier 	 Structure containing a complex number or a real number. 
 * @return Returns a structure. 
 * @author Matthew Walker (matthew@electricsheep.co.nz) 
 * @version 1, November 15, 2001 
 */
function ComplexNumMultiply(Multiplicand,Multiplier) {
	var ComplexProduct = StructNew();
	var ComplexMultiplicand = 0;
	var ComplexMultiplier = 0;
	var R = 0;
	var I = 0;
			
	if ( IsStruct(Multiplicand) )
		ComplexMultiplicand = Multiplicand;
	else	
		ComplexMultiplicand = ComplexNum(Multiplicand,0);	
	if ( IsStruct(Multiplier) )
		ComplexMultiplier = Multiplier;
	else	
		ComplexMultiplier = ComplexNum(Multiplier,0);
				
	R = ComplexMultiplicand.R * ComplexMultiplier.R - ComplexMultiplicand.I * ComplexMultiplier.I;
	I = ComplexMultiplicand.R * ComplexMultiplier.I + ComplexMultiplicand.I * ComplexMultiplier.R;
	StructInsert(ComplexProduct, "R", R);
	StructInsert(ComplexProduct, "I", I);
	return ComplexProduct;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson