473,378 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

evaluate an algebraic expression

How do i evaulate a mathematical expression that is entered in a text
field.
Ex:
Text Fields:

Xo=23
X1= 250

Expression: y = Xoe^(x1+Xo)-cos(X0+X1)+23Xo
How do i manage that?

tx
Aug 31 '08 #1
14 3681
On Aug 31, 10:29*am, serave <ramirez.sebast...@gmail.comwrote:
How do i evaulate a mathematical expression that is entered in a text
field.
Ex:
Text Fields:

Xo=23
X1= 250

Expression: y = Xoe^(x1+Xo)-cos(X0+X1)+23Xo

How do i manage that?
You have X0, x1, Xo, and X1 on the right side of the equation but
define only Xo and X1. Thus the equation can not be solved as a
numerical value for y unless you define one other value with some
numerical value. Perhaps there is a typo in the equation? If you mean
to simplify the equation as written, that is a problem in algebra.

If you define another value or correct a possible typo, either the
math functions of php or Javascript can be used to solve the
equation(the value of y for perhaps a value of x1 ?) because the
simple math functions, exponentials, and cos are all contained in both
languages.
Aug 31 '08 #2
On 31 aug, 17:29, serave <ramirez.sebast...@gmail.comwrote:
Xo=23
X1= 250

Expression: y = Xoe^(x1+Xo)-cos(X0+X1)+23Xo
To do this in PHP, you first parse the expression to convert it from a
string to a structure. You have to make a parser to do this. Next, you
compute the result.

It is far from trivial to do this in PHP. A better approach may be to
use something like bc (http://www.gnu.org/software/bc/) or another
program to evaluate the expression for you.
Aug 31 '08 #3
Do you know if there is something already wrote, maybe in javascript
or something caise i will take lots of lines to do it again. And there
might be somebody that has already wrote that?

Aug 31 '08 #4
On Aug 31, 1:03*pm, cwdjrxyz <spamtr...@cwdjr.infowrote:
On Aug 31, 10:29*am, serave <ramirez.sebast...@gmail.comwrote:
How do i evaulate a mathematical expression that is entered in a text
field.
Ex:
Text Fields:
Xo=23
X1= 250
Expression: y = Xoe^(x1+Xo)-cos(X0+X1)+23Xo
How do i manage that?

You have X0, x1, Xo, and X1 on the right side of the equation but
define only Xo and X1. Thus the equation can not be solved as a
numerical value for y unless you define one other value with some
numerical value. Perhaps there is a typo in the equation? If you mean
to simplify the equation as written, that is a problem in algebra.

If you define another value or correct a possible typo, either the
math functions of php or Javascript can be used to solve the
equation(the value of y for perhaps a value of x1 ?) *because the
simple math functions, exponentials, and cos are all contained in both
languages.
You will find how to use the math functions in Javascript and PHP in
most more complete books published on these subjects in the last
several years. Reading several of the examples given in most of these
books will likely help.

To show how math functions are used on a real web page, I have
examples using both Javascript and PHP.

For the Javascript example, view the source code of
http://www.cwdjr.net/math/cylinderAbsorption.html .

For the PHP code for http://www.cwdjr.net/calendar2/perpetual_calendar.php
view the text file:
http://www.cwdjr.net/calendar2/perpetual_calendar.txt .
Aug 31 '08 #5
My problem is not the equation, or simplifing it. i just need to
evaluate what evere equation is given by the user. How will no write
it as php or javsacsript will demant it. I need to transform the
equation to a language like php or javascript or whatevere i can use
web. I'm looking for some info like that. Maybe a predifine function
that does that job.
Aug 31 '08 #6
serave wrote:
Do you know if there is something already wrote, maybe in javascript
or something caise i will take lots of lines to do it again. And there
might be somebody that has already wrote that?

It won't help much to have something already written in javascript -
unless you want to try to convert it to PHP yourself.

But even if you do, I don't know of anything which wouldn't be
proprietary. And as Sjoerd said, this is not trivial. It can be done,
but you have a lot of work ahead of you.

I did something like this many years ago in C. I used a structure with
three parameters - the two values and the operation to be performed.
The operation was simple - but if a value was computed, I pointed to the
structure whose results was the value (via a UNION in the structure) to
be used.

However, I was not dealing with variables, etc. All I need to do was
give the results for an expression. It was orders of magnitude simpler
than what you want to do. But it was still difficult to get everything
sorted out and computed properly.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 31 '08 #7
On 31 ago, 15:32, Jerry Stuckle <jstuck...@attglobal.netwrote:
serave wrote:
Do you know if there is something already wrote, maybe in javascript
or something caise i will take lots of lines to do it again. And there
might be somebody that has already wrote that?

It won't help much to have something already written in javascript -
unless you want to try to convert it to PHP yourself.

But even if you do, I don't know of anything which wouldn't be
proprietary. And as Sjoerd said, this is not trivial. *It can be done,
but you have a lot of work ahead of you.

I did something like this many years ago in C. *I used a structure with
three parameters - the two values and the operation to be performed.
The operation was simple - but if a value was computed, I pointed to the
structure whose results was the value (via a UNION in the structure) to
be used.

However, I was not dealing with variables, etc. *All I need to do was
give the results for an expression. It was orders of magnitude simpler
than what you want to do. *But it was still difficult to get everything
sorted out and computed properly.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
tx for you information. But actually i'm going to work with php, but
if i can get something that evaluates(give the result) the function
writen by an end user, i can put it in variable and from then on i
will start my job in php
Aug 31 '08 #8
serave wrote:
On 31 ago, 15:32, Jerry Stuckle <jstuck...@attglobal.netwrote:
>serave wrote:
>>Do you know if there is something already wrote, maybe in javascript
or something caise i will take lots of lines to do it again. And there
might be somebody that has already wrote that?
It won't help much to have something already written in javascript -
unless you want to try to convert it to PHP yourself.

But even if you do, I don't know of anything which wouldn't be
proprietary. And as Sjoerd said, this is not trivial. It can be done,
but you have a lot of work ahead of you.

I did something like this many years ago in C. I used a structure with
three parameters - the two values and the operation to be performed.
The operation was simple - but if a value was computed, I pointed to the
structure whose results was the value (via a UNION in the structure) to
be used.

However, I was not dealing with variables, etc. All I need to do was
give the results for an expression. It was orders of magnitude simpler
than what you want to do. But it was still difficult to get everything
sorted out and computed properly.

tx for you information. But actually i'm going to work with php, but
if i can get something that evaluates(give the result) the function
writen by an end user, i can put it in variable and from then on i
will start my job in php
Sjoerd's is probably the best suggestion. But even so, you're looking
at lots of work.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 31 '08 #9
On Aug 31, 3:27*pm, serave <ramirez.sebast...@gmail.comwrote:
My problem is not the equation, or simplifing it. i just need to
evaluate what evere equation is given by the user. How will no write
it as php or javsacsript will demant it. I need to transform the
equation to a language like php or javascript or whatevere i can use
web. I'm looking for some info like that. Maybe a predifine function
that does that job.
Thanks for the additional information. If I understand you correctly
now, you want a program into which you can type a mathematical
equation much as it would appear in a math text. Then you want the
program to take that input, convert it into some code to solve the
equation and perhaps tabulate the results in tables, plots etc.

If the above is so, there long have been programs designed to do this.
They are used by people in math, engineering, the sciences etc. Such
programs are extremely complex, and if this is what you have in mind I
would suggest that you not waste your time on such a project. I am not
sure that any one person, no matter how skilled, could come up with
such a program that would be anywhere close to the quality of what is
available. Some such programs can be put up on a server so that input
can be from the web. However such programs are very expensive, for
good reason. Even so, input has to follow strict rules for the program
to work properly. The program must have very complex error detection
features, for there is no telling what someone may type in. Such a
program would most likely be written mostly in C++ or something of
that sort.
Aug 31 '08 #10
On 31 ago, 17:44, cwdjrxyz <spamtr...@cwdjr.infowrote:
On Aug 31, 3:27*pm, serave <ramirez.sebast...@gmail.comwrote:
My problem is not the equation, or simplifing it. i just need to
evaluate what evere equation is given by the user. How will no write
it as php or javsacsript will demant it. I need to transform the
equation to a language like php or javascript or whatevere i can use
web. I'm looking for some info like that. Maybe a predifine function
that does that job.

Thanks for the additional information. If I understand you correctly
now, you want a program into which you can type a mathematical
equation much as it would appear in a math text. Then you want the
program to take that input, convert it into some code to solve the
equation and perhaps tabulate the results in tables, plots etc.

If the above is so, there long have been programs designed to do this.
They are used by people in math, engineering, the sciences etc. Such
programs are extremely complex, and if this is what you have in mind I
would suggest that you not waste your time on such a project. I am not
sure that any one person, no matter how skilled, could come up with
such a program that would be anywhere close to the quality of what is
available. Some such programs can be put up on a server so that input
can be from the web. However such programs are very expensive, for
good reason. Even so, input has to follow strict rules for the program
to work properly. The program must have very complex error detection
features, for there is no telling what someone may type in. Such a
program would most likely be written mostly in C++ or something of
that sort.
tx a lot what you are saying is exactly what im looking for,but
hopefully free, or just a library to get the cuntion i just need it to
dosome additional work. i need to program some nnumerical methods, but
the entries must be given from and end user so i need the equation
parser
Aug 31 '08 #11
serave wrote:
On 31 ago, 17:44, cwdjrxyz <spamtr...@cwdjr.infowrote:
>On Aug 31, 3:27 pm, serave <ramirez.sebast...@gmail.comwrote:
>>My problem is not the equation, or simplifing it. i just need to
evaluate what evere equation is given by the user. How will no write
it as php or javsacsript will demant it. I need to transform the
equation to a language like php or javascript or whatevere i can use
web. I'm looking for some info like that. Maybe a predifine function
that does that job.
Thanks for the additional information. If I understand you correctly
now, you want a program into which you can type a mathematical
equation much as it would appear in a math text. Then you want the
program to take that input, convert it into some code to solve the
equation and perhaps tabulate the results in tables, plots etc.

If the above is so, there long have been programs designed to do this.
They are used by people in math, engineering, the sciences etc. Such
programs are extremely complex, and if this is what you have in mind I
would suggest that you not waste your time on such a project. I am not
sure that any one person, no matter how skilled, could come up with
such a program that would be anywhere close to the quality of what is
available. Some such programs can be put up on a server so that input
can be from the web. However such programs are very expensive, for
good reason. Even so, input has to follow strict rules for the program
to work properly. The program must have very complex error detection
features, for there is no telling what someone may type in. Such a
program would most likely be written mostly in C++ or something of
that sort.

tx a lot what you are saying is exactly what im looking for,but
hopefully free, or just a library to get the cuntion i just need it to
dosome additional work. i need to program some nnumerical methods, but
the entries must be given from and end user so i need the equation
parser
The point is - you are not going to find something like that for free.
They'll probably cost you tens of thousands of dollars.

As we've been trying to tell you. Such a script is not trivial. It
takes a lot of work to develop. And people don't give all of that work
away for free. They need to live, also.

It's also too specialized for the open source community. You'll find
very little interest there.

Probably the best free you'll find will be what Sjoerd recommended.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 1 '08 #12
serave wrote:
On 31 ago, 15:32, Jerry Stuckle <jstuck...@attglobal.netwrote:
>serave wrote:
>>Do you know if there is something already wrote, maybe in javascript
or something caise i will take lots of lines to do it again. And there
might be somebody that has already wrote that?
It won't help much to have something already written in javascript -
unless you want to try to convert it to PHP yourself.

But even if you do, I don't know of anything which wouldn't be
proprietary. And as Sjoerd said, this is not trivial. It can be done,
but you have a lot of work ahead of you.

I did something like this many years ago in C. I used a structure with
three parameters - the two values and the operation to be performed.
The operation was simple - but if a value was computed, I pointed to the
structure whose results was the value (via a UNION in the structure) to
be used.

However, I was not dealing with variables, etc. All I need to do was
give the results for an expression. It was orders of magnitude simpler
than what you want to do. But it was still difficult to get everything
sorted out and computed properly.

tx for you information. But actually i'm going to work with php, but
if i can get something that evaluates(give the result) the function
writen by an end user, i can put it in variable and from then on i
will start my job in php
Just as a precautionary note, if you actually try to write some sort
of equation parser, you may be tempted to use eval(). *DON'T*. User
input mixed with eval() is perhaps the most dangerous exploit you can
expose.

If you do try to use Sjoerd's suggestion, do not forget to look up
PHP's command line sanitizing functions. For example, when passing
arguments, use escapeshellarg(). It's used for escaping *individual*
arguments.

Be extremely careful when exposing user input to the shell.

--
Curtis
Sep 1 '08 #13
On Aug 31, 5:29*pm, serave <ramirez.sebast...@gmail.comwrote:
How do i evaulate a mathematical expression that is entered in a text
field.
What exactly do you want? Why do you want to evaluate mathematical
expressions? Do you simply want the numerical value of y?
Sep 1 '08 #14
On 1 sep, 02:50, Sjoerd <sjoer...@gmail.comwrote:
On Aug 31, 5:29*pm, serave <ramirez.sebast...@gmail.comwrote:
How do i evaulate a mathematical expression that is entered in a text
field.

What exactly do you want? Why do you want to evaluate mathematical
expressions? Do you simply want the numerical value of y?
Exactly, thats what i need. The be explicit. the user enter the values
of the x`s and the program should return the y value, given teh math
equiation entered by the user.
Sep 14 '08 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Spiegel | last post by:
Hi all, Is it possible to have an uncompiled C# expression evaluated at runtime? I'd like to store an expression within an XML file then evaluate it when the time comes, something like: ...
1
by: Charlie | last post by:
I have the first part of the project done but I'm having difficulty deciding how to add an evaluate function to this program. The program asks the user to enter a function in infix notation and...
1
by: David Laub | last post by:
I have no problems running the following dynamic XPath evaluator form MSXSL: <msxsl:script implements-prefix="dyn" language="jscript"> evaluate(context, expression) { return...
10
by: Mars | last post by:
if I want to write a program to evaluate a formulae, what kind of algorithm should I use?? for example, input: (2+3)*(3/4)+6-8 how to deal with the brackets?? need to use stacks??
3
by: Coco | last post by:
Hi! Does c# has any class method that will be able to evaluate a given string e.g ((True && False) || (True && True)) and return the result in boolean for this case is true Thanks!
13
by: Zeng | last post by:
Hello, Please help!!! I've been stuck on this issue for months. I just wonder if there is a way to programmatically evaluate expression strings such as ( ( 3 + 5 ) / 2 ) > 4 --> this...
6
by: DavidM | last post by:
Hi, Are there any libraries for manipulating algebraic expression trees? In particular, take an expression tree and simplify it down. I'm working up the next release of PyGene, the genetic...
9
by: Cristian | last post by:
algebraic expression 'a*b+c' with CIN .Is it possible? How to transfer the algebraic expression 'a*b+c' to the variable s (all double) with cout in a "Console Application" ? cout<<"Input a,b,c...
1
by: aitia | last post by:
this the code. i used ECLIPSE to run this.. it has some codes smells that i can't seem to figure out.. can any one help? import java.io.*; import java.util.*; public class Postfix { private...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.