Jump to content
IGNORED

MATH FORMULA's


Recommended Posts

On the 8-bit Atari's there are very few subjects that I don't understand and for 2 reasons: 1. I never got round to it, and 2. They are quite often too complicated for me to understand. Algorythms is one (of which I will be looking into soon) and 1 of the others is math formula's: Take for instance, the basic circle using COS and SIN:

 

10 GRAPHICS 8:DEG :COLOR 1

12 SZ=50

20 FOR D=0 TO 359

30 X=(COS(D)*SZ)+160

40 Y=(SIN(D)*SZ)+96

50 PLOT X,Y

60 NEXT D

 

This is fine, I understand COS and SIN, but what about other formulas such like:

 

COSH(x) = (EXP(x)+EXP(-x))/2   -   exactly how would I implement this in practice (in a program)? What does COSHH(x) do exactly?

 

There is a lot of formulas (that I wrote) in the Compete & Essential MAP part II, page 235. I understand the syntax but dont have a clue as to implementing them into a BASIC program. Some other formulas include:

 

TAN(x) = SIN(x)/COS(x)

SEC(x)=1/COS(x)

LOG(base a)(x) = LOG(x)/LOG(a)

 

Any help would be most appreciated, thankyou.

 

Edited by ac.tomo
Link to comment
Share on other sites

These are not assignments, but equations. It means that the left hand side is the same as the right hand side. Similar to how

 

2 = 1 + 1

 

tells us that two is equal to one plus one,

 

tan(x) = sin(x) / cos(x)

 

tells us that the tangent of x is equal to dividing the sinus of x by the cosinus of x.

 

Edited by ivop
Link to comment
Share on other sites

2 hours ago, ac.tomo said:

On the 8-bit Atari's there are very few subjects that I don't understand and for 2 reasons: 1. I never got round to it, and 2. They are quite often too complicated for me to understand. Algorythms is one (of which I will be looking into soon) and 1 of the others s math formula's


This is fine, I understand COS and SIN, but what about other formulas such like:

 

COSH(x) = (EXP(x)+EXP(-x))/2   -   exactly how would I implement this in practice (in a program)? What does COSHH(x) do exactly?

 

There is a lot of formulas (that I wrote) in the Compete & Essential MAP part II, page 235. I understand the syntax but dont have a clue as to implementing them into a BASIC program. Some other formulas include:

 

TAN(x) = SIN(x)/COS(x)

SEC(x)=1/COS(x)

LOG(base a)(x) = LOG(x)/LOG(a)

 

Any help would be most appreciated, thankyou.

 

Formulae, or formulas. (no apostroph here).  EXP(X) = E^X, where E=2.7181... Thus, cosh(X)=0.5*(E^X+E^-X).

 

COSH(x) is the line a chain (or string) forms if supported on its two ends, just to name one popular example. Cosh is related to cos in the complex plane. (cosh(ix)  = cos(x) where i is the complex unit, i.e. i^2=-1).

 

I'm unclear where the problem of implementing tan is. It is actually written there. Y=SIN(X)/COS(X) computes the tangent of the argument. Ditto for the secant.

 

As far as the log goes: This computes the logarithm to an arbitrary base. For example log_2(x) = LOG(X)/LOG(2). Concerning its use, y=log_2(x) is the unique number such that 2^y=x, i.e. b^(log_b(x))=x, or B^(LOG(X)/LOG(B))=X.

 

 

Link to comment
Share on other sites

17 minutes ago, thorfdbg said:

I'm unclear where the problem of implementing tan is.

I think the problem is ac.tomo thought it were assignments, like COSH(X) is an array index by X, and then assigned the result of an expression.

 

Link to comment
Share on other sites

17 hours ago, ivop said:

These are not assignments, but equations. It means that the left hand side is the same as the right hand side. Similar to how

 

2 = 1 + 1

 

tells us that two is equal to one plus one,

 

tan(x) = sin(x) / cos(x)

 

tells us that the tangent of x is equal to dividing the sinus of x by the cosinus of x.

 

