473,789 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3726
On Aug 31, 10:29*am, serave <ramirez.sebast ...@gmail.comwr ote:
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.comwr ote:
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...@cwdj r.infowrote:
On Aug 31, 10:29*am, serave <ramirez.sebast ...@gmail.comwr ote:
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*******@attgl obal.net
=============== ===

Aug 31 '08 #7
On 31 ago, 15:32, Jerry Stuckle <jstuck...@attg lobal.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...@attgl obal.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...@attg lobal.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*******@attgl obal.net
=============== ===

Aug 31 '08 #9
On Aug 31, 3:27*pm, serave <ramirez.sebast ...@gmail.comwr ote:
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

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

Similar topics

2
8914
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: MyExpression = "DateTime.Today.Month % 2) = 0?"Even\":\"Odd\""; string strResultString = MyExpression.Evaluate();
1
3576
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 then it prints out the function in postfix notation. I need to add an evaluate function that evaluates the postfix notation obtained by the program. I was hoping that someone could please give me some advice as to how to add the evaluate function...
1
3098
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 context.nextNode().selectNodes(expression);
10
1368
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
8024
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
33870
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 should return 0 or false( ( 3 + 6 ) / 3 ) > ( ( 5 + 3 ) / 4 ) --> this should return 1 or trueThanks for any comment or
6
5687
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 programming and genetic algorithms library. Part of PyGene works with trees holding algebraic expressions. For example, the expression:
9
3759
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 and expression in a,b,c "<<endl; cin>>a; cin>>b; cin>>c;
1
6547
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 static Stack operators = new Stack(); private static Stack operands = new Stack();
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.