Message Boards Message Boards

Solve first order linear equation using DSolve?

Posted 5 years ago

I tried to solve the first order linear equation with mathematica, but I failed to get the right answer, which I got by hand. Can you tell me why I am wrong? thanks very much!

the question:

DSolve[{y'[t] == (I*w0 - R)*y[t] + B*r/2*(Exp [I*w*t] + Exp [-I*w*t]), y[0] == 0}, y[0] == 0}, y[t],t]

the wrong answer i got: correct the question: the answer is right !!! just not the form I expected.

{{y -> Function[{t}, (B E^(t (-R + I w0))
        r (-2 R + E^(t (R - I (w + w0))) R + 
         E^(2 I t w + t (R - I (w + w0))) R + 
         I E^(t (R - I (w + w0))) w - 
         I E^(2 I t w + t (R - I (w + w0))) w + 2 I w0 - 
         I E^(t (R - I (w + w0))) w0 - 
         I E^(2 I t w + t (R - I (w + w0))) w0))/(2 (R - I w - 
         I w0) (R + I w - I w0))]}}

``

the right answer: correct the question: the answer I expected and calculated by hand. enter image description here

POSTED BY: tian zhao
15 Replies

Welcome to Wolfram Community! Please make sure you know the rules: https://wolfr.am/READ-1ST

The rules explain how to format your code properly. If you do not format code, it may become corrupted and useless to other members. Please EDIT your post and make sure code blocks start on a new paragraph and look framed and colored like this.

int = Integrate[1/(x^3 - 1), x];
Map[Framed, int, Infinity]

enter image description here

POSTED BY: Moderation Team
Posted 5 years ago

I had corrected it ,thanks~

POSTED BY: tian zhao

There is something wrong with your "right answer". It satisfies neither the differential equation nor the initial condition.

POSTED BY: Gianluca Gorni
ODE = {y'[t] == (I*w0 - R)*y[t] + B/2*r*(Exp[I*w*t] + Exp[-I*w*t]), y[0] == 0};
sol = DSolve[ODE, y, t] // FullSimplify
ODE /. sol // FullSimplify(*Check if  Mathematica solution is correct. OK is correct. *)
(* {{True, True}} *)

YOURSsolution = {{y -> Function[{t}, (B*r)/2*(Exp[I w t]/(R + I*(w - w0)) + Exp[-I w t]/(
     R - I (w - w0)))]}};
ODE /. YOURSsolution // FullSimplify(*Check if  Yours solution is correct. It's seems is Not Correct !.Is not TRUE *)
 (* {{(B E^(-I t w) r w0)/(I R + w - w0) == 0, (B r R)/(R^2 + (w - w0)^2) == 0}} *)
POSTED BY: Mariusz Iwaniuk

DSolve gives

In[1]:= ysol = 
 y /. DSolve[{y'[t] == (I*w0 - R)*y[t] + 
       B*r/2*(Exp[I*w*t] + Exp[-I*w*t]), y[0] == 0}, y, t][[1, 1]]

Out[1]= Function[{t}, (B E^(t (-R + I w0))
     r (-2 R + E^(t (R - I (w + w0))) R + 
      E^(2 I t w + t (R - I (w + w0))) R + 
      I E^(t (R - I (w + w0))) w - 
      I E^(2 I t w + t (R - I (w + w0))) w + 2 I w0 - 
      I E^(t (R - I (w + w0))) w0 - 
      I E^(2 I t w + t (R - I (w + w0))) w0))/(2 (R^2 + w^2 - 
      2 I R w0 - w0^2))]

with

In[2]:= ysol[0]
Out[2]= 0

and

In[5]:= test = 
 FullSimplify[
  D[ysol[t], t] - ((I*w0 - R)*ysol[t] + B*r/2*(Exp[I*w*t] + Exp[-I*w*t])) // 
   ExpToTrig, Element[{B, r, R, w, w0}, Reals]]

Out[5]= 0

So ysol is a solution to your problem with real B, r, R , w and w0

POSTED BY: Hans Dolhaine
Posted 5 years ago

Thanks for pointing out mistakes. I am not rigorous. but it satisfied the differential equation if you calculate by hand. I have got the form I expected. I confused the general solution and special solution.

In[16]:=  ODE = {y'[t] == (I*w0 - R)*y[t] + B/2*r*(Exp[I*w*t] + Exp[-I*w*t])};
    sol = DSolve[ODE, y, t] // FullSimplify
Out[17]:={{y -> Function[{t}, 
    1/2 B E^(t (-R + I w0) + t (R - I (w + w0)))
       r (E^(2 I t w)/(R + I (w - w0)) + 1/(R - I (w + w0))) + 
     E^(t (-R + I w0)) C[1]]}}                                                                                                        
In[18]:= Simplify[1/2 B E^(t (-R + I w0) + t (R - I (w + w0)))
                 r (E^(2 I t w)/(R + I (w - w0)) + 1/(R - I (w + w0)))]                                                
 Out[19]:= 1/2 B E^(-I t w) r (E^(2 I t w)/(R + I (w - w0)) + 1/(R - I (w + w0)))
POSTED BY: tian zhao
Posted 5 years ago

I appreciate your return. thanks very much. I got the form answer by the code. I think i only want the special solution?

POSTED BY: tian zhao
Posted 5 years ago

Thanks for your complete return. if I use the code below ,I can got the answer I expected.

In[16]:=  ODE = {y'[t] == (I*w0 - R)*y[t] + B/2*r*(Exp[I*w*t] + Exp[-I*w*t])};
    sol = DSolve[ODE, y, t] // FullSimplify
Out[17]:={{y -> Function[{t}, 
    1/2 B E^(t (-R + I w0) + t (R - I (w + w0)))
       r (E^(2 I t w)/(R + I (w - w0)) + 1/(R - I (w + w0))) + 
     E^(t (-R + I w0)) C[1]]}}                                                                                                        
In[18]:= Simplify[1/2 B E^(t (-R + I w0) + t (R - I (w + w0)))
                 r (E^(2 I t w)/(R + I (w - w0)) + 1/(R - I (w + w0)))]                                                
 Out[19]:= 1/2 B E^(-I t w) r (E^(2 I t w)/(R + I (w - w0)) + 1/(R - I (w + w0))) 

but I still confuse why my expected answer is wrong when I instead the eqution with it.

ODE = {y'[t] == (I*w0 - R)*y[t] + B/2*r*(Exp[I*w*t] + Exp[-I*w*t])};
sol = DSolve[ODE, y, t] // FullSimplifyere                                                                    
  YOURSsolution = {{y -> 
 Function[{t}, (B*r)/
    2*(Exp[I w t]/(R + I*(w - w0)) + 
     Exp[-I w t]/(R - I (w - w0)))]}};                                                                                                   
 ODE /. YOURSsolution // FullSimplify
POSTED BY: tian zhao

What exactly is your problem???

As Mariusz pointed out your solution YOURSsolution

In[36]:= YOURSsolution[t]    
Out[36]= 1/2 B r (E^(-I t w)/(R - I (w - w0)) + E^(I t w)/( R + I (w - w0)))

is NOT a solution for your ODE

In[34]:= FullSimplify[ODE /. y -> YOURSsolution]    
Out[34]= {(B E^(-I t w) r w0)/(I R + w - w0) == 0}

(but ysol is :

In[37]:= FullSimplify[ODE /. y -> ysol]
Out[37]= {True}

)

nor does it fulfill your initial condition as Mariusz has already pointed out

In[31]:= YOURSsolution[0] // FullSimplify
Out[31]= (B r R)/(R^2 + (w - w0)^2)

So, what is your question?

By the way, ysol is generally a solution without the restrictions mentioned before

In[17]:= test = 
 FullSimplify[
  D[ysol[t], t] - ((I*w0 - R)*ysol[t] + B*r/2*(Exp[I*w*t] + Exp[-I*w*t]))]

Out[17]= 0
POSTED BY: Hans Dolhaine
Posted 5 years ago

Thanks for your return again. My problem is that I want to get the solution form of YOURSsolution when I solve the equation with Mathematica. I have known that ysol is generally a solution. I think YOURSsolution is a special solution. I have solved the problem by the code that I posted. thanks~

POSTED BY: tian zhao

I want to get the solution form of YOURSsolution

What does that mean?

I think YOURSsolution is a special solution.

YOURSsolution is NOT a solution to your ODE. Why do you have this idea?

POSTED BY: Hans Dolhaine
Posted 5 years ago

Happy new year! The question came from formula derivation of a dissertation. YOURSsolution is exactly the answer the dissertation get. So I want to get the same answer by Mathematica. By dropping E^(t (-R + I w0)) C[1]]}} from the answer derivated from Mathematica, I get the same answer I expected.
I think YOURSsolution is a special solution by dropping C[1], maybe what I thought is wrong. But it satisfied ODE if you calculate by hand. the answer can make the right of the equation equal to the left. I don't know the reason...

POSTED BY: tian zhao
Posted 5 years ago

Happy new year! The question came from formula derivation of a dissertation. YOURSsolution is exactly the answer the dissertation get. So I want to get the same answer by Mathematica. By dropping E^(t (-R + I w0)) C[1]]}} from the answer derivated from Mathematica, I get the same answer I expected.
I think YOURSsolution is a special solution by dropping C[1], maybe what I thought is wrong. But it satisfied ODE if you calculate by hand. the answer can make the right of the equation equal to the left. I don't know the reason...

