在MATLAB中,如何在拉普拉斯变换中替换导数的初始值?

时间:2017-05-05 00:01:42

标签: matlab differential-equations

我有一个.m脚本,用于在MATLAB中使用具有常系数的非齐次一阶线性IVP;我将使用$ \ dot {x} - 3x = t ^ 2 $,$ x(0)= 4 $作为示例:

syms x(t) s X
Dx = diff(x(t),t)
ode = Dx - 3*x - t^2
x0 = 4

ODE = laplace(ode,t,s) % The t and s in laplace aren't necessary, as they are default
IVP = subs(ODE,{x(0)},{x0})
IVP = subs(IVP,{laplace(x(t),t,s)},{X})
IVP = collect(IVP,X)

X = solve(IVP, X)
X = partfrac(X)

sol = ilaplace(X, s, t)

Dsol = diff(sol,t)
check1 = Dsol - 3*sol
check2 = vpa(subs(sol, t, 0))

工作正常。

当我尝试对具有常系数的二阶线性IVP执行此脚本的变体时,我会在t = 0时尝试替换一阶导数的值(使用$ \ ddot {x} - 2 \ dot {x} - 3x = t ^ 2 $,$ x(0)= 4 $,$ \ dot {x} = 5 $为例):

syms x(t) s X
Dx = diff(x,t)
D2x = diff(x, t, 2)
ode = D2x - 2*Dx - 3*x - t^2
x0 = 4
xdot0 = 5

ODE = laplace(ode,t,s)
IVP = subs(ODE,{x(0)},{x0})
IVP = subs(ODE,{D(x)(0)},{xdot0}) % <- <- THIS IS THE PROBLEM LINE!!
IVP = subs(IVP,{laplace(x(t),t,s)},{X})
IVP = collect(IVP,X)

X = solve(IVP, X)
X = partfrac(X)

sol = ilaplace(X, s, t)

Dsol = diff(sol,t)
D2sol = diff(sol, t, 2)
check1 = D2sol - 2*Dsol - 3*sol
check2 = vpa(subs(sol, t, 0))
check3 = vpa(subs(Dsol, t, 0))

我不确定在二阶导数的拉普拉斯变换中作为变量D(x)(0)放置什么;我尝试的一切都给了我一些错误或其他错误。我不得不求助于kludgy

syms x(t) s X

a1 =-2
a0 = -3
x0 = 4
xdot0 = 5
rhs = t^2

Dx = diff(x,t)
D2x = diff(x,t,2)
lhs = D2x + a1*Dx + a0*x
ode = lhs - rhs

Lx = X 
LDx = s*X - x0
LD2x = s^2*X - x0*s - xdot0
LHS = LD2x + a1*LDx + a0*Lx
RHS = laplace(rhs,t,s)
IVP = LHS - RHS

IVP = collect(IVP,X)

X = solve(IVP, X)
X = partfrac(X)

sol = ilaplace(X, s, t)

Dsol = diff(sol,t)
D2sol = diff(sol,t,2)
check1 = D2sol + a1*Dsol + a0*sol
check2 = vpa(subs(sol, t, 0))
check3 = vpa(subs(Dsol, t, 0))

使用here的建议。我真正需要知道的是&#34; D(x)(0)&#34;。我试过D(x)(0)&#39;,diff(x,t)(0),Dx(0),

help = D(x)
IVP = subs(ODE,{help(0)},{xdot0})

help2 = diff(x,t)
IVP = subs(ODE,{help2(0)},{xdot0})

你说出来,没有任何效果。

提前感谢您提供的任何帮助。

0 个答案:

没有答案