find the area bounded by the curves fx=2cos x and gx=-2sin 2x on the interval from x=0 to =2 . in matlab

To find the area bounded by two curves fx=2cos(x) and gx=-2sin(2x) on the interval from x=0 to x=2, we can use calculus and MATLAB's integral function.

Firstly, we need to find the intersection points of the two curves within the given interval. We can set fx and gx equal to each other and solve for x:

2cos(x) = -2sin(2x)

cos(x) = -sin(2x)

cos(x) = -2sin(x)cos(x)

Since cos(x) cannot be zero within the given interval, we can divide both sides by cos(x):

1 = -2sin(x)

sin(x) = -0.5

We can use MATLAB's fzero function to solve for the two roots within the interval [0,2]:

main.m
f = @(x) 2*cos(x) + 2*sin(2*x);
x1 = fzero(f, 1);
x2 = fzero(f, 1.5);
70 chars
4 lines

Now we can define a new function that gives the difference between fx and gx:

main.m
h = @(x) 2*cos(x) + 2*sin(2*x) - (-2*sin(2*x));
48 chars
2 lines

And finally, we can use the integral function to find the area between the two curves:

main.m
area = integral(h, x1, x2);
28 chars
2 lines

The resulting area should be around 1.4386.

Here is the full code:

main.m
f = @(x) 2*cos(x) + 2*sin(2*x);
x1 = fzero(f, 1);
x2 = fzero(f, 1.5);

h = @(x) 2*cos(x) + 2*sin(2*x) - (-2*sin(2*x));
area = integral(h, x1, x2);
147 chars
7 lines

related categories

gistlibby LogSnag