I understand this, but be it tan(x) or sin(x)/cos(x) I still can't make use of them like I do with cos and sin in my program.

Link to comment
Share on other sites

tan(x) is just another way to calculate an angle given certain parameters.

 

e.g. say for example you have a triangle with side lengths 3(opposite),4(adjacent),5(hypotenuse)

sin of an angle (between 4 and 5) is length of opposite side/hypotenuse

cos of the same angle is adjacent side/hypotenuse

tan of the same angle is opposite/adjacent

 

So knowing only that you can calculate the angle, same can be done for other angles.

Link to comment
Share on other sites

1 hour ago, ac.tomo said:

I understand this, but be it tan(x) or sin(x)/cos(x) I still can't make use of them like I do with cos and sin in my program.

Sure you can:


10 DEG

20 X = 45

30 A = SIN(X)

40 B = COS(X)

50 C = A/B

60 D = SIN(X) / COS(X)

 

Both C and D are equal to TAN(X).

  • Like 1
Link to comment
Share on other sites

4 hours ago, ac.tomo said:

I still can't make use of them like I do with cos and sin in my program.

Or perhaps you mean that it doesn't result in nice images? Here's what the function looks like: (sourced and linked from britannica)

 

relationships-Tangent-curve-tangent-heig

 

Note how the values go to plus or minus infinity. 2*pi radians equals 360 degrees. pi/2 radians equals 90 degrees.

 

Edited by ivop
Link to comment
Share on other sites

24 minutes ago, ivop said:

Stephen's code, X nearing 90 degrees:

 

atari000.png.768fd06dfe461efc6243f22bcb708c78.pngatari001.png.c1172f89d8b9593a8735c792d9e63a74.png

 

Note that when X equals 90 you'll get a divide by zero error.

Right - I didn't put any error checking in, just a quick example of how to use substitution rather than defining a function.

 

I think maybe ac was wanting to do what you could in ?

 

public float tan(float x)
{
  if (x !=0)
  {
     return sin(x)/cos(x);
  }
  else
  {
      return 0;
  }
}

 

I don't think any BASIC variants on the 8-bit allow for user defined functions.  As mentioned, TBXL can do PROCS,

Link to comment
Share on other sites

1 hour ago, ivop said:

Or perhaps you mean that it doesn't result in nice images? Here's what the function looks like: (sourced and linked from britannica)

 

relationships-Tangent-curve-tangent-heig

 

Note how the values go to plus or minus infinity. 2*pi radians equals 360 degrees. pi/2 radians equals 90 degrees.

 

This is more what I'm looking for, take for example my 1st prog:

 

10 GRAPHICS 8:DEG:COLOR 1

20 FOR I=0 TO 359

30 X=COS(I)*SIZE+X_OFFSET

40 Y=SIN(I)*SIZE+Y_OFFSET

50 PLOT X,Y

60 NEXT I

 

I know what will happen with this, a circle will be drawn, but what if I change line 30 to:

 

30 X=1/COS(I)  -  (which is affectively X=SEC(I))  -  the secant (but I don't know what the secant is)

 

I'm trying to create different poly shapes or patterns (other than a circle) with some of these equations (if that's what you call them) that I don't understand.

 

Link to comment
Share on other sites

1 hour ago, ivop said:

The secant function is the reciprocal of the cosine, hence 1/cos. The secant line is a line that intersects another function/curve at at least two points.

Well, but that's not related to the definition of these functions (or barely so). Draw a circle of unit radius. Add a line with an angle of alpha to the horizonal that goes through the middle of the circle. Draw a line parallel to the horizontal that is tangential to the circle. The length of the line segment between the touching point with the circle and the intersection of the radius with angle alpha is the secant of alpha.

  • Like 1
Link to comment
Share on other sites

Before getting too mathematical, here's an example that ac might like:

 

atari000.png.a3c949078b127edadf680966b9f81074.pngatari001.png.71793225fcea7eac5ee7c88789ba8f17.png

 

