|
|

|
Porsche, and the Porsche crest are registered trademarks of Dr. Ing. h.c. F. Porsche AG.
This site is not affiliated with Porsche in any way. Its only purpose is to provide an online forum for car enthusiasts. All other trademarks are property of their respective owners. |
|
|
| MattR |
Jan 22 2006, 10:48 PM
Post
#21
|
|
Advanced Member ![]() ![]() ![]() ![]() Group: Members Posts: 3,279 Joined: 23-January 04 From: SF Bay Area Member No.: 1,589 Region Association: Northern California |
I'm trying to finish up some homework. Its not last minute (due tomorrow night), but I'm stuck. Britt and I have been trying to debug for a little while but with no luck.
The problem: I'm trying to solve the integral 2*sqrt(1-x*x) from -1 to 1 using the trapezoidal rule. Basically I have to solve the equation: h[f(x1) + f(x2) + ... + f(x n-1)] where x1, x2, etc. is the function evaluated at the point x1, x2, etc. along the x axis. the distance between x1 and x2 is a-b/n, which is the distance of the interval. I will need to input the number of intervals and be given an approximation for the function. Here is my code; #include #include int main(void) { int n; int f=0; int J; int x=-1; printf("Please enter the number of subdivisions n:"); scanf("%d",&n); While (x<=1) { x = x+2/n; f = f+2*sqrt(1-x*x); } J=2/n*f; printf("The approximate integration by Trapezoidal Rule is: %d \n",J); return 0; } Does anybody see anything thats glaring? I'm getting an error in line 23 (after the While (x<=1) that wont stop... |
MattR Who speaks C? Jan 22 2006, 10:48 PM
MattR error codes:
trapezoidal4.c: In function `main... Jan 22 2006, 11:03 PM
john rogers Well, you did not say which compiler you are using... Jan 22 2006, 11:04 PM
MattR Yeah, I'm using GCC compiler... sorry, i shoul... Jan 22 2006, 11:11 PM
bd1308 ssshhhhheeeeeeeeeeett..
i forgot about that.
ran... Jan 22 2006, 11:16 PM
McMark While vs. while
http://www... Jan 22 2006, 11:17 PM
MattR Jan 22 2006, 11:19 PM
MattR Okay, now I dont get any errors in GCC
but when I... Jan 22 2006, 11:21 PM
john rogers Check your output formatting. Jan 22 2006, 11:24 PM
MattR I'm getting the error in the "sqrt" function.
... Jan 22 2006, 11:26 PM
r_towle out of visual studio
While (x<=1);
made me add a... Jan 22 2006, 11:29 PM
bryanc For this problem, all of the variables should be ... Jan 22 2006, 11:36 PM
McMark I bet NaN is "not a number". http:... Jan 23 2006, 12:11 AM
MattR Jan 23 2006, 12:14 AM
Hammy http://www.914world.com/bbs2/h... Jan 23 2006, 01:11 AM
Dave_Darling Like they said, check your argument types and retu... Jan 23 2006, 02:06 AM
reverie Welcome to the club! http... Jan 23 2006, 05:23 AM
jasons Jan 23 2006, 07:55 AM
bd1308 doh!
that was the first thing that popped in... Jan 23 2006, 07:59 AM
Root_Werks http://www.914world.com/bbs2/html/e... Jan 23 2006, 10:44 AM
fiid I think you need to use printf("%f\n"... in... Jan 23 2006, 10:52 AM
MattR Okay guys,
Ive fixed a BUNCH of the problems you... Jan 23 2006, 12:11 PM![]() ![]() |
|
Lo-Fi Version | Time is now: 15th September 2025 - 04:13 PM |
| All rights reserved 914World.com © since 2002 |
|
914World.com is the fastest growing online 914 community! We have it all, classifieds, events, forums, vendors, parts, autocross, racing, technical articles, events calendar, newsletter, restoration, gallery, archives, history and more for your Porsche 914 ... |