Simple Differential Equation in Matlab and Wolfram get two different answer?

133 Views Asked by At

I'm a beginner in using Matlab. if I have a DE like

$$x'(t)=\frac{1}{\sin (2x)}$$

How I can Implement in Matlab to calculate just answer?

I try dsolve like as:

ySol(t) = dsolve(ode,cond) but couldn't define ode, and cond.

Update: this is my matlab: enter image description here

and different answer from Wolfram:

enter image description here

2

There are 2 best solutions below

4
On BEST ANSWER

These are the same answer. Separate to get

$$ \sin(2x) dx = dt $$

There are two ways to do this. The first is to integrate directly:

$$ -\frac12\cos(2x) = t + c_1 $$ $$ \cos(2x) = -2(t+c_1) $$ $$ x = \frac12 \arccos(-2(t+c_1)) $$

This is the answer given by Wolfram.

The second way is to use the double-angle formula

$$ 2\sin(x)\cos(x) dx = dt $$

$$ \sin^2(x) = t + c_2 $$

$$ \sin (x) = \sqrt{t+c_2} $$

$$ x = \arcsin(\sqrt{t+c_2}) $$

This is the answer given by MATLAB.

If you're wondering why there two different anti-derivatives of $\sin(2x)$, it's because they differ by a constant

$$ \sin^2 x = -\frac12\cos (2x) + \frac12 $$

0
On

A (Matlab oriented) complement to the very didactic answer by @Dylan.

Here is an extension of your program displaying either two or one solution(s). I use some Matlab instructions that may be new to you, in particular with a symbolic initial value $a$ (you had fixed this initial value to $a=1$) that can be constrained to be positive. The first part is with symbolic variables, almost the same as yours ; the second part uses numerical variables in order to see what happens for different values of $a$:

clear all;close all;
syms x(t) a
ode=diff(x)==1/sin(2*x); % no need to take diff(x,t)...
cond=x(0)==a; % a instead of 1
%assume(a>0)
s=dsolve(ode,cond) : % one or two solutions
%%%
T=0:0.01:0.7;
for a=0:0.1:pi/2
   g=inline(s(1));plot(T,real(g(a,T)),'r');hold on;
   g=inline(s(2));plot(T,real(g(a,T)),'b');hold on;% to be suppressed if a>0
end;

The answer(s) given by Matlab are :

s =

asin((sin(a)^2 + t)^(1/2))

-asin((sin(a)^2 + t)^(1/2))

Which one is the good one ?... Both...

If we introduce "assume(a>0)", Matlab gives a single answer which is the first one.

Other analytical facts could be commented (for example the domains of existence of solutions), but I think the asker will be satisfied with the details already given.

enter image description here