Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » PHPGoto page 1, 2  Next

evaluate an algebraic expression

 
Jump to:  
 
serave
PostPosted: Sun Aug 31, 2008 3:29 pm    Post subject: 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
 

 
cwdjrxyz
PostPosted: Sun Aug 31, 2008 6:03 pm    Post subject: Re: evaluate an algebraic expression
       
On Aug 31, 10:29 am, serave <ramirez.sebast...@gmail.com> wrote:
Quote:
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.
 

 
Sjoerd
PostPosted: Sun Aug 31, 2008 6:05 pm    Post subject: Re: evaluate an algebraic expression
       
On 31 aug, 17:29, serave <ramirez.sebast...@gmail.com> wrote:
Quote:
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.
 

 
Jerry Stuckle
PostPosted: Sun Aug 31, 2008 6:32 pm    Post subject: Re: evaluate an algebraic expression
       
serave wrote:
Quote:
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.
jstucklex@attglobal.net
==================
 

 
Jerry Stuckle
PostPosted: Sun Aug 31, 2008 6:47 pm    Post subject: Re: evaluate an algebraic expression
       
serave wrote:
Quote:
On 31 ago, 15:32, Jerry Stuckle <jstuck...@attglobal.net> wrote:
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.
jstucklex@attglobal.net
==================
 

 
serave
PostPosted: Sun Aug 31, 2008 8:18 pm    Post subject: Re: evaluate an algebraic expression
       
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?
 

 
cwdjrxyz
PostPosted: Sun Aug 31, 2008 8:26 pm    Post subject: Re: evaluate an algebraic expression
       
On Aug 31, 1:03 pm, cwdjrxyz <spamtr...@cwdjr.info> wrote:
Quote:
On Aug 31, 10:29 am, serave <ramirez.sebast...@gmail.com> wrote:

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
LINK .

For the PHP code for LINK
view the text file:
LINK .
 

 
serave
PostPosted: Sun Aug 31, 2008 8:27 pm    Post subject: Re: evaluate an algebraic expression
       
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.
 

 
serave
PostPosted: Sun Aug 31, 2008 8:39 pm    Post subject: Re: evaluate an algebraic expression
       
On 31 ago, 15:32, Jerry Stuckle <jstuck...@attglobal.net> wrote:
Quote:
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
 

 
cwdjrxyz
PostPosted: Sun Aug 31, 2008 10:44 pm    Post subject: Re: evaluate an algebraic expression
       
On Aug 31, 3:27 pm, serave <ramirez.sebast...@gmail.com> wrote:
Quote:
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.
 

Page 1 of 2 .:. Goto page 1, 2  Next

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

łódzkie biuro księgowe poligrafia wideofilmowanie angielski kraków hydroizolacje