Created
October 9, 2016 15:16
-
-
Save Alexsandr0x/05adb5ccfe1a28b3a188fd401a5afdd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float f (float V) | |
{ | |
float fx1; | |
fx1 = (p + a*pow((N/V), 2))*(V - N*b) - k*N*T; | |
return (fx1); | |
} | |
float df (float V) | |
{ | |
float fx1; | |
fx1 = -2*a*pow(N, 2)*(V - b*N)/pow(V, 3) + (a*pow(N, 2)/pow(V, 2)) - k*T + p; | |
return (fx1); | |
} | |
int main() | |
{ | |
int itr, maxmitr; | |
float h, x0, x1, allerr; | |
x0 = 1; | |
allerr = tolerance; | |
maxmitr = 45; | |
for (itr=1; itr<=maxmitr; itr++) | |
{ | |
h=f(x0)/df(x0); | |
x1=x0-h; | |
printf("root = %f \n", itr, x1); | |
if (fabs(h) < allerr) | |
{ | |
printf("root = %f \n", itr, x1); | |
return 0; | |
} | |
x0=x1; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment