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

To find the area bounded by the curves f(x)=9-x.^2 and g(x)=x-3, we need to first plot these curves and identify the points of intersection. Then we can use the definite integral formula to calculate the area between these curves.

Here's how we can do this in MATLAB:

main.m
% Define the functions f and g
f = @(x) 9 - x.^2;
g = @(x) x - 3;

% Plot the curves
x = linspace(-4,4,100); % Create a vector of 100 equally spaced points from -4 to 4
plot(x,f(x),'b',x,g(x),'r')
legend('f(x)','g(x)')
xlabel('x')
ylabel('y')
title('Intersection of f(x) and g(x)')

% Find the intersection points
fminusg = @(x) f(x) - g(x); % Define the function f(x) - g(x)
x_intersect = fzero(fminusg,1); % Use fzero to find the intersection point
y_intersect = f(x_intersect);

% Calculate the area between the curves using definite integral
area = integral(fminusg,x_intersect,4); % Integrate f(x) - g(x) from the intersection point to x = 4

% Print the result
fprintf('The area bounded by the curves f(x) and g(x) is %.2f.\n', area)
740 chars
23 lines

This code will plot the two curves, find the intersection point, calculate the area between them using the integral function, and print the result.

related categories

gistlibby LogSnag