find the area bounded by the curves f(x)=9-c.^2 and g(x)=x-3 in matlab

To find the area bounded by the curves f(x) = 9 - c^2 and g(x) = x - 3 in MATLAB, we need to find the intersection points of the two curves first. We can find the intersection points by solving the equation f(x) = g(x), which results in the quadratic equation c^2 + x - 12 = 0. The roots of this equation give us the x-coordinates of the intersection points.

Here's the MATLAB code to find the area:

main.m
syms c x % declare symbolic variables
f = 9 - c^2; % define function f(x)
g = x - 3; % define function g(x)
eqn = f == g; % solve f(x) = g(x)
x_int = double(solve(eqn, x)); % solve for x
c_int = sqrt(9 - x_int); % calculate corresponding c values
A = abs(int(f-g, x, x_int(1), x_int(2))); % calculate absolute value of integral
328 chars
8 lines

In the above code, we first declare c and x as symbolic variables using the syms command. Then we define the two functions f(x) and g(x) using the symbolic variables c and x. Next, we solve the equation f(x) = g(x) using the solve command, which gives us the x-coordinates of the intersection points. We calculate the corresponding values of c using the equation for the curve f(x). Finally, we use the int command to calculate the definite integral of the absolute difference between f(x) and g(x) over the interval between the intersection points, which gives us the area bounded by the two curves.

Note that we take the absolute value of the integral because the curve f(x) is below g(x) in the region between the intersection points. Also, we convert the output of the solve command to double precision using the double command because the int command requires numeric input.

related categories

gistlibby LogSnag