Matlab coding For BCA II(1)(1)
Matlab coding For BCA II(1)(1)
% Quotient of limits
quot_limit = limit(f1 / f2, x, 1);
disp('Limit of (x^2 / (3x + 2)) as x approaches 1:');
disp(quot_limit);
syms x;
5. Continuity of a Function:
To test continuity, you need to check if a function is continuous at a specific point. If the
left-hand limit, right-hand limit, and the function value at that point are all the same, the
function is continuous at that point.
MATLAB Coding
syms x;
% Define a function
f = piecewise(x < 1, x^2, x >= 1, 2*x + 1);
% Function value at x = 1
f_at_1 = subs(f, x, 1);
disp('Function value at x = 1:');
disp(f_at_1);
f = x^2;
g = 3*x + 1;
disp('Increasing intervals:');
disp(increasing_intervals);
disp('Decreasing intervals:');
disp(decreasing_intervals);
disp('Convex intervals:');
disp(convex_intervals);
disp('Concave intervals:');
disp(concave_intervals);
% Compute the second derivative at the critical points to determine maxima or minima
second_derivative_vals = double(subs(f_double_prime, x, critical_points));
2. Techniques of Integration
In MATLAB Coding, you can perform symbolic integration using different techniques
such as substitution, integration by parts, or partial fraction decomposition.
MATLAB Coding
% Use MATLAB Coding's 'int' function to compute the definite integral from 0 to 2
syms x;
g=x^2;
p = int(g,0,2);
fprintf( 'integration of g is %f \n',p)
4. Improper Integrals
Improper integrals arise when the limits of integration involve infinity or the integrand
has a singularity.
`MATLAB Coding
: Integral of 1/x from 1 to infinity
f = @(x) 1./x;
improper_integral = integral(f, 1, Inf);
disp('Improper Integral of 1/x from 1 to infinity:');
disp(improper_integral);
% Compute the volume of the solid formed by rotating f(x) about the x-axis from x = 0 to
x=2
volume = pi * integral(@(x) f(x).^2, 0, 2);
disp('Volume of solid formed by rotating y = x^2 from 0 to 2 about the x-axis:');
disp(volume);
```
\[
A = 2\pi \int_{a}^{b} f(x) \sqrt{1 + (f'(x))^2} \, dx
\]
MATLAB Coding
% Define a function f(x) = x^2
f = @(x) x.^2;
% Define the interval and number of subintervals (n, which must be even)
a = 0;
b = 2;
n = 4; % Number of subintervals, should be even
% Back substitution
x = zeros(n, 1);
for i = n:-1:1
x(i) = augmented_matrix(i, end) - augmented_matrix(i, 1:n) * x;
end
% Bisection method
while (b - a) / 2 > tol
c = (a + b) / 2; % Midpoint
if f(c) == 0
break; % Exact solution found
elseif f(a) * f(c) < 0
b = c; % Narrow down the interval
else
a = c;
end
iter = iter + 1;
if iter >= max_iter
disp('Maximum iterations reached');
break;
end
end
% Bisection method
while (b - a) / 2 > tol
c = (a + b) / 2; % Midpoint
if f(c) == 0
break; % Exact solution found
elseif f(a) * f(c) < 0
b = c; % Narrow down the interval
else
a = c;
end
iter = iter + 1;
if iter >= max_iter
disp('Maximum iterations reached');
break;
end
end
% Initial guess
x0 = 1.5;
tol = 1e-6;
max_iter = 100;
iter = 0;
% Newton-Raphson method
while abs(f(x0)) > tol
x1 = x0 - f(x0) / f_prime(x0); % Update the guess
x0 = x1;
iter = iter + 1;
if iter >= max_iter
disp('Maximum iterations reached');
break;
end
end