Finding derivative of a function stored in a character array

前端 未结 3 1968
后悔当初
后悔当初 2021-01-26 11:30

What I need to do is read a file which contains equations. I need to take the derivative of each equation and then write those derivative equations in a different .txt file. I\'

3条回答
  •  Happy的楠姐
    2021-01-26 11:59

    What you're really asking for is a parser. A parser is basically a set of rules to read those equations and change/read (parse) each of them. I'd try to iterate over each line of the file, and differentiate it considering you have a specific character set (i.e ^ means power, x is the parameter, etc.);

    For example, some pseudo code:

    Open the file.
    While there's lines to read:
       Read a line - 
       Seperate it by the operands (+,-,/,*)
       For each part:
         Find the power of x,
         Reduce it by one,
         ...(derivating rules) // no way around, you have to implement each function if you want this to work as others mentioned in the comments.
       Reconnect the parts into a string,
       Add it to a list.
     Print each element of the list.
    

    If you need help translating that into C, just ask for it; I'll happily help you.

提交回复
热议问题