How to give a piecewise function as input

12 ビュー (過去 30 日間)
Mehul kumar
Mehul kumar 2021 年 11 月 18 日
回答済み: VBBV 2022 年 3 月 28 日
clear all
clc
syms t s y(t) Y
dy(t)=diff(y(t));
d2y(t)=diff(y(t),2);
F = input('Input the coefficients [a,b,c]: ');
a=F(1);b=F(2);c=F(3);
nh = input('Enter the non-homogenous part f(x): ');
eqn=a*d2y(t)+b*dy(t)+c*y(t)-nh;
LTY=laplace(eqn,t,s);
IC = input('Enter the initial conditions in the form [y0,Dy(0)]: ');
y0=IC(1);
dy0=IC(2);
LTY=subs(LTY,{laplace(y(t), t, s),y(0),dy(0)},{Y,y0,dy0});
eq=collect(LTY,Y);
Y=simplify(solve(eq,Y));
yt=simplify(ilaplace(Y,s,t));
disp('The solution of the differential equation y(t)=')
disp(yt);
lhs input:
[1,0,16]
rhs input:
F(t)=cos4t 0<t<pi
o t>pi

回答 (2 件)

Robert U
Robert U 2021 年 11 月 18 日

VBBV
VBBV 2022 年 3 月 28 日
clear all
clc
syms t s y(t) Y
dy(t)=diff(y(t));
d2y(t)=diff(y(t),2);
F = [-1 1 16]; %input('Input the coefficients [a,b,c]: ');
a=F(1);b=F(2);c=F(3);
nh = piecewise(t>0 & t< pi, cos(4*t), 0) %input('Enter the non-homogenous part f(x): ');
nh = 
eqn1=a*d2y(t)+b*dy(t)+c*y(t)-subs(nh,t,0)
eqn1 = 
eqn2=a*d2y(t)+b*dy(t)+c*y(t)-subs(nh,t,pi)
eqn2 = 
% LTY=laplace([eqn1 eqn2],t,s)
IC = [y(0) == 1; dy(0) == 0];% input('Enter the initial conditions in the form [y0,Dy(0)]: ');
y0=IC(1);
dy0=IC(2);
% LTY=subs(LTY,[laplace(y(t), t, s),y(0),dy(0)],[Y,y0,dy0])
% eq=collect(LTY,Y)
sol =simplify(dsolve([eqn1 eqn2],IC));
% yt=simplify(ilaplace(y,s,t))
disp('The solution of the differential equation y(t)=')
The solution of the differential equation y(t)=
disp(sol)
fplot(sol,[-1 1])

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by