lvhaiwei007 发表于 2010-12-23 11:17

谁能看看下边的程序怎么回事?

S = dsolve('Df = f + g','Dg = -f + g','f(0) = 1','g(0) = 2')

S =

    f:
    g:

正确结果为
S.f = (i + 1/2)/exp(t*(i - 1)) - exp(t*(i + 1))*(i - 1/2)
         S.g = exp(t*(i + 1))*(i/2 + 1) - (i/2 - 1)/exp(t*(i - 1))
为什么出错了呢?

bainhome 发表于 2010-12-23 11:58

你又是通过什么判断出MATLAB结果出错了?>> S = dsolve('Df = f + g','Dg = -f + g','f(0) = 1','g(0) = 2')
S =
    f:
    g:
>> S.f
ans =
exp(t)*cos(t) + 2*exp(t)*sin(t)
>> S.g
ans =
2*exp(t)*cos(t) - exp(t)*sin(t)
>> diff(S.f)
ans =
3*exp(t)*cos(t) + exp(t)*sin(t)
>> S.f+S.g
ans =
3*exp(t)*cos(t) + exp(t)*sin(t)
>> syms t
>> subs(S.f,t,0)
ans =
   1
>> subs(S.g,t,0)
ans =
   2
>> -S.f+S.g
ans =
exp(t)*cos(t) - 3*exp(t)*sin(t)
>> S.g
ans =
2*exp(t)*cos(t) - exp(t)*sin(t)
>> diff(S.g)
ans =
exp(t)*cos(t) - 3*exp(t)*sin(t)It looks perfect to me.

tenglang 发表于 2010-12-23 12:35

本帖最后由 tenglang 于 2010-12-23 12:37 编辑

结果和楼上的只是表达形式不同. 一个是用三角函数表示,一个是用复数表示.
help dslove, you will find the exmaples in the help
Examples:

dsolve('Dx = -a*x') returns

ans = C1/exp(a*t)

x = dsolve('Dx = -a*x','x(0) = 1','s') returns

x = 1/exp(a*s)

S = dsolve('Df = f + g','Dg = -f + g','f(0) = 1','g(0) = 2')
returns a structure S with fields

S.f = (i + 1/2)/exp(t*(i - 1)) - exp(t*(i + 1))*(i - 1/2)
S.g = exp(t*(i + 1))*(i/2 + 1) - (i/2 - 1)/exp(t*(i - 1))

lvhaiwei007 发表于 2011-2-28 09:07

回复 3 # tenglang 的帖子

谢谢,对Matlab不熟
页: [1]
查看完整版本: 谁能看看下边的程序怎么回事?