LAB Sheet-8
LAB Sheet-8
Lab Sheet-8
1. Differentiation
syms x
f = x^3 + 2*x^2 + x; % Define a symbolic function
df = diff(f, x); % First derivative
disp(df) % Display the derivative
Integration
syms x
f = x^2 + 3*x + 5; % Define a symbolic function
F = int(f, x); % Indefinite integral
disp(F)
syms x y
f = x^2 + y^2; % Define the function to integrate
inner_integral = int(f, y, 0, x); % Integrate with respect to y from 0 to x
result = int(inner_integral, x, 0, 1); % Integrate with respect to x from 0 to 1
disp(result) % Display the result
Plotting Functions
Example:
fplot(@(x) x^3 - 3*x^2 + 4, [-2, 2]); % Plot the function on the interval [-2, 2]
xlabel('x');
ylabel('f(x)');
title('Function Plot');
grid on;
Solving Ordinary Differential Equations (ODEs)
MATLAB provides the dsolve function for symbolic solutions and numerical solvers such as
ode45 for numerical solutions.
syms y(x)
Dy = diff(y, x); % Define derivative
ODE = Dy + 3*y == sin(x); % Define the ODE
ySol = dsolve(ODE); % Solve the ODE
disp(ySol);
syms y(x)
Dy = diff(y, x); % Define the derivative
ODE = Dy + 2*y == exp(-x); % Define the ODE
cond = y(0) == 1; % Initial condition
ySol = dsolve(ODE, cond); % Solve the IVP
disp(ySol); % Display the solution
Numerical Solution
% Solve y' = -2*y with initial condition y(0) = 1
Practise Problems: