
22.12.2009, 00:06
|
|
Познающий
Регистрация: 09.11.2009
Сообщений: 30
С нами:
8685853
Репутация:
26
|
|
Сообщение от AFoST
Есть ли на php класс для работы с комплесными числами?
или нужна замена метода imag из класса complex для с++.
На phpclasses нашел такой:
PHP код:
<?
define('Z_CARTESIAN', 0);
define('Z_POLAR', 1);
define('Z_RADIAN', 0);
define('Z_DEGREE', 1);
class Z{
// Constructor
function Z($var = "", $im = "", $type = Z_CARTESIAN, $unit = Z_RADIAN ){
if( $unit ){
$this->unit = $unit;
}
list( $this->x, $this->y ) = $this->parse( func_get_args() );
}
// Public Functions
function SetUnit($unit = Z_RADIAN){
$this->unit = $unit;
return $this->unit;
}
function Re(){
return $this->x;
}
function Im(){
return $this->y;
}
function Mod(){
return hypot( $this->x, $this->y );
}
function Arg(){
if( $this->unit ){
return rad2deg( atan( $this->y / $this->x ) );
}
else{
return atan( $this->y / $this->x );
}
}
# For the following 4-op functions, input vars is same as constructor function.
function Add(){
list( $x, $y ) = $this->parse( func_get_args() );
$this->x+= $x;
$this->y+= $y;
}
function Sub(){
list( $x, $y ) = $this->parse( func_get_args() );
$this->x-= $x;
$this->y-= $y;
}
function Mul(){
list( $x, $y ) = $this->parse( func_get_args() );
list( $mod, $arg ) = $this->ToPolar( $x, $y );
list( $this->x, $this->y ) = $this->ToCartesian( $this->Mod()*$mod, $this->Arg()+$arg );
}
function Div(){
list( $x, $y ) = $this->parse( func_get_args() );
list( $mod, $arg ) = $this->ToPolar( $x, $y );
list( $this->x, $this->y ) = $this->ToCartesian( $this->Mod()/$mod, $this->Arg()-$arg );
}
// Private functions
function parse( $arr ){
list ($var, $im, $type, $unit ) = $arr;
if( $var ){
if( $im ){
if( $type == Z_POLAR ){
if( stristr( $im, "d" ) || ( ($unit == Z_DEGREE) && (!stristr( $im, "d" )) ) ){
$im = deg2rad( $im );
}
list( $x, $y ) = $this->ToCartesian( $var, $im );
}
else{
$x = $var;
$y = $im;
}
}
else{
list( $x, $y ) = $this->parse_number( $var );
}
}
return array( $x, $y );
}
function parse_number($str){
$str = preg_replace("/\s*/","",$str);
if( preg_match("/(?i)[^erd\-+ij.,0-9]+/", $str) ){
return -1;
}
else{
if( stristr( $str, "e" ) ){
preg_match("/(?i)([0-9]+)e-[ij]?([0-9rd]+)[ij]?/", $str, $arr);
if( sizeof( $arr ) ){
if( stristr( $arr[2], "d" ) ){
$arr[2] = deg2rad( $arr[2] );
}
list( $re, $im ) = $this->ToCartesian( $arr[1], $arr[2] );
}
}
else{
preg_match_all( "/(?i)([\-+]?[0-9.,ij]+)/", $str, $arr, PREG_SET_ORDER );
if( sizeof( $arr ) ){
foreach( $arr as $number ){
if( preg_match( "/(?i)[ij]/", $number[1] ) ){
$im += $number[1];
}
else{
$re += $number[1];
}
}
}
}
return array($re, $im);
}
}
function ToCartesian( $mod, $ang ){
return array( ( $mod*cos($ang) ), ( $mod*sin($ang) ) );
}
function ToPolar( $re, $im ){
return array( hypot( $re, $im ) , atan( ($im/$re) ) );
}
}
?>
Последний раз редактировалось TDKronuS; 22.12.2009 в 00:08..
|
|
|

