hi to everyone!i need help for my assignment in our numerical analysis.our instructor asked us to solve a linear equation using turbo c language.Can anyone help me with this problem,a simple sample code will do.Ex.f(x)=2x^3+x^2
hi to everyone!i need help for my assignment in our numerical analysis.our instructor asked us to solve a linear equation using turbo c language.Can anyone help me with this problem,a simple sample code will do.Ex.f(x)=2x^3+x^2
2x is multiplication; you can do it with 2 * x
. The ^ operator exists in C, but not in the way that formulae use it. It means bitwise exclusive-OR instead of exponentiation. Turbo C supports the pow()
function though, so you can use that:
/* f(x)=2x^3+x^2 */
double f(double x)
{
return pow(2 * x, 3) + pow(x, 2);
}
First of all, do you understand the maths involved?
By that, I mean can you do this on paper. If you can't, then you first need maths help, not programming help.
If you can do it on paper, try transferring that to a program and post what you can come up with.
w00ps
thanks for the reply.But what if the function is not fixed,meaning the user could input any function of x or [f(x)] with different value.
Then you need to parse the string first.. That can be pretty hard.
Try to understand how you do it, how you calculate f(x), write that down in steps on paper or on your computer and post it here.
this is the first equation:
f(x)=2x^3 + x^2
then we have to get it's 1st derivative, in math the 2nd equation would be like this:
f'(x)=6x^2 + 2x
my problem now is how to solve for it's derivative.
Note: this is not a fixed program the user is asked to input the f(x) that he wants to be solved,whatever equation that is being inputed by the user must get a correct answer.TY
Hi the Grand Matematical Conclave...
2x^3 + x^2 is not a part of a LINEAR equation!
That's a linear equation:
A*x + B = 0
So ask a user to type A then B - that's all, your program is capable to print this equation solution now...
Are you sure this is linear equation or linear function? I'm pretty sure your examples are linear functions.. Linear equations are solved like so:
Solve for x and y:
x+2y=8
3x-2y=0
Elimination:
x+2y=8
+
3x-2y=0
4x =8
4 4
x=2
Solve for y using x=2:
x+2y=8
2+2y=8
2y=6
2 2
y=3
It's not a LINEAR EQUATION:
x+2y=8
3x-2y=0
It's a SYSTEM of linear equations.
Feel the difference...
Where is a word SYSTEM in the original post?..
other than the fact that you're confusing linear functions with linear equations, a huge problem can be located in the title of your thread:
"Turbo C"
throw that crap away, now, and get a real compiler. and if you have an instructor who insists you use Turbo C, them them to sod off, as well.
all they're doing with Turbo C, in ensuring you will be a worthless programmer and incompetent in the global workplace.
.