It shows how to plot tan(x) by calculating sin(x)/cos(x), but only if cos(x) is non-zero. And it clips the Y value to being on screen.

 

Edit: there's a small bug. IF (B=0) you should not plot a pixel (+/- infinity), hence the double pixel at the bottom, because it replots the previous pixel.

 

Edited by ivop
  • Like 1
Link to comment
Share on other sites

4 hours ago, ac.tomo said:

I'm trying to create different poly shapes or patterns (other than a circle) with some of these equations (if that's what you call them) that I don't understand.

You don't need to understand this:

r\left(\varphi\right) = \left(         \left|                 \frac{\cos\left(\frac{m\varphi}{4}\right)}{a}         \right| ^{n_2} +         \left|                 \frac{\sin\left(\frac{m\varphi}{4}\right)}{b}         \right| ^{n_3} \right) ^{-\frac{1}{n_{1}}}.

 

...but still can have lots of fun while discovering several, astonishing shapes, by tweaking a,b,m,n1,n2 and n3:

 

Sf2d.png

 

see Superformula

 

  • Like 3
Link to comment
Share on other sites

On 6/24/2021 at 11:23 PM, Irgendwer said:

You don't need to understand this:

r\left(\varphi\right) = \left(         \left|                 \frac{\cos\left(\frac{m\varphi}{4}\right)}{a}         \right| ^{n_2} +         \left|                 \frac{\sin\left(\frac{m\varphi}{4}\right)}{b}         \right| ^{n_3} \right) ^{-\frac{1}{n_{1}}}.

 

...but still can have lots of fun while discovering several, astonishing shapes, by tweaking a,b,m,n1,n2 and n3:

 

Sf2d.png

 

see Superformula

 

This is just what I'm looking for, but how on earth would I implement that equation/formula in BASIC? I can do a bit of it, but thats about it.

Link to comment
Share on other sites

1 hour ago, ac.tomo said:

This is just what I'm looking for, but how on earth would I implement that equation/formula in BASIC? I can do a bit of it, but thats about it.

That is about it :) First calculate mφ/4 (i.e. m times angle divided by four, your outer FOR loop will run through all angles). Then calculate both the cos and sin of the result. Calculate cos result divided by a, calculate sin result divided by b. Apply abs() on both. Raise the first term to the power of n2, the second term to the power of n3, and add both together. Then calculate -1/n1. Raise your previous result to the power of the just calculated -1/n1. There's your radius with parameters a,b,m,n1,n2 and n3, at angle φ (phi).

 

Edited by ivop
Link to comment
Share on other sites

40 minutes ago, ivop said:

That is about it :) First calculate mφ/4 (i.e. m times angle divided by four, your outer FOR loop will run through all angles). Then calculate both the cos and sin of the result. Calculate cos result divided by a, calculate sin result divided by b. Apply abs() on both. Raise the first term to the power of n2, the second term to the power of n3, and add both together. Then calculate -1/n1. Raise your previous result to the power of the just calculated -1/n1. There's your radius with parameters a,b,m,n1,n2 and n3, at angle φ (phi).

 

 

Ok, are you ready for a laugh! Here's what I think the formula converts to (in BASIC style):

 

r(phi)=(ABS((COS(m*phi)/4)/a)~n2+ABS((SIN(m*phi)/4)/b))~-1/n1

 

Would that be about right? I assume the 'phi' in r(phi) is omitted when entered in BASIC?

Link to comment
Share on other sites

Your parenthesis are off. Now you take the cosine of m*phi, and then divide by 4, and divde by a. Similar to the sinus part.

 

FOR phi loop full circle

 

     radius = ( ( ABS( COS(m*phi/4) / a ) ~n2) + ( ABS( SIN(m*phi/4) / b ) ~n3) ) ~ (-1/n1)

 

edit: I used your notation for to-the-power-of n (~n). It should be ^ in Atari Basic.

Edited by ivop
Link to comment
Share on other sites

4 hours ago, ivop said:

