Professional Documents
Culture Documents
AIM: Solving First Order Ordinary Differential Equation using Built-in Functions.
THEORY:
MATLAB provides the dsolve command for solving differential equations symbolically.
The most basic form of the dsolve command for finding the solution to a single equation
is :
dsolve('eqn')
where eqn is a text string used to enter the equation.
It returns a symbolic solution with a set of arbitrary constants that MATLAB labels C1,
C2, and so on.
You can also specify initial and boundary conditions for the problem, as comma-
delimited list following the equation as:
dsolve('eqn','cond1', 'cond2',…)
For the purpose of using dsolve command, derivatives are indicated with a D. For
example, an equation like f'(t) = -2*f + cost(t) is entered as: 'Df = -2*f + cos(t)'
Higher derivatives are indicated by following D by the order of the derivative.
For example the equation f"(x) + 2f'(x) = 5sin3x should be entered as:
'D2y + 2Dy = 5*sin(3*x)'
Let us take up a simple example of a first order differential equation:
y' = 5y. s = dsolve('Dy = 5*y')
MATLAB executes the code and returns the following result:
s = C2*exp(5*t)
PROCEDURE:
To plot the graph of a function, you need to take the following steps:
1. Define x, by specifying the range of values for the variable x, for which the function is
to be plotted.
2. Define the function, y = f(x).
3. Call the plot command, as plot (x, y).
CODE:
clc;
clear all;
syms f(x,y)
f(x,y) = 7*x + 17*y
f(5,4)
syms f(y)
M = [y^2 y^5 y^4;y^3 y y^2;y^6 y^4 y^3];
f(y) = M
f(3)
syms f(x,y)
f(x,y) = x^2*y^3
f(5,4)
xVAL = 3:7;
yVAL = 5:9;
f(xVAL,yVAL)
syms f(x,y)
f(x,y) = 7*x^2 + 17*y + 89
dfx(x,y) = diff(f,x)
syms x
f = cos(5*x);
diff(f)
diff(diff(f))
syms y(t) b
eqn = diff(y,t) == b*y^2 + y
cond = y(0) == 7
ySol(t) = dsolve(eqn,cond)
clc;
PRECAUTIONS:
1) Don’t forget to login or sign-up on Octave online.
2) Save the code/input after completing it and before running it.
3) Saving the code and it’s output by downloading it on the computer after
completing the work.
Marking Criteria:
Concept (A)
Implementation (B)
Performance (C)
Total