Re: Read ecuations from file
Do you need those formulas as just Strings or do you need them as if they are real expressions?
kind regards,
Jos
Re: Read ecuations from file
I need them to do some mathematical stuff ,so real expressions .
Re: Read ecuations from file
Well, you're in quite some work then: you either have to write an almost complete formula/expression parser (also see my blog entry on expression compilers) or you have to include a script interpreter such as the included Javascript engine. Both have their pros and cons. There is no free lunch here.
kind regards,
Jos
Re: Read ecuations from file
I reached a impas with my project. I read the expressions in a ArrayList called "matrix" and for mathematical operations i copy the Arraylist into another ArrayList called "clone" . Why when the statements at lines 33, 34,35 are executed affects both ArrayLists ?
I didn't posted all my code because is ~550 lines
Code:
ArrayList matrix= new ArrayList () ;
ArrayList clone =new ArrayList();
....
//-----------------------------------------------
i=0;
matrix.add(new ArrayList());
clone.add(new ArrayList());
while(fis.hasNext())
{
aux=fis.next();
if("end".equals(aux)==true) //this is where i read the ecuations
{ i++;
clone.add(new ArrayList());
matrix.add(new ArrayList());
aux=fis.next();}
((ArrayList)matrix.get(i)).add(aux);
}
}
//-----------------------------------------------------------------
public Double calcExp(int poz)
{
suma=0;
Collections.copy(clone,matrix); // i need to copy matrix into clone every time this function is called
for(j=0;j< ((ArrayList)clone.get(poz)).size();j++)
{
if("^".equals( ((ArrayList)clone.get(poz)).get(j)) && ")".equals( ((ArrayList)clone.get(poz)).get(j-1))==false)
{
((ArrayList)clone.get(poz)).set(j,calcExpPow(poz,j)); //calcExpPow returns a double
((ArrayList)clone.get(poz)).remove(j+1);
((ArrayList)clone.get(poz)).remove(j-1);
j--;
System.out.println("pow");
this.Display(clone);
}
System.out.println(" ^");
this.Display(matrix);//this shouldn't change but displays same elements like clone
}
...
return suma;
}
//--------------------------------------------------------