how do I get the square root of a number?

Posted By: sadsack

how do I get the square root of a number? - 12/07/10 00:32

I am trying to make a small program the gives the freq. of a tuned Circuit. I looked in the manual under math and could not find anything about using square root .
Thank you
renny
Posted By: Superku

Re: how do I get the square root of a number? - 12/07/10 00:38

sqrt(x)
Posted By: sadsack

Re: how do I get the square root of a number? - 12/07/10 01:03


this is what I came up with so far. I dod not have any input code yet.

Code:
////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
#define PI 3.14159

int f = 0;

int l = .00000012;
int c = .0000000000020;
/////////////////////////////////////////////////////////////////////

PANEL* panDisplay =
{
	digits(35, 10, "f = %0.f", *, 1,f);

	digits(35, 28, "l = %0.f", *, 1, l);
	digits(35, 38, "c = %0.f", *, 1, c);
	flags = SHOW;
}

/////////////////////////////////////////////////////////////////////

function main()
{
  screen_size.x = 800;
  screen_size.y = 600;
	screen_color.blue = 150; // and make its background dark blue
	while (1)
	{
		f = 1/ 2*PI * sqrt(l*c)		
		
		wait (1);
	}
}



It will not compile and does not give me an error.
renny
Posted By: Superku

Re: how do I get the square root of a number? - 12/07/10 01:11

Uh what are you doing there?

var l = .00000012;
var c = .0000000000020;

var-accuracy ends with .001, you should use double variables.

