ASSIGNMENT 3 Matlab Rishab

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

ASSIGNMENT 3

Solution 1

Differential equations are a fundamental tool in mathematical modeling, and they play a
crucial role in describing the behavior of DC (Direct Current) motors. DC motors are
commonly used in various applications, including robotics, electric vehicles, and industrial
automation. To model a DC motor using differential equations, you need to consider the
electrical and mechanical components of the motor separately and then combine them to
create a comprehensive model.

Here's a basic overview of how differential equations are used in mathematical modeling of a
DC motor:

Electrical Model:

The electrical part of a DC motor includes the armature (rotating coil) and the field winding
(stationary magnetic field).

The voltage applied to the armature, typically called the armature voltage, results in a current
flowing through the armature winding. This current can be described by Ohm's law: V = I *
R, where V is voltage, I is current, and R is the armature resistance.

The rate of change of current in the armature winding can be described using the differential
equation: L * di/dt = V - I * R, where L is the armature inductance, di/dt represents the rate of
change of current with respect to time, and I is the armature current.

Mechanical Model:
The mechanical part of the DC motor involves the interaction between the armature and the
rotor (the part that rotates).

The torque generated by the motor is proportional to the product of the armature current and
the magnetic field strength (provided by the field winding).

The differential equation describing the mechanical part relates the torque (T) to the angular
velocity (ω) and inertia (J) of the motor: J * dω/dt = T.

Combining Electrical and Mechanical Models:

To create a comprehensive mathematical model of the DC motor, you need to combine the
electrical and mechanical equations.

The electrical torque (T_e) generated by the motor is proportional to the product of the
armature current (I) and the field strength (Kφ): T_e = Kφ * I.

The mechanical torque (T_m) is related to the angular velocity and back electromotive force
(EMF) generated by the motor: T_m = Kt * ω, where Kt is the motor torque constant.

Equate T_e and T_m to find the overall dynamic equation for the DC motor: Kφ * I = J *
dω/dt.

Solving and Simulating the Differential Equations:

The differential equation that relates armature current and angular velocity represents the
dynamic behavior of the DC motor.

Engineers can solve this differential equation numerically using techniques like Euler's
method or use simulation software to predict the motor's response under different operating
conditions, such as changing voltages or loads.

These simulations help in designing control systems and optimizing the motor's performance
for specific applications.

In summary, differential equations are essential for modeling DC motors as they provide a
mathematical framework to understand how electrical and mechanical components interact
within the motor. This modeling enables engineers to design and control DC motors for
various applications accurately.

Solution 2

Matlab provides several ordinary differential equation (ODE) solvers to handle various types
of ODEs and differential algebraic equations (DAEs). These solvers can be categorized into
two main groups: explicit and implicit methods. Here's a comparison of some common ODE
solvers available in Matlab in a tabulated form:

Solver Name Method Type Pros Cons


ode45 Explicit (Runge- - Adaptive step size - Slower for very
Kutta) control for stiff problems.
accuracy. - Good
for most non-stiff
problems.
ode23 Explicit (Runge- - Adaptive step size - Less stable for
Kutta) control for very stiff problems.
accuracy. - Faster
than ode45 for
some problems.
ode113 Explicit (Adams- - High accuracy for - Not as widely
Bashforth- non-stiff problems. used as ode45 and
Moulton) ode23.
ode15s Implicit (BDF) - Suitable for stiff - May not perform
problems. - well for non-stiff
Adaptive step size problems.
control.
ode23s Implicit (BDF) - Suitable for - May not perform
mildly stiff well for non-stiff
problems. - problems.
Adaptive step size
control.
ode23t Implicit (TR- - Suitable for stiff - May not perform
BDF2) problems with well for non-stiff
oscillations. - problems.
Adaptive step size
control.
ode23tb Implicit (TR- - Suitable for stiff - May not perform
BDF2) problems with well for non-stiff
discontinuities. - problems.
Adaptive step size
control.

When selecting an ODE solver in Matlab, it's crucial to consider the nature of your ODE
problem, including its stiffness, discontinuities, and the required level of accuracy. You may
need to experiment with different solvers to find the one that best suits your specific
application.

Solution 3

(i) In MATLAB, we can use the Symbolic Math Toolbox to create 2-D and 3-D plots
of symbolic expressions and functions. Additionally, we can perform symbolic
differentiation and other algebraic operations on symbolic variables.

MatLab code

syms x y % Define symbolic variables x and y

f = 2*sin(x)^2 + 5*cos(y)^2; % Define a symbolic function f(x, y)

