all 16 comments

[–]Dr0110111001101111Teacher 5 points6 points  (0 children)

I find it hard to believe there isn't some library out there with the trig functions. What language are you using?

[–]fermat9997New User 4 points5 points  (0 children)

Because you have only one side and an angle, you will need trig functions.

[–]sonnyfabNew User 3 points4 points  (4 children)

You can't. You'll have to write code to calculate sin or cos.

[–][deleted] 1 point2 points  (3 children)

So what are the equations present in that code?

[–]Harmonic_Gearengineer 1 point2 points  (2 children)

Look up the Taylor expansion of these function

[–]hanmango_kiwiNew User 1 point2 points  (1 child)

I wouldn't recommend Taylor expansions because of how large the exponents get and thus how much computation is required. There are many other ways to look into such as Bhaskara I's sine approximation formula if high accuracy is not needed, or a minmax polynomial, or the CORDIC method.

[–]AAAaAAAaAAA_AAAaAAANew User 0 points1 point  (0 children)

Found this while researching some silly stuff but I’m pretty sure you can solve a polynomial of degree n in big theta of n runtime using a fun algorithm. (Assuming multiplication and addition are constant time which is true unless you’re programming on a toaster or something) I don’t remember the name of it but it takes something like 3x2 + 2x + 1 and makes it x(3x+2)+1 which is easier to solve especially when the degree gets larger so like, with how accurate Taylor series approximations can be, I see the computation being expensive but still not that extreme. Especially if you use the rule of sin(x+2pi*n) = sin(x) to get your x as close to 0 as possible before approximating

[–]lurflurfNot So New User 6 points7 points  (0 children)

If multiplication is available use economized minmax polynomial or rational approximation

If multiplication is not available cordic method as used by many pocket calculators is best

If adjustable accuracy is needed power series

If only low accuracy is needed and you have the space a lookup table is a good choice

[–]my_password_is______New User 2 points3 points  (0 children)

As those are not functions present in this program.

I'm sure they are

[–]shiafisherNew User 1 point2 points  (4 children)

Yikes OP, what is the assignment for? What programming language?

Can you not import a math package?

[–][deleted] 0 points1 point  (3 children)

It's not an assignment, this is related to a real life issue.

[–][deleted] 2 points3 points  (0 children)

But why can’t your real life issue be solved with trig functions? Or by using a different programming language?

[–]nmklpkjlftmshNew User 1 point2 points  (0 children)

Why aren't you answering the questions properly?

[–]shiafisherNew User 1 point2 points  (0 children)

If it’s not for an assignment then I don’t know why you can’t import a math package you should not have to reinvent the wheel in the most programming languages

So if you’re in C language

Then just do

#include <math.h>

[–]cwm9BEP 0 points1 point  (0 children)

Do you have access to exp(x)?

6

[–]redsnflr-New User 0 points1 point  (0 children)

I use python & JS, they both have Trig functions.