You are on page 1of 9

AMITY SCHOOL OF ENGINEERING

AMITY UNIVERSITY UTTAR PRADESH

DEPARTMENT OF COMPUTER SCIENCE


& ENGINEERING

SIMULATION LAB [ES204]

PRACTICAL LAB FILE

SUBMITTED TO: SUBMITTED BY:


Ms. Nidhi Gaur Debabrata Pain
(A2305220415)
3CSE6Y
EXPERIMENT NO. 7

AIM: Solving First Order Ordinary Differential Equation using Built-in Functions.

SOFTWARE USED: MATLAB or Octave online (https://octave-online.net/)

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;

%First order ode


%dy/dt=9
diffeq1 = @(t,y)[9];
tspan = [3 7];
y0 = 6;
[t,y] = ode45(diffeq1, tspan, y0);
figure;
plot(t,y,'linewidth',2)
xlabel('t');
ylabel('y');
title('Solution of dy/dt=9');

%Second order ode


%d2y/dt2=17
diffeq2 = @(t,y)[y(2);17];
tspan = [3 7];
y0 = [6 9];
[t,y] = ode45(diffeq2, tspan, y0);
figure;
plot(t,y,'linewidth',2)
xlabel('t');
ylabel('y');
legend('y1','y2');
title('Solution of d2y/dt2=17');

%Third order ode


%d3y/dt3=23
diffeq3 = @(t,y)[y(2);y(3);23];
tspan = [3 7];
y0 = [6 8 9];
[t,y] = ode45(diffeq3, tspan, y0);
figure;
plot(t,y,'linewidth',2)
xlabel('t');
ylabel('y');
legend('y1','y2','y3');
title('Solution of d3y/dt3=23');
INPUT:
OUTPUT:
RESULTS AND DISCUSSIONS:
In this experiment I was successfully able to understand and solve the first order ordinary
differential equations and also plotted the graphs of first, second and third order ordinary
differential equations using graphical enhancements such as xlabel, ylabel, legend, title,
etc. in the Octave online and Matlab software.

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:

Criteria Total Marks Marks Obtained Comments

Concept (A)

Implementation (B)

Performance (C)

Total

You might also like