Hi!i need your help.please help me solve my assignment in numerical analysis,our teacher asked us to get the derivative of a function using turbo c programming language.I really don't have any idea on how to solve this. The equation would be like this f(x)=3x^2-5x.In this program, the user is asked to input the function that he wants to be solved.anyone please help.....

Why don't you use the quadratic formula? If all of the equations are quadratic, it should work.

You can do square roots in C with the sqrt() function from math.h, and arbitrary powers (if you wanted to) with pow().

The first part of the problem, of course, is parsing the equation. I think you could get away with using '-' and '+' to separate the terms of the equation.

It all depends on the range of equations that your program is supposed to deal with.

Now that I re-read your post, it seems like you might be looking for the derivative of the equation, not its zeros. In that case, you'd have to apply the laws of derivatives to the equation, once you parse it . . . .

Sounds pretty complicated to me. How much experience do you have with C?

 Also pay attention to what was said in your other thread . . . http://www.daniweb.com/forums/thread139491.html [/edit]

Thanks for the reply...It's actually very hard for me because I am not an expert of c.I only know the basics...Can you please give me any idea on parsing?

Thanks for the reply...It's actually very hard for me because I am not an expert of c.I only know the basics...Can you please give me any idea on parsing?

Well if you have the following equation:

f(x)=3x^2-5x

you need to extract the 3 and the -5. You need to know exactly what assumptions you can make regarding the user input (i.e. can you assume legal input, no spaces, integers only, that x^2 comes before x in all cases, that the polynomial degree is 2, etc.) If you can assume all of this, your parsing job is much easier. You know exactly what form the input, which will be stored in a C-style string, is. Just go through the string a character at a time till you run into a plus or minus or digit. Mark the position of the that character, then keep going till you hit a non-digit. That will mark the beginning and end of the x^2 coefficient. Find the 2 and ignore it. Keep going till you bump into the next plus or minus or digit, which is the start of the x coefficient. Go character by character till you hit a non-digit and that'll mark the end of the x coefficient. Extract those two coefficient substrings, turn them into integers, do your math, create your new polynomial, and output it.

Again, you need to know exactly what you need to be able to handle. The fewer assumptions you can make, the more cases the parser needs to deal with, i.e.

-5 x^2 + 3 - 7x
x^2-x-1
5-6x^1 + 5 x^2

But if it's plain old stuff like:

64x^2+3x

your job is considerable simpler. ctype.h could come in handy, as could atoi and itoa:

thanks for the help...i really appreciate it..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.