Page 1 of 2

Back on the math ( slightly different focus)

Posted: Mon Oct 03, 2005 5:38 pm
by Charles256
So have you ever been thinking.. man I need to calculate the distance between two points...how am I going to code that? Granted, I am over simplifying but do tell me what things you have tried to accomplish mathemtically in PHP or things that you weren't even able to but wanetd to. Let me know! I plan on beginning work on a math library for PHP . Since my main area of study right now is calculus and linear algebra I will probably start on htat front first but if anybody has some pressing needs or desires then let me know and I'll start work on those first. :-D

Posted: Mon Oct 03, 2005 5:41 pm
by feyd
I'd like to see a ROAM engine in PHP. :)

Posted: Mon Oct 03, 2005 5:49 pm
by Chris Corbyn
Calculating the position of the sun (very very accuratley) based on geographical location, and time of year (to the second).... OUCH... I haven't done maths since A-Level (16-18 yo) but it was good fun to work on... and immensely complex - no kidding this was full-on hard-core maths I didn;t know anything about to start with. Other than that one-off project it's only been vaguely technical maths that I do all the time in programming with *fairly* poor mental arithmetic skills.... but hey... what are calculators for? :P

Posted: Mon Oct 03, 2005 7:00 pm
by Weirdan
knapsack problem is what was absorbing me for a week. Finally I gave up and wrote a bruteforce implementation, shame! :)

Posted: Mon Oct 03, 2005 7:07 pm
by Charles256
the knapsack problem? do i really need to tell people to explain what they were trying to accomplish:-D

Posted: Mon Oct 03, 2005 8:06 pm
by sweatje

Code: Select all

class Point {
	var $x;
	var $y;
	function Point($x, $y) {
		$this->x = $x;
		$this->y = $y;
	}
	function dist($p) {
		return sqrt(pow($this->x - $p->x,2)+pow($this->y - $p->y,2));
	}
	function show() {
		return '('.$this->x.','.$this->y.')';
	}
}

Posted: Mon Oct 03, 2005 8:07 pm
by Charles256
lol,is that your contribution or you making fun of my simple example?:-D

Posted: Mon Oct 03, 2005 8:14 pm
by sweatje
Well you asked "man I need to calculate the distance between two points...how am I going to code that? " That would be my answer, write a class to encapsulate "pointness", create two instances of Point, and ask one how far it is from the other.

I had this point class lying around as a example for some reason. Even have a test case:

Code: Select all

class PointTestCase extends UnitTestCase {
	function TestPointDistance() {
		$p1 = new Point(1,1);
		$p2 = new Point(2,2);
		$p3 = new Point(1,3);
		
		$this->assertEqual(sqrt(2), $p1->dist($p2));
		$this->assertEqual(2, $p1->dist($p3));
	}
}

Posted: Mon Oct 03, 2005 8:16 pm
by Charles256
go back and read my entire first sentence... i ithnk you mis-understood me:-D

Posted: Mon Oct 03, 2005 8:18 pm
by sweatje
I guess I could use MatLab in PHP if you are bored ;)

Posted: Mon Oct 03, 2005 8:21 pm
by Charles256
heh.yep part of this is to spite matlab...my taecher thinks it's awsome and unique....i have the urge to spite him:-D

Posted: Mon Oct 03, 2005 10:03 pm
by Ambush Commander
Hmm... that reminds me... wouldn't it be cool if someone wrote a wrapper library for PHP to interface Mathematica? Just a thought.

Posted: Tue Oct 04, 2005 1:09 am
by pilau
I heared there was a most professional math program that costs about 1200$.

Posted: Tue Oct 04, 2005 7:40 am
by Maugrim_The_Reaper
I think what Charles is trying to say is that he'd like to know what sort of problems with Maths people are having ;) Simple geometry is a given in any math's library, but are there any other areas of interest to folk?

Personally I think we need:

a) a maths book
b) an OOP structure
c) get kicking.

If we keep the classes small and tight, should be able to keep things organised as we move along to establishing an interface into the library.

Posted: Tue Oct 04, 2005 7:54 am
by Charles256
a maths book??