How to give a piecewise function as input

조회 수: 8 (최근 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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by