Current Lua downloadable firmware will be posted here

User avatar
By Yomero
#64415 Hello everyone. A simple question :D , is there any way to activate the basic functions, such as trigonometric from the lmathlib.c file?

I have tried to build the firmware from docker by modifying or removing comments from the lmathlib.c file without success.

Any help is welcome.

Thanks in advance
User avatar
By Yomero
#64494 So I decided to create the trigonometric functions that I need for a project with a celerometer and a gyroscope following the link https://github.com/nodemcu/nodemcu-firmware/issues/1280.

When I create the arcsin function I am not getting the correct values ​​for the calculated values ​​(-1 to 1) in this function using the series equivalent to the arcsin function of this link https://en.wikipedia.org/wiki/Inverse_t ... _functions. The dfp and dfi functions represent the double factorial functions to even and odd numbers for the calculation of the series. I hope and can help the development of this function.

regards

Image

Here my code

Code: Select allfunction sin(x)
   local p=-x*x*x
   local f=6
   local r=x+p/f
   for j=1,60 do
      p=-p*x*x
      f=f*2*(j+1)*(j+j+3)
      r=r+p/f
   end
   return r
end

function cos(x)
   return sin(math.pi/2-x)
end

function tan(x)
   return sin(x)/cos(x)
end

function arcsin(x)
   local suma=x
   for i=1,60 do
      suma = suma + (dfi(2*i-1)/dfp(2*i))*(math.pow(x,2*i+1)/(2*i+1))
      print("Suma: "..suma)
   end
   return suma
end

function dfp(x)
   local par=1
   for i=2,x,2 do
      par = par * i
   end
   return par
end

function dfi(x)
   local impar=1
   for i=1,x,2 do
      impar = impar * i
   end
   return impar
end



Note that when generating an approximation with 60 values like sin function, the result does not get close to the correct one and if it increases near 200, the card will restart itself.

regards