openSUSE Forums > Programming/Scripting » Math formula (sin)

Go Back   openSUSE Forums > Programming/Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read


Programming/Scripting Questions about programming, bash scripts, perl, php, cron jobs, ruby, python, etc.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 22-Oct-2009, 03:33
mmarif4u's Avatar
Parent Penguin
 
Join Date: Jun 2008
Location: /dev/swat
Posts: 710
mmarif4u hasn't been rated much yet
Default Math formula (sin)

Hi,
I am working on a PHP/MySQL script where i need to apply a math formula.
Code:
sin(a) = m(V - b)
Here m and b are static values, which i already have, V is coming from a sensor live, so i need to calculate 'a' here.
something like:
Code:
a = sin(m(V - b))
But i am not sure, that how to move sin to other side and leave just 'a' on the left side.

Any ideas about this math formula.
Thanks.
__________________
Visit my website: http://anl4u.com
Laptop: openSUSE 11.2 | KDE4.3.1 '6' | Kernel 2.6.31.5 | Intel Mobile 4 series graphic card | Intel centrino dual core 2.0Ghz Processor | 4GB RAM | 320GB HDD
Reply With Quote
  #2 (permalink)  
Old 22-Oct-2009, 03:45
Wise Penguin
 
Join Date: Jun 2008
Location: NZ
Posts: 1,848
deano_ferrari has a spectacular reputation aura aboutdeano_ferrari has a spectacular reputation aura aboutdeano_ferrari has a spectacular reputation aura aboutdeano_ferrari has a spectacular reputation aura about
Default Re: Math formula (sin)

From memory, I think you want the arcsine function:

a=asin(m(V - b))
Reply With Quote
  #3 (permalink)  
Old 22-Oct-2009, 04:01
mmarif4u's Avatar
Parent Penguin
 
Join Date: Jun 2008
Location: /dev/swat
Posts: 710
mmarif4u hasn't been rated much yet
Default Re: Math formula (sin)

Thanks.
As i did like this way, which i know is wrong somehow.
Code:
$a_x = sin(0.062763 * ($ch410 - (-0.19564)));
$a_y = sin(0.062763 * ($ch411 - (-0.19564)));
The above give the output:

Quote:
x: 2.52651224568
y: -1.27401076136
Now if i put the asin function:
Code:
$a_x = asin(0.062763 * ($ch410 - (-0.19564)));
$a_y = asin(0.062763 * ($ch411 - (-0.19564)));
The output is:
Quote:
x: 2.55217155313
y: -1.27724895412
Which is also wrong. The output in this case would be:
Quote:
x = 10
y = -5
In this case V is, which is $ch410 and $ch411:
Quote:
x: 2.570
y: -1.585
I am sure, before putting the values in the formula, have to simply the formula 1st, then put values, but the hard part is that for me, to simply the formula 1st.

Any ideas?
__________________
Visit my website: http://anl4u.com
Laptop: openSUSE 11.2 | KDE4.3.1 '6' | Kernel 2.6.31.5 | Intel Mobile 4 series graphic card | Intel centrino dual core 2.0Ghz Processor | 4GB RAM | 320GB HDD

Last edited by mmarif4u; 22-Oct-2009 at 04:03. Reason: Adding..
Reply With Quote
  #4 (permalink)  
Old 22-Oct-2009, 05:34
Flux Capacitor Penguin
 
Join Date: Jun 2008
Location: GMT+10
Posts: 5,222
ken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud of
Default Re: Math formula (sin)

Remember that these trig functions usually expect input and generate output in radians, not degrees.
Reply With Quote
  #5 (permalink)  
Old 22-Oct-2009, 07:50
weighty_foe's Avatar
Explorer Penguin
 
Join Date: Sep 2008
Location: Earl Shilton UK
Posts: 100
weighty_foe hasn't been rated much yet
Default Re: Math formula (sin)

Agree with ken_yap. It's arcsine (sin^-1) you need - working here:

a = sin(m(V - b))

sin^-1 (a) = sin^-1 (sin(m(V-b)))

sin^-1 (a) = m(V-b)

And yeah, you need to use radians, not degrees. Convert degrees to radians like this:

radians = degrees * (pi/180).

I'd use the math constant pi in php rather than use an approximation.
__________________
Happily using Linux since 1998
Share & Enjoy
Reply With Quote
  #6 (permalink)  
Old 22-Oct-2009, 09:56
mmarif4u's Avatar
Parent Penguin
 
Join Date: Jun 2008
Location: /dev/swat
Posts: 710
mmarif4u hasn't been rated much yet
Default Re: Math formula (sin)

Thanks guys for all your support and help.
That rad2deg did the job.

PHP Code:
$a_x asin($m * ($ch410 $b));
$a_y asin($m * ($ch411 $b));

echo 
rad2deg($a_x).'<br />';
echo 
rad2deg($a_y).'<br />'
Thanks again Kenyap and weighty_foe and deano_ferrari.
__________________
Visit my website: http://anl4u.com
Laptop: openSUSE 11.2 | KDE4.3.1 '6' | Kernel 2.6.31.5 | Intel Mobile 4 series graphic card | Intel centrino dual core 2.0Ghz Processor | 4GB RAM | 320GB HDD
Reply With Quote
Reply

Bookmarks


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2