Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming: I tried to write a integral function. The program should take 4 arguments: function, a, b, deltax where function is 1, 2, or

C programming:

I tried to write a integral function. image text in transcribed

The program should take 4 arguments: function, a, b, deltax where function is 1, 2, or 3. If function is 1, () = sin(). If function is 2, () = . If function is 3, () = sin(^2).

The output should be like this:

$ ./integral 1 0 3.1415926 0.0001

integral value = 2.000000

$ ./integral 2 0 2 0.0001

integral value = 2.666667

this is the code I wrote, the output is not correct, can you help me to fix it.

#include #include

int function; double x, y, a, b, deltax, N, i, result, result1;

double power(double x, double y) { double result1 = 1; for(y;y>0;y--) { result = result1*x; } return result1; }

double integ(int function, double a, double b, double deltax) { double result=0; double N=(b-a)/deltax; double i = N-1;

if(function==1) { result=-cos(b)+cos(a); } else if(function ==2) { result=(power(b,3)-power(a,3))/3; } else if(function ==3) { result=deltax*(sin(power((a+i*deltax),2))+sin(power((a+N*deltax),2))/2); } return result; }

int main(int atoc, char **argv) { int val1=atoi(argv[1]); double val2=atof(argv[2]); double val3=atof(argv[3]); double val4=atof(argv[4]);

double z = integ(val1,val2,val3,val4); printf("integral value = %d ", z);

}

f(x)dx = F(b) F(a) dx where F is the antiderivative of f - i.e. f = F. If the function f is simple, it's possible to find the antiderivative. For example, if f = 2x then F = x2. However, if the function is more complicated, it's not possible to easily find the antiderivative this is called a nonelementary antiderivative. For example, if f = sin (x), the antiderivative is not obvious. From calculus, you should remember that an integral can be calculated as a sum of trapezoids. So, for non-obvious antiderivatives like sin (x), we can use the following trapezoid approximation: i=N-1 F f(a + idx) + f(a +(i + 1)^x). S*f(x)dx = AX i=0 Where N = b. This is equivalent to calculating the sum of (f(x)=f(x+^x) Ax ) as x goes from a to b in steps of Ax

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions

Question

CC Copy

Answered: 1 week ago

Question

1. Identify three communication approaches to identity.

Answered: 1 week ago

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago

Question

3. Describe phases of minority identity development.

Answered: 1 week ago