diff(diff(f, y), x) % Compute the second partial derivative of f with respect to x & y

syms x y: This command defines x and y as symbolic variables. In MATLAB's Symbolic


Math Toolbox, these variables are treated as symbolic and can be used for algebraic
operations, differentiation, integration, and more.
f = 2*sin(x)^2 + 5*cos(y)^2;: Here, you define a symbolic expression f as a function of x and
y. The expression contains two terms, one involving sin(x)^2 and the other cos(y)^2. These
trigonometric functions are treated symbolically.

diff(diff(f, y), x): This command computes the second partial derivative of f with respect to y
and then x. In other words, it calculates ∂²f/∂y∂x. Let's break down the differentiation steps:

First, diff(f, y) computes the partial derivative of f with respect to y, resulting in 2*sin(x)^2*(-
sin(y)).

Then, diff(..., x) computes the partial derivative of the previous result with respect to x. The
final output is -4*sin(x)*cos(x)*sin(y).

So, the output of the given command is the symbolic expression -4*sin(x)*cos(x)*sin(y),
which represents the second mixed partial derivative of the original function f(x, y) with
respect to x and y.

(ii) To create 2-D and 3-D plots using the Symbolic Math Toolbox in MATLAB, we
can use the ezplot and ezsurf functions for symbolic expressions.
Creating 2-D Plots:

For 2-D plots of symbolic expressions, you can use the ezplot function. Here's an
example using a symbolic expression f(x):
syms x
f = sin(x);
ezplot(f, [-pi, pi]); % Plot f(x) from -π to π

Creating 3-D Plots:

For 3-D plots of symbolic expressions involving two variables, you can use the
ezsurf function. Here's an example using a symbolic expression g(x, y)
syms x y
g = x^2 + y^2;
ezsurf(g, [-1, 1, -1, 1]); % Plot g(x, y) over the specified range.

Solution 4

(i)

The Symbolic Math Toolbox in MATLAB is used for symbolic computation and algebraic
manipulation of mathematical expressions, equations, and variables. It allows you to work
with mathematical objects in a symbolic form, rather than numeric, which is particularly
useful for tasks such as algebraic simplification, solving equations, symbolic integration,
differentiation, and more. One common use of the Symbolic Math Toolbox is for the
symbolic solution of a system of linear equations.

Here's the MATLAB syntax for solving a system of linear equations using the Symbolic Math
Toolbox:

% Define symbolic variables and equations

syms x y z;

eq1 = 2*x + y - z == 1;

eq2 = x - y + 2*z == -3;

eq3 = 3*x + 2*y + z == 4;

% Create a system of equations

eqns = [eq1, eq2, eq3];

% Solve the system of equations symbolically


(ii)

The Symbolic Math Toolbox in MATLAB is used for symbolic computation and
algebraic manipulation of mathematical expressions and equations. It allows you to work
with mathematical objects in a symbolic form, rather than numeric, which is particularly
useful for tasks such as algebraic simplification, solving equations, symbolic integration,
differentiation, and finding limits of expressions. Here's why you might use the Symbolic
Math Toolbox for finding the limit of an expression:

Exact and Symbolic Results: When you find limits symbolically, you get exact
symbolic results, which can be useful for theoretical analysis and precision. Symbolic limits
allow you to work with variables and expressions in their exact mathematical form.

Analytical Insights: Symbolic limits help you gain analytical insights into the
behavior of mathematical expressions as they approach specific values or infinity. This can be
essential in various fields of mathematics, physics, and engineering.

Handling Complex Expressions: Symbolic math tools can handle complex


expressions, including limits of functions involving multiple variables, trigonometric
functions, and special functions.

Here's an example of how to find the limit of an expression using MATLAB's Symbolic Math
Toolbox:

% Load the Symbolic Math Toolbox

syms x;

% Define a symbolic expression

f = (x^2 - 1) / (x - 1);
% Find the limit of the expression as x approaches 1

limit_result = limit(f, x, 1);

Solution 5

In MATLAB, you can solve a nonlinear equation using the fsolve function from the
Optimization Toolbox. The fsolve function finds the roots of a system of nonlinear equations
numerically. Here's the syntax:

x = fsolve(fun, x0)

Example:

Let's say you want to solve the following nonlinear equation:

Here's how you can do it in MATLAB:

% Define the equation as an anonymous function

fun = @(x) x^3 - 6*x^2 + 11*x - 6;

% Initial guess for the solution

x0 = 2;

% Solve the equation

