Jump to content

How to simulate 'INV' or 'TAN ^ -1'...?


 Share

Recommended Posts

Greetings,

  I have a need to use a Tan function to a power of "-1".  On a calculator this is normally the "INV" key or possibly the "2nd" key.  The "Tan ^ -1" should return a value in degrees.  This seems to not be exactly possible using AutoIT.  Here is a sample script:

 

#include <MsgBoxConstants.au3>
#include <Math.au3>

Local $_value = .25
ConsoleWrite("tan convert to degrees value is: " & _Degree(Tan($_value)) & @CRLF)  ;returns 14.63   *....SEEMS CLOSE...*  should be 14.036

And I also attempted:

ConsoleWrite("inverse tan of value is: " & Tan($_value) ^ -1 & @CRLF)  ;returns 3.916 however should be 14.036 
ConsoleWrite("inverse tan of value is: " & _Degree(Tan($_value) ^ -1) & @CRLF)  ;returns 224.388 however should be 14.036
ConsoleWrite("inverse tan of value is: " & (Tan ^ -1) * ($_value) & @CRLF)  ;returns 1.#INF

As can be seen in the code...the closest answer (from what I get on a calculator) is "14.63"...when the calculator indicates it should be "14.036"...is there some reason for the discrepancy?  Is simulation of a "INV" or "2nd" key on the calculator possible using AutoIT?  I thank you in advance for any suggestion.   

Link to comment
Share on other sites

3 hours ago, Burgs said:

_Degree(Tan($_value))

This doesn't make sense! Tan($x) is a scalar value, not an angle.

As @ahmet just said, you need ATan($x)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thanks to both of you that replied.  I have attempted the ATan function, however I am seeing a value returned of "0.244978663126864", which is not what my Windows 11 calculator is returning (using '2nd' and 'Tan ^ -1').

Sorry about the "Degree(Tan($_value))" I mis-read the documentation and thought the value was returned in radians and I wanted to convert to degrees...however I see the INPUT is in radians. 

I am trying to reproduce the values in this information, "https://www.usgs.gov/educational-resources/determine-percent-slope-and-angle-slope".  Specifically the information located in the second part of the page beginning at "Angle of Slope" in a bold font.

 

 

Link to comment
Share on other sites

  • Moderators

Burgs,

These are my results for Tan-1(.25) in radians:

  • AutoIt ATan function:                  0.244978663126864
  • My Sharp scientific calculator:  0.24497866
  • My Windows 10 calculator:        0.24497866312686415417208248121128

The 26.5 degrees mentioned for ATan(.5) on the page to which you linked is obviously floored from the actual value of 26.565051. All 3 methods mentioned above match to 6 decimal places.

Do you still have a problem?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks for your input Melba, I think I have it now...just need to convert those results to degrees, which the calculator did automatically.  I am old also...hahaha .  Regards to you and the others that replied.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...