GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-May-2008, 07:56
silenceee silenceee is offline
New Member
 
Join Date: May 2008
Posts: 3
silenceee is on a distinguished road

finding the value and derivative of a math function


hi
what should we do if we take a math function from input like "sin(2x+1)/tan(x^2) " and we want to find the derivative of the functionand the value of the function for a special x (ex. x=2) ....
(we might have sin,cos,tan,cotn,exp,ln,log in the input .and we only have one variable)
i have no idea for solving this problem.
  #2  
Old 13-May-2008, 11:36
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: finding the value and derivative of a math function


Quote:
Originally Posted by silenceee
hi
what should we do if we take a math function from input like "sin(2x+1)/tan(x^2) " and we want to find the derivative of the functionand the value of the function for a special x (ex. x=2) ....
(we might have sin,cos,tan,cotn,exp,ln,log in the input .and we only have one variable)
i have no idea for solving this problem.

What kind of class is this assignment for? What are the prerequisites?

The C language (C++ too) has no features or functions that convert user input to identifiers (functions or variables). So, for example, you couldn't just enter "sin(x)" and have the compiler or any of its standard library functions convert that to a function call.

What you are looking for is something like an "arithmetic expression parser." There are numerous examples on the web, and there are several commonly used ways to convert user input to a function call that evaluates the expression.

First step is (usually) to break the input into "tokens" and classify them as "identifiers," operators," etc.

Compiler writers define a set of rules (sometimes called "productions") that define what kinds of tokens can be combined in such a way that implies something semantically significant, like calling a library functions to get the value sin(x) and cos(x) and then add their numerical results.

Symbolically manipulating expressions consisting of various combinations of the various standard library functions to apply rules for differentiating and integrating them analytically is another level entirely.


So: Where would you like to start? We have no way of knowing what you know and/or what you have done. We have no way of knowing exactly what you are required to produce. (Integrating polynomials is a lot easier than, say, integrating some other kinds of functions.)

Give us some specific information, and ask specific questions.

I mean, what kind of help could you possibly expect by just giving a vague problem description and saying that you have no idea???

Regards,

Dave
  #3  
Old 13-May-2008, 12:07
silenceee silenceee is offline
New Member
 
Join Date: May 2008
Posts: 3
silenceee is on a distinguished road

Re: finding the value and derivative of a math function


thanks for your guidance.
since i'm a begginer i don't exactly know what i need !!!
i should read about the keys that you have given and think about it.
if i couldn't solve the problem i would try to ask my question specificly.
  #4  
Old 13-May-2008, 12:44
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: finding the value and derivative of a math function


Quote:
Originally Posted by silenceee
..since i'm a begginer i don't exactly know what i need...

I meant no disrespect. Believe it or not, some of us actually remember being in a position like that. (In my case, it was about 10 minutes ago.)

My problem with your problem is: It's not exactly a beginner subject in any context that I can imagine. That's why I asked about the subject of the course and its prerequisites.

I mean, if you were an experienced programmer in certain other languages (like Maple, for example) and wanted help with C or C++ that would be one thing. (But I don't think you would have said that you don't have any idea. And it still wouldn't exactly be a beginner topic.)

If you have no programming experience and are given a problem in what amounts to symbolic logic and symbol manipulation as well as arithmetic expression parsing, I would really like to know what course it is.

Regards,

Dave

Footnote:

"No one was born knowing this stuff, you know."
---davekw7x
  #5  
Old 16-May-2008, 04:57
silenceee silenceee is offline
New Member
 
Join Date: May 2008
Posts: 3
silenceee is on a distinguished road

Re: finding the value and derivative of a math function


This is the project of a 3 credit course of c++ programming.and we should give it as our final project.and uo to now i have solved simple basic problems like calculating n! and....!!!!
anyhow i should solve it...
i'm trying to write the program just using the basic things.if i could solve it i'll let you know.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:15.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.