Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,143,418 members, 7,781,212 topics. Date: Friday, 29 March 2024 at 10:43 AM |
Nairaland Forum / Science/Technology / Programming / C++ Experts Please Come To My Aid.... (1136 Views)
Help Needed Urgently On Visual Basic. Experts Please! / Official Thread For C# Experts And Beginners / C++ Experts Pls Help Me . (2) (3) (4)
C++ Experts Please Come To My Aid.... by Nobody: 7:51pm On Jul 24, 2014 |
hello guys, am kinda new to this awesome compiler called cplusplus, so far so good have written few programs on a cgpa calculator, etc... but i discovered that my knowledge on c++ is mainly on the input/output platform,,, ok see what i mean, i want to start writting programs on Calculus, for example Case 1. 1. write a program that can add three numbers, this one is quite easy and of course requires you to define how your input variable should be ( int, float, etc) but it will only display your output in a Number format. Case 2. 2. write a program that can find the differential or integral of a function, lets say ( y = 2x^3).. this is where am having a problem and is really ostracizing me from learning this program, of course from the about function when you diffenciate it you get dy/dx = 6x^2 but how can i display this as the output? . |
Re: C++ Experts Please Come To My Aid.... by davidsmith8900: 7:55pm On Jul 24, 2014 |
Ezechinwa: hello guys, am kinda new to this awesome compiler called cplusplus, so far so good have written few programs on a cgpa calculator, etc... but i discovered that my knowledge on c++ is mainly on the input/output platform,,, ok see what i mean, i want to start writting programs on Calculus, for example What are you trying to display as output? The graph? The equation? The final answer? Can u please be more clear on your questions, if you want it answered? |
Re: C++ Experts Please Come To My Aid.... by Nobody: 8:04pm On Jul 24, 2014 |
davidsmith8900: i want my output (answer) to be dy/dx = 6x^2 rather than just a whole number... 1 Like |
Re: C++ Experts Please Come To My Aid.... by davidsmith8900: 8:12pm On Jul 24, 2014 |
Ezechinwa: Okay, I see what you are saying. The input is an equation or certain x/y data and as an output you want to find an equation. Here is a video that can get you started ~> https://www.youtube.com/watch?v=VvPBbNNMC-A Here are 2 topics that have answered your question before: A. http://stackoverflow.com/questions/2982167/integration-math-in-c B. http://stackoverflow.com/questions/1564543/c-math-library-with-integration This tutorial might be able to help you out ~> http://www.cplusplus.com/doc/tutorial/variables/ THIS LOOKS LIKE WHAT YOU ARE LOOKING FOR ~> http://www.cplusplus.com/forum/beginner/91632/ BUT DOUBLE CHECK ME ON THAT. |
Re: C++ Experts Please Come To My Aid.... by Nobody: 8:18pm On Jul 24, 2014 |
i will read up the links... and buy enough mb for watch the video.. thanks 1 Like |
Re: C++ Experts Please Come To My Aid.... by davidsmith8900: 8:20pm On Jul 24, 2014 |
Ezechinwa: i will read up the links... and buy enough mb for watch the video.. thanks What is your input? Can we see a source code? What do you have, so you wont have to buy enough mb just to watch a video. |
Re: C++ Experts Please Come To My Aid.... by WhiZTiM(m): 8:50pm On Jul 24, 2014 |
Are you sure you know exactly what you want to do? And are you sure you are ready to do it? Its called "Symbolic Differentiation" or Automatic Differentiation. Its complex and orders of magnitude much harder than it seems. Your biggest problems includes: * Input parsing * Data Structure and Abstraction * Chaining of Operation Graph(Forward and Rervese accumulation) * Output formatting In simple implementation, you basicall imbue your expressions into an Accumulation tree... (Chain rule or Function of a function) ....And you apply appropriate operation from depest node to root... First try making a calculator.... Learn parsing and solving expressions using stacks and then decision/operation trees... http://www.sciencedirect.com/science/article/pii/S0377042700004222?np=y and http://en.m.wikipedia.org/wiki/Automatic_differentiation There are programming libraries that will to certain extent, cushion the pain of implementing an Automatic Differentiating program... Check out one of the CAS Software I use in my professional field... Maxima... It does a hell of symbolic calculus and lots of symbolic/precise maths.... http://maxima.sourceforge.net I hope you know some Numerical Methods...?? Numeric methods are better industrially suited on computers... due to insane vectorized speeds on cache lines.... Symbolic is more applicable to academia/technical writing... I dunno your experience level with Programming, Computing and Undergraduate Maths ....but I hope I made little sense?? 1 Like |
Re: C++ Experts Please Come To My Aid.... by Nobody: 12:21am On Jul 25, 2014 |
WhiZTiM: Are you sure you know exactly what you want to do? And are you sure you are ready to do it? yeah, lots of sense bro,,,, i think am mathematically sound, and i will put hard effort to learn it, i know with time i will only get better.... and you also made a good point, precisely about libuaries that support dy.dx.... thanks... |
Re: C++ Experts Please Come To My Aid.... by Nobody: 12:52am On Jul 25, 2014 |
davidsmith8900: #include <iostream> #include <math.h> #include <cstdlib> using namespace std ; int main () { double y ; // " output variable" double x ; // " input variable " double n; // " power" double c; // " coefficent" double q ; // " power constant" double w ; // " power reduction " cout << " ENTER power of the function" cin >> n ; cout << " ENTER co-efficient of x " cin >> c ; q= (n * c) ; // initial manupulation w= ( n-1) ; // initial manupulation 2 y = pow ( q , w ) ; // final differential valve cout << " the differencial of the equation is " ; cout << q << "(x) ^ " << w ; // " note ^ means power " system ( "PAUSE" ; return 0 ; } |
Re: C++ Experts Please Come To My Aid.... by Nobody: 12:58am On Jul 25, 2014 |
Ezechinwa: the problem here is that if i should display my output to be y, where y = ( nx^ (n-1)) because x is a not a variable type char, it will return your valve as a number,,, rather than another function... also remember differenciation is a link of functions tending to zero, so numbers are not relevent... |
Re: C++ Experts Please Come To My Aid.... by asalimpo(m): 4:31pm On Jul 25, 2014 |
Your problem isnt hard for basc differentiation cases. I dnt code in c++ but java . The algorithm for solvg it shud b cross platform. If ur really determined u can solve it. Just focus concentrate and think,step by step. Pseudo code: ============= differentiate the expression: 2xr3 read "2x raise to power 3" ans= 6xr2. 1) get the input as a string. Input = 2xr3 2) convert the strng input into an expression object. (this is where oop concepts kick in.u know oop?) oop = object oriented programmg. 3.) process d expression object to get an answer . Which will b anoda expression object. Step2: creatg d expression object from string object ========================== take the string argument and break it up at partcular points of interest. Inputstring=2xr3. - brk it up at the power character,i.e ,'r' in this case. You will store the resultants in a list: an array or a list (read up on arrays and containers) the result will b = [2x][3] // we ignored d power character. This list has a size of 2. because it contains 2 elements. From d list the power is the second element i.e 3. - wrkg with d list is cumbersome but possible (and faster) so we'll put the elents into objects. That handle d dirty work. - create an object called 'Term' representg d "terms in an expression". (you need oop here) //using java here .. Chnge to cpp class Term { string sterm; int num; char variable=null; //set to null initially Term(string arg) { 1. Parse the argumnt to a number if it wrks, store d result in the number variable i.e num the argument is a num 2. If it fails (you know about exception handling? Read it up) then the arg isnt a number. It is a number and a variable in the form:<num><var> where 'var' is an alphabet character. Now,split the arg into 2 parts the number part and d variable part: we ar back to string parsing again. 2.1 = you will get two elements after d parse , ur results are stored in a container:an array,or list. It shud b in d form [num][var]. 2.2 now process d elements in d container of 2.1 convert the first element 'num' from srtng type to number type . Use the srting to int parse function of ur language. Wrap the parse call in a fail-safe block,to handle problems arisg durg d conversion process. In java this is a try-catch block. The process is called exception handling. Any error arisg at this stage ,shudnt b processed further. So , 2x, when parsed should become [2][x] all string types. '2' will then b converted to number type i.e int through string to number parsg. If all goes well, you'll get a number,e.g 2 in this case. Store it in the class field, 'num' store the character variable in d class field, 'variable'. All this code takes place in d Term's constructor the main work in this class is over. (... To b continued ) * Wat compiler are usg and how dyu get it ,install it and compile with it* 1 Like |
Re: C++ Experts Please Come To My Aid.... by asalimpo(m): 5:42pm On Jul 25, 2014 |
... Continuing all d previos wrk is happing in a class called Term which represents d terms in an expression. A term takes a string argument in its constructor and converts it internally into a) a number or b) a number and a character variable (representing a sun expression). A constructor is a method (similar to a function) tht a class invokes wen it wants to create new copies of itself.i.e wen its about to be instantiated. You will want to know wat type of term object u are dealg with in ur program. Is it a number , or an expression term? So you'll add methods to ur class to answer this questions.
now you've got to create the calculus class representg d expression. Lets call it Differentiator. It takes two Terms and produces an answer representg the result of d differentiation.
to b continued ... |
Re: C++ Experts Please Come To My Aid.... by Nobody: 5:49pm On Jul 25, 2014 |
@asalimpo.... don't know how to thank u enough.... well am using devcpp... and i will put your post into practise when i return.... i sure will update you... once again thanks |
Re: C++ Experts Please Come To My Aid.... by asalimpo(m): 6:19pm On Jul 25, 2014 |
continuing ... The Expression Object returned by d differentiator wasnt defined. Here's a rough sketch.
1 Like |
Re: C++ Experts Please Come To My Aid.... by asalimpo(m): 6:50pm On Jul 25, 2014 |
Wrapping up ... So far 3 objects hav been created to solve d differentiation problem. Term,Expression,Differentiator,Parser(not shown) now we'll create a fourth object. Called calculusProgram . It has two methods, differentiate and integrate . Integration isnt shown. differentiate - takes in a string expression and return a string result representing the answer. It should throw an error wen thngs go wrong. The steps first: get the input string - the expression to b differentiated - Parse the input string into an expression object - pass the expression object to a Differentiator for differiation. Invoke its 'compute' method to get a result . The result is an expression object convert the result to a sting by calling the resultant expression's object 'toString' method .
the code hasnt been tested (debugged and compiled) - it's in java (but shud b easy to port to c++). - add a constructor to d differentiator class that makes it take an Expression as argument. After validation,it shud assign the terms in the Expression object to its internal fields (Rt,Lt) 1 Like |
(1) (Reply)
Help On Andriod Studio / Check Out My Python Code For Giving You The Date/time You Are Currently. / Website Or Software Programming?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 60 |