Back on the math ( slightly different focus)

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Back on the math ( slightly different focus)

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd like to see a ROAM engine in PHP. :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

knapsack problem is what was absorbing me for a week. Finally I gave up and wrote a bruteforce implementation, shame! :)
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

the knapsack problem? do i really need to tell people to explain what they were trying to accomplish:-D
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post 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.')';
	}
}
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

lol,is that your contribution or you making fun of my simple example?:-D
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post 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));
	}
}
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

go back and read my entire first sentence... i ithnk you mis-understood me:-D
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

I guess I could use MatLab in PHP if you are bored ;)
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

I heared there was a most professional math program that costs about 1200$.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

a maths book??
Post Reply