# COSINE SIMILARITY examples, formula and calculations

[insert_php]if (empty(\$result)) \$result=’ result comes here’ ;
if(isset(\$_POST[‘save’]))
{
\$finalresult=0;
\$result=0;
\$resultss=0;
\$results=0;
\$n1=\$_POST[‘concentration’];
\$n2=\$_POST[‘valence’];if(!preg_match(“/([^\s][0-9].,?)./”, \$n1) && !preg_match(“/([^\s][0-9].,?)./”, \$n2))
{
echo ” Invalid “;
}
else
{
echo “inputs from first form are : “.\$n1;
echo “”;
echo “inputs from second form are : “.\$n2;
echo “”;
\$n1arr=explode(‘,’, \$n1);
\$n2arr=explode(‘,’, \$n2);
echo “________________________”;
echo “”;
if(count(\$n1arr)==count(\$n2arr))
{
echo “value after spliting first form variable in array is given below “;
for (\$i=0; \$i

# COSINE SIMILARITY CALCULATOR

Note: You must enter at least 3 values for each file, otherwise it will show invalid error.

Enter multiple values for file 1 separated by comma Enter multiple values for file 2 separated by comma Result[insert_php] echo \$result; [/insert_php]

## Example of COSINE SIMILARITY calculations

concentration = 2,4,6
valence = 2,4,6,1
Formula = cos(file 1, file 2) = (file 1 .file 2) / ||file 1|| ||file 2||
file1.file2 =56
||file1||sqrt (56)= 6.92
||file2||sqrt (56)= 6.92
cos(fil1.file2)= 56/7.48.7.48 = 0.999