-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEquation.pd
More file actions
43 lines (32 loc) · 1.22 KB
/
Equation.pd
File metadata and controls
43 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//*******************************************************
//* File: C:/Users/User/Desktop/Third Year Project/CollisionAvoidanceSystem/QuadraticEquation.pd
//* Author: Varuna
//* Created: 15:02:04 on Monday March 9th 2015 UTC
//*******************************************************
class Equation ^=
abstract
var a : real;
var b : real;
var c : real;
interface
function getXForMinimumValue : real
^= (let derivative ^= differentiateWRTx;
((derivative.c * -1.0) / derivative.b));
function solve : real
^= (let toBeRoot ^= (b*b)-(4*a*c);
([toBeRoot < 0.0] : 100000.0,
[] : (let r1 ^= ((-1.0*b) + ((toBeRoot)^(0.5)))/(2*a);
let r2 ^= ((-1.0*b) - ((toBeRoot)^(0.5)))/(2*a);
([r1 > 0.0 & r1 <= r2]: r1,
[r2 > 0.0 & r2 < r1] : r2,
[] : 100000.0))));
function differentiateWRTx : Equation
^= Equation{0.0, 2.0 * a, b};
operator +(other : Equation) : Equation
^= Equation{a + other.a, b + other.b, c + other.c};
operator - (other : Equation) : Equation
^= Equation{a - other.a, b - other.b, c - other.c};
redefine function toString : string
^= "\n(" ++ a.toString ++ ") x^2 + (" ++ b.toString ++ ") x + (" ++ c.toString ++")";
build{!a : real, !b : real, !c : real};
end;