Tuesday, June 30, 2020

Matlab Script - Symbolic solution for second-order differential equation

This Script run on Octave platform. The script get input second order differential equation with initial condition, of the form:
 The script return the function y(t).
Download the file simplediff2.m 

% Script to solve  second-order differential equation

% Specify the second-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
% y1 - initial condition for y'(t) -  y'(0) = y1

syms y(t) a y0 y1

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

% S = dsolve(eqn, cond)
S = dsolve (eqn, y(0) == y0, diff(y)(0) == y1)

Example :
Differential equation with initial condition:

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

% S = dsolve(eqn, cond)
S = dsolve (eqn, y(0) == y0, diff(y)(0) == y1)

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