-
C programs not working..:-(
Im writing a program to find the root of the sixth degree equation f(x) = x^6 - 10x^5 - 38x^4 + 368x^3 + 445x^2 - 2950x -3000
but it keeps giving me a floating exception...:-(
Can nyone help!!!!!!?????
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
float new_guess;
float last_guess;
new_guess=9;
do
{
last_guess=new_guess;
new_guess = last_guess - f(last_guess)/fprime(last_guess);
printf("Guess: %f\n",new_guess);
}while(abs(new_guess - last_guess) > 0.01);
printf("Root of the sixth degree equation is: %f\n",new_guess);
return EXIT_SUCCESS;
}
float f(float x)
{
float y;
y= x*x*x*x*x*x - 10*(x*x*x*x*x) - 38*(x*x*x*x) + 368*(x*x*x) + 445*(x*x) - 2950*x -3000;
return y;
}
float fprime(float x)
{
float z;
z= 6*(x*x*x*x*x) - 50*(x*x*x*x) - 152*(x*x*x) + 1140*(x*x) + 890*x -2950;
return z;
}
-
I cut and pasted ur program, compiled it using Borland's free compiler and it ran fine.
here's what I get...
Guess: 11.617638
Guess: 10.730997
Root of the sixth degree equation is: 10.730997
so, not sure what ur problem is.
Oh, I did move the function definitions in front of the main program, but I think that's just cuz this compiler is picky, and didn't see them.
good luck
-
-
Member
Well, to start with, d/dx(368x³) = 1104x² not 1140x²
-
Member
Also you seem to have misplaced a bracket in f()
-
Member
Also, when posting code, could you use the [CODE] tag (the # button above)?
It makes it a lot easier to read as it doesn't break lines & it keeps tabs.
Thanks
Tell me if the above stuff helped.
-
-
Member
Your maths looks OK... I get -3 as the answer, which works.
-
yes it is...stupid me
thanx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
New Security Features Planned for Firefox 4
Another Laptop Theft Exposes 21K Patients' Data
Oracle Hits to Road to Pitch Data Center Plans
Microsoft Preps Array of Windows Patches
Microsoft Nears IE9 Beta With Final Preview
Simplified Analytics Improve CRM, BI Tools
Android Passes RIM as Top Mobile OS in 2Q
VMware Updates Hyperic System Management
File Monitoring Key to Enterprise Security
LinkedIn Snaps Up SaaS Player mSpoke
|
Bookmarks