Tuesday, June 30, 2020

Matlab Script - Symbolic solution for first-order differential equation

This Script run on Octave platform. The script get input differential equation with initial condition, of the form:
 

 The script return the function y(t).
 Download the file simplediff1.m 

% simple script to solve
% Symbolic solution for first-order differential equation

% Specify the first-order derivative by using:
% diff and the equation by using ==.
% Then, solve the equation by using dsolve.

% load symbolic package, and initilize PYTHON variable
pkg load symbolic
setenv PYTHON C:\ProgramData\Anaconda3\pythonw.exe

% Define symbolic variables:
% y(t) - function y and argumenr t
% a - parameter
% y0 - initial condition for y(t) -  y(0) = y0

syms y(t) a y0 t0
% ****  input the equaion here: *****
eqn = diff(y,t) == a*y;

% ****  input the initial conditions here: *****
cond = [y(0)==y0];

S = dsolve(eqn, cond)


Examples 1:

Differential equation with initial condition:

 % ****  input the equaion here: *****
eqn = diff(y,t) == a*y;
% ****  input the initial conditions here: *****
cond = [y(0)==y0];

 The solution:




                                                                                                  

Examples 2:

Differential equation with initial condition:

% ****  input the equaion here: *****
eqn = diff(y,t) == a*t*y;

% ****  input the initial conditions here: *****
cond = [y(0)==y0];

 The solution:








Examples 3:

% ****  input the equaion here: *****
eqn = diff(y,t) == a*y;
% ****  input the initial conditions here: *****
cond = [y(t0)==y0];

 The solution:






No comments:

Post a Comment

Featured Post

Solve simple Absolute Value Inequality

  Exam - BARTON COLLEGE PRACTICE PLACEMENT TEST Ex. 39 Exercise: The inequality |8 - x| < 8   is equivalent to:   a) x < 0 b) x &g...