PEF524 Posted February 1, 2007 Share Posted February 1, 2007 hey... im trying to make a loop using all of the degrees 0-360 and displaying with the Sine of each of those is EX) Angle Sin 0 0 1 .01745 2 .0349 etc etc ... this is what im doing and it is not working, can anyone help? <?php $sin=sin($i); $i=deg2rad($i); for($i=0; $i<=360; $i=$i+1) echo "$sin"; ?> thanks! Link to comment https://forums.phpfreaks.com/topic/36585-solved-for-loops-and-sin/ Share on other sites More sharing options...
Jessica Posted February 1, 2007 Share Posted February 1, 2007 <?php for($i=0; $i<=360; $i=$i+1) $d=deg2rad($i); $sin=sin($d); echo "$sin"; ?> You have some things backwards, try that? Link to comment https://forums.phpfreaks.com/topic/36585-solved-for-loops-and-sin/#findComment-174241 Share on other sites More sharing options...
PEF524 Posted February 1, 2007 Author Share Posted February 1, 2007 ugh... thanks but that didn't work for me for whatever reason its not looping through all of the degrees for the code you gave me it just said "-2.44921270764E-16" I'll keep playing around with it Link to comment https://forums.phpfreaks.com/topic/36585-solved-for-loops-and-sin/#findComment-174251 Share on other sites More sharing options...
Jessica Posted February 1, 2007 Share Posted February 1, 2007 try starting at 1 instead of 0? Link to comment https://forums.phpfreaks.com/topic/36585-solved-for-loops-and-sin/#findComment-174253 Share on other sites More sharing options...
PEF524 Posted February 1, 2007 Author Share Posted February 1, 2007 still no luck, even with changing 0 to 1 i basically just want a list of all the sines of all the angles without having to write out the sin() function for each one... anyone else have any ideas? ??? Link to comment https://forums.phpfreaks.com/topic/36585-solved-for-loops-and-sin/#findComment-174276 Share on other sites More sharing options...
Jessica Posted February 1, 2007 Share Posted February 1, 2007 What happens if you just do: print sin(deg2rad(1)); Does that work? The sin of 1 degree, is very small, right, it's almost 0, yeah? (or is that cos?) So it should print a very small number. You may have to format it in order to get it to look right. Link to comment https://forums.phpfreaks.com/topic/36585-solved-for-loops-and-sin/#findComment-174279 Share on other sites More sharing options...
dgiberson Posted February 1, 2007 Share Posted February 1, 2007 echo "<table><tr><td>Angle</td><td>Sin(x)</td></tr>"; for ($i=0;$i<=360;$i++) { $d = deg2rad($i); $sin = sin($d); echo "<tr><td>$i</td><td>$sin</td></tr>"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/36585-solved-for-loops-and-sin/#findComment-174284 Share on other sites More sharing options...
PEF524 Posted February 1, 2007 Author Share Posted February 1, 2007 thanks dgiberson and jesirose, got it Link to comment https://forums.phpfreaks.com/topic/36585-solved-for-loops-and-sin/#findComment-174305 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.