Skip to content

Instantly share code, notes, and snippets.

@joakiti
Created September 20, 2016 20:16
Show Gist options
  • Save joakiti/b8f342628cf77e4369ab0ce0571d3a30 to your computer and use it in GitHub Desktop.
Save joakiti/b8f342628cf77e4369ab0ce0571d3a30 to your computer and use it in GitHub Desktop.
hejhejhej
public class Polynomial
{
double[] cs;
int typeLigning;
public Polynomial(double[] cs) {
this.cs = cs;
typeLigning = cs.length - 1;
}
public void show() {
System.out.println("Du har valgt en " + typeLigning + " grads ligning");
}
public void sjovmetode() {
int a = cs.length-1;
for ( int i = 0; i < cs.length; i++ ) {
if (i == 0) {
System.out.print(cs[i] + "+");
}
else if ( i == a ) {
System.out.print(cs[i] + "x^" + i);
}
else
{
System.out.print(cs[i] + "x^" + i + "+");
}
}
}
public double compute(double x) {
double sum = 0;
for ( int i = 0; i < cs.length; i++) {
sum += cs[i]* Math.pow(x,i);
}
return sum;
}
public Polynomial differentiate() {
double[] aloha = new double[] {,};
aloha = cs;
for ( int r = 1; r < cs.length-1; r++)
{
aloha[r-1] = cs[r]*r;
}
Polynomial jeremy = new Polynomial(aloha);
return jeremy;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment