programming functions in c

Discussion in 'Software' started by troublesome, Nov 9, 2006.

  1. troublesome

    troublesome Private E-2

    Hi guys just wondered if you could help me out, i'm fairly new to programming in c, I have to do it as part of my uni course. I've recently hit a wall however, the task we've been set to do if to write a program that will take a function and integrate it using the simpson rule (dont worry about this bit, if you dont know what it is), i'm pretty confident i can write the function to do the actual integration, but the thing is, the function that is to be integrated cannot be hard coded into the program and must be user defined, the way we have done this so far is with a scanf("") statement, however i cannot seem to input fuctions such as - root(1+(x^4)) [or (1+x^4)^0.5], and have the program like it... is there any other way of inputting the function above (or similar) or a way you know of to get it to like it?

    Cheers for reading any help would be much appreciated, Chris.
     
  2. goldfish

    goldfish Lt. Sushi.DC

    Wow, okay.

    My approach would be to make a function parser. I.e. loop through all the charachters and parse them (in context) and then load that into a list of operations. Once you have that list you can turn it into whatever you need to do the intergration. So, for example, you'd take an input of chars as such:

    Code:
    x^2
    
    And that would, say turn it into your symbolic representation of ...

    Code:
    pow(x,2)
    
    (i'm using the C++ pow function but I'm sure you have used your own ;))

    Then again that would take some time. Right now I can't really think of a better way to do it, though.
     
  3. troublesome

    troublesome Private E-2

    Cheers mate i'll have a go at that, i couldnt really think of any way of doing it so at least this is a start even if it will take me a while... thanks again
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds