solution of differential equation

1 次查看(过去 30 天)
Hi everyone, how could I solve dx/dt + x = sqrts(sin^2(t)) on Matlab? I tried with statements:
close all clear all t=[0:0.001:10]; s1=dsolve('Dx + x = abs(sin(t))','t'); pretty(s1)
but it evaluates a wrong solution. This is wrong:
C3*exp(-t) - (2^(1/2)*cos(pi/4 + t))/2
This is right:
Sqrt[Sin[t]^2]/2 - (Cot[t]*Sqrt[Sin[t]^2])/2 + C/exp(t)
Thank you for your help.
  1 个评论
John D'Errico
John D'Errico 2016-6-5
I see that you changed the problem, adding a sqrt where one was not before. Worse, you did not even change the solution that DOES result from the original problem as posed.
So, have you tried to solve this problem? See that solve generates a completely different solution, assuming that you really intended sqrt instead of the syntactically invalid sqrts?

请先登录,再进行评论。

采纳的回答

John D'Errico
John D'Errico 2016-5-29
编辑:John D'Errico 2016-5-29
Really? It is wrong? So, I guess this must be a bug of some kind?
syms t C3
x = C3*exp(-t) - (2^(1 /2)*cos(pi/4 + t))/2;
simplify(diff(x,t) + x)
ans =
sin(t)
It must be time to send dsolve (as well as simplify) back to school then. Possibly there are two ways to write that expression, both of which are mathematically equivalent. :)
Personally, I prefer that which dsolve generated, though I have not tested your alternative to see if it also solves the given problem.
By the way, there is no need to pre-define t as a numeric vector in this problem, when you then immediately use t as a symbolic variable. In fact, the two different uses of t will become confusing to you at some point, and probably cause a bug for you in the future.

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by