Clear Filters
Clear Filters

solution of differential equation

3 views (last 30 days)
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 Comment
John D'Errico
John D'Errico on 5 Jun 2016
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?

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 29 May 2016
Edited: John D'Errico on 29 May 2016
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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!