Your parenthesis are off. Now you take the cosine of m*phi, and then divide by 4, and divde by a. Similar to the sinus part.

 

FOR phi loop full circle

 

     radius = ( ( ABS( COS(m*phi/4) / a ) ~n2) + ( ABS( SIN(m*phi/4) / b ) ~n3) ) ~ (-1/n1)

 

edit: I used your notation for to-the-power-of n (~n). It should be ^ in Atari Basic.

Many thanks for that, I think thats the 1st time I've ever done a conversion like that, I'm too busy tomorrow, but will be trying it out soon, thanks again.

Link to comment
Share on other sites

45 minutes ago, ac.tomo said:

Many thanks for that, I think thats the 1st time I've ever done a conversion like that, I'm too busy tomorrow, but will be trying it out soon, thanks again.

It is possible in less than a screen full of Atari Basic. It is pretty slow though. I won't ruin your journey to finding out how it works by publishing the source. Just some images:

 

atari001.png.3e169a31a1847e492aa365b182d0075f.png  atari002.png.3758480475ebd83f5df89ee648907e8a.png  atari004.png.2d5a40d5d0361980a3140ae45d10e98e.png

 

Note that a and b are scale factors. Better keep them equal, and equal to one (1), and use the scale factor below to keep the points within the drawing area. Sadly, plot and drawto don't clip automatically.

 

Polar coordinates (radius, angle) to cartesian (x,y) is done by:

 

x = scale * calculated_radius * cos(angle) + centerpoint_x

y = scale * calculated_radius * sin(angle) + centerpoint_y

 

Have fun! :)

 

Edited by ivop
  • Like 3
Link to comment
Share on other sites

Yep, it's the circumflex (^).

 

Note that when you keep a and b equal to 1, you can remove them from the equation. Dividing by 1 is useless, but Atari Basic will happily do it for you ;)

 

Use the scale factor to keep your plotted or drawn-to pixel within the visibile area.

 

Final tip, at first use a step size in your outer loop and try a simple shape, like the square, triangle or circle. FOR PHI=0 to 359 STEP 4, and if it looks good, go down to 3, 2, or even 1.

 

Edit: the numbers on the 2D plot on Wikipedia refer to m, n1, n2 and n3. 3,4.5,10,10 is the sort-of triangle, 2,2,2,2 is a circle, et cetera. Be prepared to change the scale factor each time you change shape. Basic will error out with Error Code 141: Cursor Out of Range :) My sample images used a STEP size of 2.

 

atari000.png.a7aee13ac546b1d6ddd42998456cc3e5.png  atari001.png.d4f37e85b1aed0ba30699832fe6e503b.png

Edited by ivop
Link to comment
Share on other sites

On 7/2/2021 at 6:56 PM, ivop said:

Yep, it's the circumflex (^).

 

Note that when you keep a and b equal to 1, you can remove them from the equation. Dividing by 1 is useless, but Atari Basic will happily do it for you ;)

 

Use the scale factor to keep your plotted or drawn-to pixel within the visibile area.

 

Final tip, at first use a step size in your outer loop and try a simple shape, like the square, triangle or circle. FOR PHI=0 to 359 STEP 4, and if it looks good, go down to 3, 2, or even 1.

 

Edit: the numbers on the 2D plot on Wikipedia refer to m, n1, n2 and n3. 3,4.5,10,10 is the sort-of triangle, 2,2,2,2 is a circle, et cetera. Be prepared to change the scale factor each time you change shape. Basic will error out with Error Code 141: Cursor Out of Range :) My sample images used a STEP size of 2.

 

atari000.png.a7aee13ac546b1d6ddd42998456cc3e5.png  atari001.png.d4f37e85b1aed0ba30699832fe6e503b.png

Many thanks for that ivop. I think I'll be looking for more help from you when I decide to try to understand algorythms (mainly for) rotating 3d solid objects. I've got a couple of programs to rotate 3d wire graphics. This is another subject I don't understand but want to (the algorythms to do the filling).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

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