Showing posts with label First order differential equation. Show all posts
Showing posts with label First order differential equation. Show all posts

Thursday, July 2, 2020

Matlab - Nonlinear Differential Equation with Initial Condition

Nonlinear Differential Equation with Initial Condition

Solve this nonlinear differential equation with an initial condition. The equation has multiple solutions.
 
Download the file nonldiff1.m

% Nonlinear Differential Equation with Initial Condition
%Solve this nonlinear differential equation with an initial condition.
%The equation has multiple solutions.

% initial conditions:  y(t0) = y0

syms y(t) t0 y0
ode = (diff(y,t)+y)^2 == 1;
cond = y(t0) == y0;
ySol(t) = dsolve(ode,cond)


The matlab output:
 ySol(t) =

 exp(-t)*exp(t0)*(y0 + 1) - 1
 exp(-t)*exp(t0)*(y0 - 1) + 1


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:






Monday, March 30, 2015

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 ...