Solve 3rd order differential equation in Martlab and Simulink
In this video it shows the steps to implement a 3rd order differential equation in both Matlab script and Simulink Model. In this video it is using Matlab R2021a version to demonstrate the implementation.
It used DSOLVE command to solve the differential equation in Matlab script. In Simulink Model it uses 3 integrator blocks to design the 3rd order differentiations.
The equation used in this demo is:
2 (?^3 y)/(?x^3 )+9 (?_y^2)/(?x^2 )+12 ?y/?x+5y=0
With initial conditions of:
(?_y^2)/(?x^2 ) (0)=3,?y/?x (0)=2,y(0)=1
The response received from both the approach is compared at the same for their similarity.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Complete source code and other details:
Equation in different notations:
2*y’’’ + 9*y’’ + 12*y’ + 5*y = 0
y’’ = 3, y’ = 2, y = 1
Matlab:
2*diff(y,x,3)+9*diff(y,x,2)+12*diff(y,x,1)+5*y = 0
y(0)=1,Dy(0)=2, D2y(0)=3
Matlab Script:
syms y(x) y0 Dy0 D2y0
Dy = diff(y);
D2y = diff(Dy);
D3y = diff(D2y);
equation = 2*diff(y,x,3)+9*diff(y,x,2)+12*diff(y,x,1)+5*y == 0;
y_output = dsolve(equation, y(0)==1,Dy(0)==2, D2y(0)==3);
% y_output = dsolve(equation, y(0)==y0,Dy(0)==Dy0, D2y(0)==D2y0);
% y_output = subs(y_output , {y0, Dy0, D2y0},{1,2,3});
fplot(y_output, [0 20]);
Output:
Simulink Model: