Mercurial > hg > jslab
view src/samer/functions/Quadratic.java @ 5:b67a33c44de7
Remove some crap, etc
author | samer |
---|---|
date | Fri, 05 Apr 2019 21:34:25 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
/* * Copyright (c) 2000, Samer Abdallah, King's College London. * All rights reserved. * * This software is provided AS iS and WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ package samer.functions; import samer.maths.*; import samer.core.*; public class Quadratic extends Function { double a, b, c; public Quadratic(double a, double b, double c) { this.a = a; this.b = b; this.c = c; } public double apply(double t) { return c+t*(b+a*t); } public String format(String arg) { StringBuffer buf=new StringBuffer(); boolean f=false; if (c!=0) { buf.append(X.string(c)); } if (b!=0 || b<0) { if (f) { buf.append(b>0 ? " + " : " - "); f=true; } if (b==1 || b==-1) buf.append(arg); else buf.append(X.string(Math.abs(b))).append(arg); } if (a!=0) { if (f || a<0) { buf.append(a>0 ? " + " : " - "); f=true; } if (a==1 || a==-1) buf.append(arg+"^2"); else buf.append(X.string(Math.abs(b))).append(arg+"^2"); } return buf.toString(); } public Function derivative() { return new Linear(2*a,b); } }