x = fsolve(fun, x0);
Solution 6

% Define the ODE as a function handle

ode_fun = @(t, y) -3*y - t/2;

% Define the time span for the solution

tspan = [0, 10]; % Adjust the time span as needed

% Set the initial condition

y0 = 1; % Initial value of y at t = 0

% Choose an ODE solver (e.g., ode45)

[solution_t, solution_y] = ode45(ode_fun, tspan, y0);

% Plot the solution

figure;

plot(solution_t, solution_y);

xlabel('t');

ylabel('y');

title('Solution of 2y'' + 6y + t = 0');

grid on;
Solution 7

(i)

The Symbolic Math Toolbox in MATLAB is used for symbolic computation and algebraic
manipulation of mathematical expressions, equations, and variables. It provides a powerful
set of tools for performing calculations in a symbolic form rather than a numeric one. Here
are some reasons why you might use the Symbolic Math Toolbox:

Symbolic Manipulation: It allows you to work with mathematical objects symbolically, which
means you can perform algebraic manipulations without losing precision. This is particularly
useful for simplifying complex expressions, solving equations symbolically, and obtaining
exact results.

Exact Solutions: The Symbolic Math Toolbox can provide exact solutions to equations and
expressions. This is especially valuable in mathematics, science, and engineering when you
need to find precise analytical solutions to problems.

Symbolic Differentiation and Integration: It enables symbolic differentiation and integration,


which can be used to derive derivatives and integrals of functions symbolically, making it
easier to work with mathematical expressions and equations.

Symbolic Variables: You can define symbolic variables, which are treated as variables with
unknown values. These variables can be used in mathematical expressions and equations to
perform symbolic calculations.

Here's how you can create symbolic variables in MATLAB using the Symbolic Math
Toolbox:

% Load the Symbolic Math Toolbox (if not loaded)

% This is required to use symbolic functionality

syms x y z; % Define symbolic variables x, y, and z


(ii)

% Load the Symbolic Math Toolbox (if not loaded)

% This is required to use symbolic functionality

syms x y z; % Define symbolic variables x, y, and z

Solution 8

% Load the Symbolic Math Toolbox (if not loaded)

% This is required to use symbolic functionality

syms x y;

% Define the equation

eqn = y == exp(x) - 2*x^2;

% Solve the equation symbolically for y in terms of x

sol_y = solve(eqn, y);

% Verify the solution numerically

x_values = [-2, -1, 0, 1, 2]; % Example x-values to verify

verification_result = zeros(size(x_values));

for i = 1:length(x_values)

x_val = x_values(i);

y_val_symbolic = subs(sol_y, x, x_val); % Substitute x_val into the symbolic solution

y_val_numeric = exp(x_val) - 2*x_val^2; % Calculate the right-hand side


verification_result(i) = isequal(y_val_symbolic, y_val_numeric); % Check if the solutions
are equal

end

% Display the results

disp('Symbolic Solution:');

disp(sol_y);

disp('Verification Results:');

disp([x_values; verification_result]);

Solution 9

% Define the ODE as an anonymous function

b = 1; % You can adjust the value of b as needed

ode_fun = @(t, y) cos(b*t);

% Define the time span for the solution

tspan = [0, 10]; % Adjust the time span as needed

% Set the initial condition

y0 = 0; % Initial value of y at t = 0

% Solve the ODE using ode45

[t, y] = ode45(ode_fun, tspan, y0);


% Plot the solution

plot(t, y);

xlabel('t');

ylabel('y');

title('Solution of dy/dt = cos(bt)');

grid on;

Solution 10

For Differentiation

Syntax:

diff(expression, variable)

expression is the symbolic expression you want to differentiate.

variable is the variable with respect to which you want to differentiate.

Example:

syms x;

f = x^2 + 3*x + 2;

df = diff(f, x);

For Integration

Syntax:

int(expression, variable)

expression is the symbolic expression you want to integrate.

variable is the variable with respect to which you want to integrate.

Example:
syms x;

f = x^2 + 3*x + 2;

F = int(f, x);

Taylor Series Expansion

Syntax:

taylor(expression, variable, point, 'Order', n)

expression is the symbolic expression for which you want to find the Taylor series
expansion.

variable is the variable around which you want to expand the series.

point is the point around which you want to expand the series.

'Order' is an optional keyword specifying the order of the Taylor series expansion.

n is the order of the Taylor series expansion (the number of terms).

Example:

syms x;

f = exp(x);

taylor_expansion = taylor(f, x, 0, 'Order', 5);

You might also like