22.12.2009, 07:56
|
|
Познавший АНТИЧАТ
Регистрация: 27.04.2007
Сообщений: 1,044
С нами:
10021597
Репутация:
905
|
|
Код:
perldoc Math::Complex ))
|
|
|

22.12.2009, 15:04
|
|
Познающий
Регистрация: 05.05.2008
Сообщений: 43
С нами:
9482319
Репутация:
2
|
|
Подскажите скриптик, отправляю из проги пост запрос с содержанием например 'info=12345' нужно чтоб скрипт сохранил данный текст в файл
|
|
|

22.12.2009, 15:43
|
|
Познающий
Регистрация: 12.09.2009
Сообщений: 61
С нами:
8769340
Репутация:
19
|
|
Сообщение от akahaos
Подскажите скриптик, отправляю из проги пост запрос с содержанием например 'info=12345' нужно чтоб скрипт сохранил данный текст в файл
PHP код:
$site='fbi.ru';
$patch='new.php';
$dat='?info=1234';
$fp = fsockopen($site, 80);
fputs($fp,'POST '.$patch.' HTTP/1.1
Host: '.$site.'
Connection: close
Content-Length: '.strlen($dat).'
'.$dat);
$f='';
while (!feof($fp)) $f.=fgets($fp, 1000);
fclose($fp);
file_put_contents('file.txt',$f);
php 5<=
|
|
|

22.12.2009, 15:17
|
|
Познавший АНТИЧАТ
Регистрация: 12.03.2008
Сообщений: 1,379
С нами:
9560486
Репутация:
1809
|
|
Помогите с str_replace()
Есть строка и массив:
'1', '2', '3', '4'
Array ( [0] => 2 [1] => 4 )
нужно удалить и строчки '2', и '4'
получиться должно: '1', '3'

|
|
|

22.12.2009, 15:24
|
|
Он хакер.
Регистрация: 01.11.2008
Сообщений: 1,756
С нами:
9223466
Репутация:
3171
|
|
Сообщение от mff
Есть строка и массив:
'1', '2', '3', '4'
Array ( [0] => 2 [1] => 4 )
нужно удалить и строчки '2', и '4'
получиться должно: '1', '3'

in_array()?+explode
|
|
|

22.12.2009, 15:27
|
|
Познавший АНТИЧАТ
Регистрация: 12.03.2008
Сообщений: 1,379
С нами:
9560486
Репутация:
1809
|
|
Сообщение от m0Hze
in_array()?+explode
не совсем понятно  можно примерчик? спасибо!
|
|
|

22.12.2009, 15:38
|
|
Познающий
Регистрация: 12.09.2009
Сообщений: 61
С нами:
8769340
Репутация:
19
|
|
Сообщение от mff
не совсем понятно  можно примерчик? спасибо!
PHP код:
$str='1,2,3,4';
$del=array(2,4);
$str=str_replace($del,'',$str);
$str=str_replace(',,',',',$str);
$arr=explode(',',$str);
|
|
|

22.12.2009, 15:51
|
|
Познавший АНТИЧАТ
Регистрация: 12.03.2008
Сообщений: 1,379
С нами:
9560486
Репутация:
1809
|
|
Сообщение от Eo0
PHP код:
$str='1,2,3,4';
$del=array(2,4);
$str=str_replace($del,'',$str);
$str=str_replace(',,',',',$str);
$arr=explode(',',$str);
стоп, задача упростилась, вот:
$str = "1,2,3,4";
массив = Array ( [0] => 2 [1] => 4 )
получиться должно:
$str="1,3";
Последний раз редактировалось mff; 22.12.2009 в 15:59..
|
|
|

22.12.2009, 16:27
|
|
Познающий
Регистрация: 05.05.2008
Сообщений: 43
С нами:
9482319
Репутация:
2
|
|
Eo0, не срабатывает(
|
|
|
|
 |
|
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|