Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication7;
/**
*
* @author dell
*/
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
/**
* Created by 20111807 on 3/7/2016.
*/
public class Polynomial {
private double ploy[];
private int degree;
private final static int SIZE=11;
public Boolean isEqual(Polynomial p) {
int dgree=p.getDegree();
if( dgree == getDegree()){
for(int i=SIZE-1;i>=0;i--){
if ( p.ploy[i] == ploy[i]){
return true;
}else
return false;
}
}return false;
}
@Override
public String toString() {
String tm="";
for(int i=degree;i>=0;i--){
if(i>1){
tm+=""+ploy[degree-i]+"x^"+(i)+" + ";
}else if(i==1){
tm+=""+ploy[degree-i]+"x"+" + ";
}else
tm+=""+ploy[degree-i];
}
return tm;
}
public static double[] add(Polynomial p1, Polynomial p2){
return p1.add(p2);
}
public double[] add(Polynomial p){
int dgree=p.getDegree();
double tmp[]=new double[dgree];
if( dgree== getDegree()){
for(int i=0;i<dgree;i++){
tmp[i]=ploy[i]+p.ploy[i];
}
return tmp;
}
System.out.print("----NotEqual");
return tmp;
}
public double evaluate(double x){
double sum=0;
for(int i=SIZE-1;i>=0;i--){
sum+=ploy[i]*Math.pow(x,i);
}
return sum;
}
public void setPolynomial(String aPoly) {
}
public void setPolynomial(int aDegree,double[] aPoly ) {
degree=aDegree;
System.arraycopy(aPoly,0,ploy,0,SIZE);
}
public int getDegree() {
return degree;
}
public Polynomial(String aPloy) {
ploy = new double[SIZE];
String[] dgre = aPloy.split("(-?([0-9]*\.[0-9]+|[0-9]+)*)x?(\^)");
degree=Integer.parseInt(dgre[1].charAt(0)+"");
// aPloy= "2x^3+-3.0x^2+6x+4";
String[] parts = aPloy.split("x(\^\d+)?[\+]");
int i=0;
for (String part : parts) {
ploy[i]=Double.parseDouble(part);
i++;
}
/*
try {
Pattern regex = Pattern.compile("(-?([0-9]*\.[0-9]+|[0-9]+)*)x?(\^?([0-9]*\.[0-9]+|[0-9]+))?");
Matcher regexMatcher = regex.matcher(aPloy);
Matcher DegreeMatcher = regex.matcher(aPloy);
DegreeMatcher.find();// to return first match
degree=Integer.parseInt(DegreeMatcher.group(4));
int tmpdegree=0;
while (regexMatcher.find()) {
// System.out.print(Double.parseDouble(regexMatcher.group(1)+""));
if(isNumeric(regexMatcher.group(1))){
ploy[tmpdegree] = Double.parseDouble(regexMatcher.group(1));
// System.out.print(ploy[tmpdegree]);
tmpdegree++;
}
}
}
catch (PatternSyntaxException ex) {
}
*/
}
public Polynomial(double[] aPoly , int aDegree ) {
degree = aDegree;
ploy = new double[SIZE];
System.arraycopy(aPoly,0,ploy,0,SIZE);
}
public Polynomial() {
//SIZE=0;
degree=0;
ploy = new double[SIZE];
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team