POSTED BY: tian zhao

NO!!!

YOURSsolution is NOT a solution of ODE, even if calculated by hand, and it does NOT fulfill YOURSsolution[ 0 ] == 0.

In[150]:= YOURSsolution /. t -> 0
% // FullSimplify

Out[150]= 1/2 B r (1/(R - I (w - w0)) + 1/(R + I (w - w0)))    
Out[151]= (B r R)/(R^2 + (w - w0)^2)

You may drop the condition y[ 0 ] == 0 in your ODE to get

ysol1 = y /. DSolve[{y'[t] == (I*w0 - R)*y[t] + B*r/2*(Exp[I*w*t] + Exp[-I*w*t])}, y, t][[1, 1]]

Then drop, as you wanted to, C[1]

ysol2 = ysol1 /. C[1] -> 0

But

In[171]:= ysol2[0]
Out[171]= 1/2 B r (1/(R + I (w - w0)) + 1/(R - I (w + w0)))

That is NOT what you wanted.

ysol2 is a solution of ODE

In[172]:= 
ysol2'[t] == (I*w0 - R)*ysol2[t] +    B*r/2*(Exp[I*w*t] + Exp[-I*w*t]) // FullSimplify

Out[172]= True

ysol2 looks very similar to YOURSsolution (but remember: it does not fulfill your initial condition)

In[181]:= (B r)/2 (2/(B r) ysol2[t] // Simplify // Expand)

Out[181]= 1/2 B r (E^(I t w)/(R + I (w - w0)) + E^(-I t w)/(  R - I (w + w0)))

but it is not the same

In[173]:= ysol2[t] - YOURSsolution // FullSimplify
Out[173]= (I B E^(-I t w) r w0)/((R - I w)^2 + w0^2)

Look at the signs in the w / w0 terms , I have the suspicion that there is a typo in that dissertation.

POSTED BY: Hans Dolhaine
Posted 5 years ago

thanks for your detailed reply. I appreciate that you are so responsible and warm!!! ysol2 is a solution of ODE, I can not agree with you more. thanks!!!

POSTED BY: tian zhao
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract