|
|
The ln(exp(1)) seems to evaluate incorrectly for me. I'm no way a Regexp guru, so please could address this one?
I don't claim to be a great programmer, I try to imitate one.
|
|
|
|
|
There is a bug in MathParser. For modes other than RAD, functions ACOS, ASIN, and ATAN don't work properly.
E.g. you calculate ASIN as: a=asin(factor*b), where you use "factor" to convert angle to radians. Unfortunately with ASIN the angle is not the "input" but rather the "output", so you should rather do a=asin(b)/factor. Same goes for acos and atan
|
|
|
|
|
I would like to use "MathieuMathParser" DLL via C#.net 2005.
But I can't add it to refrences.
erorr:
please make sure that the file is acceseble and that is a valid assembly or COM component.
Have anyone ever uesed it via C#??
|
|
|
|
|
Hi Paratrooper!
I've a big problem with the math parser.
Something about my environment:
PC 1
- Intel Celeron (32 Bit only)
- Windows XP Pro. with SP2 Deutsch/German, 32 Bit Version
- MS .NET Framework 2.0
PC 2
- Virtual Machine on PC 1 using VMware Workstation 5.5.2
- Ubuntu Linux, 32 Bit Version
- Mono Project 1.1.13.8 .NET Runtime
PC 3
- Intel Pentium D 950 CPU (32 Bit, with 64 Bit Extensions)
- Windows XP Pro. with SP2 Deutsch/German, 32 Bit Version
- MS .NET Framework 2.0
PC 4
- AMD Opteron (32 Bit, with 64 Bit Extensions)
- SuSE Linux 10, 64 Bit Version
- Mono Project 1.1.13.8 .NET Runtime
Problem:
I use the math parser as a simple calculator (console application).
When I try to evaluate the expression "(4264 * 0,052) + 800" on PC1 & PC2 the
result is "1021.728" (correct). The same program returns on PC3 & PC4 the value "222528.0"!
Other Samples:
0,5 * 10 = 5 (On PC1 & PC2)
0,5 * 10 = 50 (On PC3 & PC4)
I don't understand these "strange" results.
I've tried to solve the problem but I don't know much about RegEx.
Remark: I've tried to compile the program on all pc's above. Makes no difference
Thanks, Daniel
|
|
|
|
|
Daniel,
I am having a similar problem:
The sample you gave:
0,5 * 10 = 50 (On PC3 & PC4)
Returns 50 for me too.
Regards,
Luc Pettett
|
|
|
|
|
You got this Problem cause all Win64 Bit Edition are English. In the German Language Pak are only some Ressources translated - not the internal .Net String-Formating-Routines. So it's the described Problem with the decimal Point.
Xynratron
|
|
|
|
|
I Got Error when i tried the 10/(3+(4*5)/12*48+17) expression
Whats Wrong?
Thanks
|
|
|
|
|
I solved your expression. The result was 0.1 (no error).
|
|
|
|
|
Para manejar cualquier funcion:
string ecuacion="cos(X-asin(2,3*X))+exp(X)-ln(cos(X*sin(X+2)))"; //la funcion que quieras!
Ejem: Reemplazar X por 2,0001
Evaluar(2,0001);//el resultado final! =)
public double Evaluar(double value)
{
string temporal = ecuacion;
MathParser.Parser p = new MathParser.Parser();
while (ecuacion.IndexOf("(") > 0)
{
int inicio = ecuacion.LastIndexOf("(") + 1;
int fin = ecuacion.IndexOf(")", inicio);
string temp = ecuacion.Substring(inicio, fin - inicio);
try
{
double resultado = Double.Parse(temp);
string temp1 = ecuacion.Substring(inicio - 1, fin - inicio + 2);
ecuacion = ecuacion.Replace(temp1, resultado.ToString());
}
catch
{
p.Evaluate(temp.Replace("X", Convert.ToString(value)));
ecuacion = ecuacion.Replace(temp, p.Result.ToString());
}
}
p.Evaluate(ecuacion.Replace("X", Convert.ToString(value)));
ecuacion = temporal;
return p.Result;
}
|
|
|
|
|
Hi, would it be possible to add support for logical operators (<,>, == etc.), whose result instead of true or false would be 1 or 0 respectivelly?
Felin
|
|
|
|
|
Hello there,
i tried some floating point expressions and it seems the floting value is mistreated, as its integer part is being removed in most operations. This is what i cannot fix as my regex skills are weak.
Some test cases:
0.00004730/2 becomes 00004730/2
4.73004469661202E-05/2 becomes 73004469661202E-05/2
1114.73004469661202E-05/2 becomes 73004469661202E-05/2
1114.730+2 becomes 730+2
I would be glad to see this fixed, because this nice Solver fits into my app very good.
Tnx in advance!
I don't claim to be a great programmer, I try to imitate one.
|
|
|
|
|
Hello,
I wrote this parser on a german operating system.
It searches for double values like "1,53E-2" or "123,56" etc.
Values like "4.7534" will be ignored.
Replace the code below and the parser should work on your non-german system.
// Solve Sin, Cos, Tan...
Regex regEx = new Regex( @"([a-z]{2,})([\+-]?\d+\.*\d*[eE][\+-]*\d+|[\+-]?\d+\.*\d*)", RegexOptions.IgnoreCase );
// Solve Factorial.
...
regEx = new Regex( @"(\d+\.*\d*[eE][\+-]?\d+|\d+\.*\d*)!" ); // Search for patterns like 5!
// Solve power.
regEx = new Regex( @"\{(.+)\}\^(-?\d+\.*\d*[eE][\+-]?\d+|-?\d+\.*\d*)" ); // Search for patterns like {-5}^-1
regEx = new Regex( @"(\d+\.*\d*e[\+-]?\d+|\d+\.*\d*)\^(-?\d+\.*\d*[eE][\+-]?\d+|-?\d+\.*\d*)" ); // Search for patterns like 5^-1
// Solve multiplication / division.
regEx = new Regex( @"([\+-]?\d+\.*\d*[eE][\+-]?\d+|[\-\+]?\d+\.*\d*)([\/\*])(-?\d+\.*\d*[eE][\+-]?\d+|-?\d+\.*\d*)" );
// Solve addition / subtraction.
regEx = new Regex( @"([\+-]?\d+\.*\d*[eE][\+-]?\d+|[\+-]?\d+\.*\d*)([\+-])(-?\d+\.*\d*[eE][\+-]?\d+|-?\d+\.*\d*)" );
Servus...
Paratrooper.
|
|
|
|
|
Hello Paratrooper,
Tnx for the solution - it works great. Strangelly i thought i had problems with "," as decimal separator, but now it seems I didn.
I actually changed the code to be like:
@"([a-z]{2,})([\+-]?\d+" + RegxNumericSeparator + @"*\d*[eE][\+-]*\d+|[\+-]?\d+,*\d*)"
where the RegxNumericSeparator is a escapeSpecialChars(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
The escapeSpecialChars is not very nice, and because of this I wont post it (regex are not my friends yet), but i believe everybody knows what it does.
Breakable
============
I don't claim to be a great programmer, I try to imitate one.
|
|
|
|
|
Hey Paratrooper666,
Nice code. The fix works fine except for one thing:
When you enter a decimal number without the zero, e.g. (.4 instead of 0.4)
the parser returns an incorrect result.
Any suggestions on how to fix it???
Thanks,
Louis
|
|
|
|
|
Its not that the integer part is being removed its a problem with the sequencing of the operations within the Solve function.
For example take 0.00004730 * 2.0. This is quite rightly calculated as 0.000946. However, this is is replaced into the expression as 9.46E-4.0 The problem comes is that the "Solve addition / subtraction" code picks up on the minus sign and tries to calculate
(9.46E) - (4.0) this causes an error.
Otherwise, it's a pretty good piece of code and potentially extremely useful. Boolean evaluations like those suggested would be useful.
Cheers
Simon
A great programmer merely hasn't been asked to do the impossible yet!
|
|
|
|
|
Sorry for the double post.
Having thought about the problem, its merely a question of telling the ToString function what format to convert the number into.
As all numbers internal to the Parser are stored as doubles the format specifier is "f15". Therefore, in the Solve function, wherever there's a:
Expression = regEx.Replace( Expression, result.ToString(), 1 );
or similar replace with:
Expression = regEx.Replace( Expression, result.ToString("f15"), 1 );
This then solves the problem with the further processing of the result as in my previous post.
Cheers
Simon
A great programmer merely hasn't been asked to do the impossible yet!
|
|
|
|
|
Hi Simon,
9.46E is not a valid number!
Try this: Console.WriteLine( 9.46E );
or this Console.WriteLine( (9.46E) - (4.0) );
You will get an error, because the exponent is missing!!!
Servus...
Paratrooper.
|
|
|
|
|
I know 9.46E is not a valid number!!
Try my example with your maths parser and see what happens:
0.0000473 * 2
You'll get an error, why? because it works out the sum correctly but then replaces it into the expression string in exponent form. 9.46E-4.0 This is then interpreted by the "Calculate addition/subtraction" code as
(9.46E) - (4.0). Obviously 9.46E is not a number and therefore you get an error.
Simon.
|
|
|
|
|
Hi,
if I trie to solve your example, the solver returns the correct result (9,46E-05).
I think, the problem occurs only on an english OS.
In a day or two, I will release a fixed version.
Servus...
Paratrooper.
|
|
|
|
|
could anybody tell me how to use the dll in detail? I don't know how to use a dll.
Thank you very much!!!
-------------------
I am learning C++ and English
|
|
|
|
|
Hi,
you are learning C++?
I have no idea how to use a dll in C++.
If you develope your projects with Visual Studio and C#:
1. include the dll in your project:
Project -> Add Reference -> Browse -> choose the dll.
2. use the dll in your project:
using MathParser;
MathParser p = new MathParser();
if( p.Evaluate("cos(4Pi)/2") ) Console.Write(p.Result);
else Console.Write("Error.");
|
|
|
|
|
That will solve your comma/dot problems. E.g. Single.Parse(number, CultureInfo.InvariantCulture.NumberInfo).
You can also change the running thread's culture info, but the above is a bit cleaner.
Wout
|
|
|
|
|
Hi,
I think you have a problem evaluating expressions with decimals. I tried to evaluate the following expression:
0,27 * 0,02 * 0,01 * 20
And got this result: 5,4E-100
Is this something you will fix?
/Kalle
|
|
|
|
|
Hi stenflo!
Problem has been fixed!
"(\+-]?\d+,*\d*e[\+-]?\d+|[\-\+]?\d+,*\d*)([\/\*])(-?\d+,*\d*e[\+-]?\d+|-?\d+,*\d*)"
^ ^
| |
this and this
are responsible for an incorrect result.
0,27 * 0,02 * 0,01 * 20 -> 5,4E-3 * 0,01 * 20
----------- ___^__
|
RegEx is not able to find this number, because it
searches only for lower 'e'.
I have replaced 'e' in the pattern through '[eE]' (in the whole class).
(RegexOptions.IgnoreCase would also work)
Now, it seems to work very well.
I have also fixed a problem with exponents.
1e2 should return 100.
But there was a bug in the RegEx-Pattern, which inserts the missing '*'.
(1e2 -> 1e*2 -> Error.)
|
|
|
|