Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,277 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,200 people online right now. Registration is fast and FREE... Join Now!




is my simpson rule formula is wrong?

 
Reply to this topicStart new topic

is my simpson rule formula is wrong?, i

yaya
post 2 Apr, 2008 - 08:41 AM
Post #1


New D.I.C Head

*
Joined: 2 Apr, 2008
Posts: 1

cpp

#include<stdio.h>
#include<math.h>
double c(double T);
double c(double T)
{return ( (1.59e-11)*pow(T,4) - (1.58e-8)*pow(T,3) + (3.49e-6)*pow(T,2) + (4.72e-4)*T - (9.34e-3) );}


main()
{
float k,T1,T2,h;
double T,sum_odd,sum_even,ans;
int i,n;
printf("\nEnter the value of k:");
scanf("%f",&k);
n=2*k;
printf("n is the even number = %d\n",n);

printf("T1= 330K\n");
printf("T2 = 300K\n");
T1=330;
T2=300;
h=(T2-T1) / (n);
printf("the value of h is %1.2f\n",h);

sum_odd=0;
for(i=2;i<=n;i+=2){sum_odd+=c(T1+(i-1)*h);}
sum_even=0;
for(i=2;i<n;i+=2){sum_even+=c(T1+i*h);}

ans=(h/3)*(c(T1)+c(T2)+(4.0*sum_odd)+(2.0*sum_even));
printf("\nThe definite integral from T1 to T2");
printf("\nOf c(T)d(T) is approx.%.4f\n",ans);
system("pause");}

*edit: Please use code tags in the future, thanks! code.gif

This post has been edited by Martyr2: 2 Apr, 2008 - 09:39 PM
User is offlineProfile CardPM

Go to the top of the page

KYA
post 2 Apr, 2008 - 09:32 PM
Post #2


#include <nerd.h>

Group Icon
Joined: 14 Sep, 2007
Posts: 4,205



Thanked 50 times

Dream Kudos: 1150
My Contributions


How is your output? From my glance over it looks fine.

Use [ code ] tags in the future please
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 12:33AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month