Mercurial > hg > jslab
annotate src/samer/maths/Constant.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
rev | line source |
---|---|
samer@0 | 1 /* |
samer@0 | 2 * Copyright (c) 2000, Samer Abdallah, King's College London. |
samer@0 | 3 * All rights reserved. |
samer@0 | 4 * |
samer@0 | 5 * This software is provided AS iS and WITHOUT ANY WARRANTY; |
samer@0 | 6 * without even the implied warranty of MERCHANTABILITY or |
samer@0 | 7 * FITNESS FOR A PARTICULAR PURPOSE. |
samer@0 | 8 */ |
samer@0 | 9 |
samer@0 | 10 package samer.maths; |
samer@0 | 11 import samer.core.*; |
samer@0 | 12 |
samer@0 | 13 public class Constant extends Function implements Generator |
samer@0 | 14 { |
samer@0 | 15 double k; |
samer@0 | 16 |
samer@0 | 17 public Constant() { k=Shell.getInt("constant",1); } |
samer@0 | 18 public Constant(double k) { this.k=k; } |
samer@0 | 19 public void dispose() {} |
samer@0 | 20 |
samer@0 | 21 // Generator |
samer@0 | 22 public double next() { return k; } |
samer@0 | 23 public void next(double [] x) { for (int i=0; i<x.length; i++) x[i]=k; } |
samer@0 | 24 |
samer@0 | 25 // Function |
samer@0 | 26 public double apply(double t) { return k; } |
samer@0 | 27 public Function derivative() { return new Zero(); } |
samer@0 | 28 |
samer@0 | 29 public String toString() { return "Constant("+k+")"; } |
samer@0 | 30 public String format(String arg) { return X.string(k); } |
samer@0 | 31 } |