# Performing complicated calculation on bands in Google Earth Engine

I'm trying to perform ANIR index calculation on my image collection. I'm having trouble writing the code in the right way. ANIR index formula is :

``````cos^-1[((a^2)+(b^2)+(c^2))/(2*a*b)]
``````

(a2, b2 and c1, are Euclidean distances between bands B4, B8, B11/B12 respectively).

This is the function I have written so far-

``````var addANIR = function(image) {
var ANIR = image.expression(
'(1/cosin)',
{
'B4': image.select('B4'),
'B8': image.select('B8'),
'B11': image.select('B11'),
'cosin': top.cos()

}).rename('ANIR');
//NDVI index

//Add 0.0 value to NDVI (currently not in use)

};
``````

This function gives me an Error. What is wrong with the function/code?

I've never calculated this index, and am not convinced I got it completely right. But based on what you provided, it could look something like this:

``````var addANIR = function(image) {
var a = ee.Image().expression(
'sqrt((832.8 - 644.6)**2 + (i.B8 - i.B4)**2)', {i: image}
)
var b = ee.Image().expression(
'sqrt((1613.7 - 832.8)**2 + (i.B11 - i.B8)**2)', {i: image}
)
var c = ee.Image().expression(
'sqrt((1613.7 - 644.6)**2 + (i.B11 - i.B4)**2)', {i: image}
)
var anir = ee.Image().expression(
'1 / cos((a**2 + b**2 + c**2) / (2 * a * b))', {a: a, b: b, c: c}
).rename('ANIR')