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 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.
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]
ODE = {y’[t] == (Iw0 - R)y[t] + B/2r(Exp[Iwt] + Exp[-Iwt]), 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}} *)
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))]
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)))
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
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~
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…
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…
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!!!