this post was submitted on 27 Nov 2023
18 points (84.6% liked)

Asklemmy

43757 readers
1321 users here now

A loosely moderated place to ask open-ended questions

Search asklemmy ๐Ÿ”

If your post meets the following criteria, it's welcome here!

  1. Open-ended question
  2. Not offensive: at this point, we do not have the bandwidth to moderate overtly political discussions. Assume best intent and be excellent to each other.
  3. Not regarding using or support for Lemmy: context, see the list of support communities and tools for finding communities below
  4. Not ad nauseam inducing: please make sure it is a question that would be new to most members
  5. An actual topic of discussion

Looking for support?

Looking for a community?

~Icon~ ~by~ ~@Double_A@discuss.tchncs.de~

founded 5 years ago
MODERATORS
 

sorry for my layman terminology, but to my understanding as a coder a function has a name, parameters, arguments and operations. if sin is the name, and its parameters are side opposite and hypotenuse, and its arguments are context dependent, what is the operation itself? am i making sense?

def sin (hypotenuse, opposite):
     ??!?!?!!?
top 14 comments
sorted by: hot top controversial new old
[โ€“] dmention7@lemm.ee 8 points 11 months ago* (last edited 11 months ago)

This is kind of a weirdly phrased question.

Mathematically, THE argument of the sine function is the angle in question. One definition of sine, using the sides of a right triangle, is the ratio of the opposite leg to the hypotenuse of said triangle: sin(theta)=opposite/hypotenuse.

Edit: it occurred to me that maybe what you're asking is how to compute the angle, theta, for which sin(theta) = a certain ratio of opposite/hypotenuse. There is an inverse sine function (often called arcsin) that does just that. Arcsin(opp/hyp)=theta. That's the case where it would make sense to take the side lengths as arguments.

[โ€“] Haus@kbin.social 8 points 11 months ago (1 children)

I didn't get what you were asking until I started to answer. The parameter is the angle. The algorithm is https://en.wikipedia.org/wiki/CORDIC . In (most?) compiled languages, this algorithm is performed on hardware. In (some?) interpreted languages, it's done in hardware.

[โ€“] jackpot@lemmy.ml 2 points 11 months ago (1 children)

whats the difference between an algorhythm and a function

[โ€“] OwenEverbinde@lemmy.myserv.one 9 points 11 months ago* (last edited 11 months ago)

An algorithm is the meat of a function. It's the "how."

And if you're using someone else's function, you won't touch the "how" because you'll be interacting with the "what." (You use a function for what it does.)

You will be creating your own algorithm by writing code, however. Because an algorithm is just a sequence of steps that, taken together, constitute an attempt at achieving an objective.

Haus is saying all the little steps that go into approximating sine occur directly on the hardware.

[โ€“] OwenEverbinde@lemmy.myserv.one 3 points 11 months ago* (last edited 11 months ago)

Oddly enough, on a computer, I have not seen secant, cosecant, or cotangent.

I have seen sin, cos, tan, arcsin, arccos, and arctan.

Though the arc functions will only have one parameter, so if this is homework, you'll probably be avoiding the arcs and using secant and friends

Anyways:

sin ( angle )

Term In this example
Parameter Angle is the parameter. It's in radians, so in Java you'll use a conversion like Math.toRadians(a) on whatever number you're going to use as an argument
Argument If I were to call sin(Math.PI / 4) then I would be passing the argument ฯ€ / 4 to the function.
In other words, if a parameter is a question, then an argument is an answer. If a parameter is a coin slot, than an argument is the coin you choose to insert.
Operation An operation is practically synonymous with "function". It is performed on inputs to arrive at an output. However, usually in code, I hear "operation" used to describe things like /, *, and +. Things that have multiple inputs and a single output, all of the same form.

If someone is asking you, "which operation should you use in the body of function sin ( hyponetuse, opposite ) then I imagine the expected answer would be, / because

  1. / is an operation, and because
  2. opposite / hypotenuse will perform the division that yields the sine of whatever triangle those two sides belong to.
[โ€“] funnyboy_roks@lemmy.ml 2 points 11 months ago

The parameter for the sin function is an angle. The angle can be specified in either radians or degrees, depending on the context. The output of the sin function is the ratio between the opposite side and the hypotenuse on a right triangle like this.

There are many different algorithms which can be used to calculate sin(a), but all that I know require a decent understanding of Calculus (Taylor Series) or Trigonometry (CORDIC). You can find a Python implementation of the CORDIC algorithm here.

In a more general sense, the "operation" of the sin function is the "sin" operation. In maths, one very rarely goes lower than f(a) = sin(a) and when one does, it's often just to find an alternate way to estimate the value of sin. One can think of the sin function as being similar to ln(x) in that it is much closer to an operation than being an actual function.

[โ€“] BackOnMyBS@lemmy.world 1 points 11 months ago* (last edited 11 months ago)

I'm probably way too elementary for this post, but just in case someone doesn't know about SohCahToa (pro. soh-cah-toh-ah).

Soh

  • sin is opposite over hypotenuse

Cah

  • cos is adjacent over hypotenuse

Toa

  • tan is opposite over adjacent

I made it through my college trigonometry class by just remembering that one simple pneumonic. Everything else that was taught could be derived from it.

[โ€“] jackpot@lemmy.ml 1 points 11 months ago (2 children)

also what are the other fives operations, sin was just an example

[โ€“] criitz@reddthat.com 2 points 11 months ago* (last edited 11 months ago)

One way to think about it -

The argument to the function is an angle

The operation is:

Draw a triangle with hypotenuse length 1, one angle 90, another angle is the one passed to the function

Divide the length of the side opposite the passed angle by the length of the hypotenuse

Return this value

The other trig functions are the same with different sides being divided.

[โ€“] BassTurd@lemmy.world 1 points 11 months ago

I'm not a math expert by any means so I can't really answer the first part well. I can say that when I was taught trig, they were used to calculate angles in a triangle, and the function you used was dependent on the info you had. Sine/Cosecant, Cosine/Secant, and Tangent/Cotangent are the functions. Each function is paired with an opposite. To remember the formula, it's Soh Cah Toa, where the first letter is the the function, the second two are the inputs. So, Sin(x) == opposite/hypotenuse, and then the opposite of that is Sec(x) == hypotenuse/opposite, and so on.

That's poorly explained and leaves a lot of info on the table, but that's what I remember.

[โ€“] foggy@lemmy.world 1 points 11 months ago (1 children)
[โ€“] PipedLinkBot@feddit.rocks 1 points 11 months ago

Here is an alternative Piped link(s):

https://piped.video/Dsf6ADwJ66E?si=ISKljD_IdxC2_Na

Piped is a privacy-respecting open-source alternative frontend to YouTube.

I'm open-source; check me out at GitHub.