You output the wrong variables (what's a,b?).

Code:
f = 2*pi sqrt(L*c)/1



You have defined PI, not pi.
There is no operator between pi and sqrt.
Again, what is L? (lite-C is case-sensitive).
(Dividing by 1 is not so helpful, but I guess you know that. wink )
There is no semicolon.
Posted By: sadsack

Re: how do I get the square root of a number? - 12/07/10 01:14

I know, I fixed most of that stuff I going have to do the PI
Posted By: sadsack

Re: how do I get the square root of a number? - 12/07/10 01:32

To find the freq of a tuned tank you need to know this
l = is the coil in henry
c = is the capacitor in farad
f = freq

f=2*PI*sqrt*(lc)/1

so let say the l is .00000012 henrys
and c is .000000000029 farads
very simple, but not so easy when you trying to make the computer do it.
renny
Posted By: sadsack

Re: how do I get the square root of a number? - 12/07/10 01:36

New code still will not compile????


Code:
////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
#define PI 3.14159

int f = 0;

int l = .00000012;
int c = .0000000000020;
/////////////////////////////////////////////////////////////////////

PANEL* panDisplay =
{
	digits(35, 10, "f = %0.f", *, 1,f);

	digits(35, 28, "l = %0.f", *, 1, l);
	digits(35, 38, "c = %0.f", *, 1, c);
	flags = SHOW;
}

/////////////////////////////////////////////////////////////////////

function main()
{
  screen_size.x = 800;
  screen_size.y = 600;
	screen_color.blue = 150; // and make its background dark blue
	while (1)
	{
		f = 2*PI * sqrt*(l*c)/1
		
		
		wait (1);
	}
}


Thank you for your help I still don't know what I am doing wrong.
renny
Posted By: Redeemer

Re: how do I get the square root of a number? - 12/07/10 02:08

There are multiple problems with this statement:
Code:
f = 2*PI * sqrt*(l*c)/1



Starting from the left of the statement:
(1) "f" is an int and thus will only record whole numbers (1, 2, 3, 4, etc.)
(2) You are not giving any input to the sqrt function, instead you are trying to multiply it by something(?)
(3) You have assigned "l" and "c" fractional values, but they are int variables so they have not recorded them. "(l*c)" will produce 0.
(4) You are dividing the results of the previous quotient by 1, but dividing *anything* by 1 will yield the original number. x/1 = x
(5) There is no semicolon at the end of the line.

I think what you mean to write is:
Code:
f = 2*PI * sqrt(l*c);



You should also change the variable definitions to:
Code:
double f, c, l;


Posted By: sadsack

Re: how do I get the square root of a number? - 12/07/10 17:06

ok new code, still will not compile. I need to make it compile befor I can start working on the math.


Code:
#include <acknex.h>
#include <default.c>
#define PI 3.14159

double f = 0;

double C = .000000000020;
double L = .0000000000020;
/////////////////////////////////////////////////////////////////////

PANEL* panDisplay =
{
	digits(35, 10, "f = %0.f", *, 1,f);

	digits(35, 28, "l = %0.f", *, 1, l);
	digits(35, 38, "c = %0.f", *, 1, c);
	flags = SHOW;
}

/////////////////////////////////////////////////////////////////////

function main()
{
  screen_size.x = 800;
  screen_size.y = 600;
	screen_color.blue = 150; // and make its background dark blue
	while (1)
	{
		f = 1/ 2*PI*sqrt(L*C);
         
         wait (1);
   }
}


Why will this code not compile?
renny
Posted By: Rei_Ayanami

Re: how do I get the square root of a number? - 12/07/10 18:37

Lite-C is case sensetive!

l != L
Posted By: sadsack

Re: how do I get the square root of a number? - 12/07/10 19:09

Yes I know when i seen that I made the change to LC. It still will not compile,
I need to make it compile befor I can work on getting to work right.
Posted By: Rei_Ayanami

Re: how do I get the square root of a number? - 12/07/10 19:28

WTF?

I tried to compile it, and I just needed to change the L to l and the C to c...
Posted By: sadsack

Re: how do I get the square root of a number? - 12/07/10 20:05

I did and it still does not compile.



Code:
#include <acknex.h>
#include <default.c>
#include <cmath>

#define PI 3.14159;

double f = 0;

double L = .00000012;
double C = .0000000000020;
/////////////////////////////////////////////////////////////////////

PANEL* panDisplay =
{
	digits(35, 10, "f = %0.f", *, 1,f);

	digits(35, 28, "L = %0.f", *, 1, L);
	digits(35, 38, "C = %0.f", *, 1, C);
	flags = SHOW;
}

/////////////////////////////////////////////////////////////////////

function main()
{
  screen_size.x = 800;
  screen_size.y = 600;
	screen_color.blue = 150; // and make its background dark blue
	while (1)
	{
		f = 1/ 2*PI*sqrt(L*C);
         
         wait (1);
   }
}




I can't find anything wrong with it, it should compile.
Posted By: Rei_Ayanami

Re: how do I get the square root of a number? - 12/07/10 20:08

what the heck is cmath?

And why you put a ";" after the pi definitioN?
Posted By: sadsack

Re: how do I get the square root of a number? - 12/07/10 21:45

having ";" or not having makes it compile. I can see no one so far know why it does not compile.
Posted By: sadsack

Re: how do I get the square root of a number? - 12/07/10 22:07

Ok I got it to compile here the code:


Code:
////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>

#define PI 3.14159

double f = 0;
double L = .00000012;
double C = .000000000020;

/////////////////////////////////////////////////////////////////////

PANEL* panDisplay =
{
	digits(35, 10, "f = %0.f", *, 1, f);
	digits(35, 19, "L = %0.f", *, 1, L);
	digits(35, 28, "C = %0.f", *, 1, C);
	flags = SHOW;
}

/////////////////////////////////////////////////////////////////////

function main()
{
  screen_size.x = 800;
  screen_size.y = 600;
	screen_color.blue = 150; // and make its background dark blue
	while (1)
	{
		f = 1 / 2*PI * sqrt(C*L) ;
		wait (1);
	}
}



But I still get 0 for L C f.
Posted By: Pappenheimer

Re: how do I get the square root of a number? - 12/07/10 22:14

From the manual:
Quote:
!! #define lines normally don't end with a semicolon, unless you want value to end with a semicolon for some reason. Some PRAGMA defines (see below) require a semicolon for ending a text string.


this means that '#define PI 3.14;' includes the semicolon within the equation in which you use PI, so the compiler reads the semicolon in the middle of the equation, where it 'cuts' the equation into two pieces - which are getting almost always senseless this way.
Posted By: sadsack

Re: how do I get the square root of a number? - 12/07/10 22:32

Here is the formual for finding the frq of a tuned tank




I don't know If I am puting the formual in the code right.

Thank You Pappenheimer
Posted By: Superku

Re: how do I get the square root of a number? - 12/07/10 22:40

Quote:
I don't know If I am puting the formual in the code right.

No, sorry. Your square root multiplies with the numerator.
Write instead:

f = 1 / (2*PI * sqrt(C*L));
Posted By: sadsack

Re: how do I get the square root of a number? - 12/08/10 00:13

Thank you superku it works not I must test it it come up with the right numbers.
renny
© 2024 lite-C Forums