存储在字符数组的函数的导数求 [英] Finding derivative of a function stored in a character array

查看:210
本文介绍了存储在字符数组的函数的导数求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做的就是读取包含公式的文件是什么。我需要每个方程的导数,然后在不同的.txt文件写那些衍生方程。我读过的所有方程式入字符数组的数组,现在我不知道该怎么办一旦我存储他们到数组。我真的不需要帮助编写公式到另一个文件;我知道我可以明白这一点。

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've read all the equations into an array of character arrays and now I don't know what to do once I've stored them into the array. I really don't need help writing the equations into another file; I know I can figure that out.

我需要什么帮助上找到一种方法,采取职能的衍生物。的类型将要读方程是不那么复杂;他们将是不需要的链式法则或商法则多项式。会有,但是,的的SiNx COS X 谭X 。这将被读一些示例方程。

What I need help on is finding a way to taking the derivative of the functions. The type of equations that are going to be read are not that complicated; they're going to be polynomials that don't need the chain rule or quotient rule. There will be, however, sin x, cos x and tan x. Some sample equations that would be read are.

-2x^2+2x-3

-2x+sinx-3

-x+sin2x-tanx

的三角函数不会有括号和可变永远是X。
我只需要在正确的方向一推,请。

The trig functions will not have parenthesis and the variable will always be "x". I just need a push in the right direction, please.

推荐答案

什么是你真正要求一个<一个href=\"http://stackoverflow.com/questions/5853136/how-do-i-write-a-parser-in-c-or-objective-c-from-without-a-parser-generators\">parser.
解析器基本上是一套规则来阅读这些方程和改变/读取(解析)他们每个人。
我想尝试遍历文件的每一行,并区别开来考虑你有一个特定的字符集(即^意味着权力,x是参数等。);

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.);

例如,一些伪code:

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.

如果您需要帮助的翻译成C,自讨苦吃;我将愉快地帮助你。

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

这篇关于存储在字符数组的函数的导数求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