How to find general solution of second order differential equation

This is the first time I am using Matlab to solve differential equations and I have a question. I have the following second order differential equation:
y’’ + 0.2*y’ + 20000000*y = sin(2*pi*t)
How do I find the general solution of this equation?

Answers (2)

syms y(t)
ode=diff(diff(y(t),t))+0.2*diff(y(t),t)==sin(2*pi*t) ;
sol = dsolve(ode)

2 Comments

Thank you for your response. The code you provided does not contain the 20000000y term. I added it back in and changed some of the numerical constants, such as changing the 0.2 to 0.3. When I reran the code, my answer did not contain any C1, C2, etc. constants. I thought that the general solution of a differential equation should have these constants. For the same equation, I compared MATLAB’s solution to Wolfram Alpha’s and Wolfram contains constants C1, C2, etc. while MATLAB does not contain these constants. How come even if I change the original equation, the general solution with these C1, C2 constants is not provided?
I forgot to add that term.....it is not possible to get a solution without constants C1, C2......you recheck..

Sign in to comment.

syms y(t)
ode = diff(y,2) + 0.3*diff(y) +...
2e7*y == sin(2*pi*t);
dsolve(ode)

13 Comments

You may want to rewrite the result in 'sincos'.
rewrite(dsolve(ode), 'sincos')
Thank you for your response. When I ran the code, I received a very long output that started out like this:
C1*exp(-(3*t)/20)*cos((7999999991^(1/2)*t)/20)
When I used Wolfram Alpha to solve for the general solution, its answer had numbers like 10^-13. Why is MATLAB producing large numbers such as 7999999991? Is MATLAB correct in solving the general solution?
I noticed that this line of code changed the way the output was formatted, which is making it look more like the output Wolfram Alpha provided. This new line of code, however, does not have i’s in its answer, which were included in the ‘rewrite’ command. As I am new to Matlab, I do not understand what these lines of code are doing. Could you explain what these commands to do the answer?
If I have an initial condition, how would I plot a graph of the solution?
If you have initial conditions use ode45.
syms y(t)
dy = diff(y);
ode = diff(y,2) + 0.3*diff(y) +...
2e7*y == sin(2*pi*t);
Sol = dsolve(ode, y(0) == 1, dy(0) == 0);
fplot(matlabFunction(Sol))
Thanks, this helps. How would I modify the code so the graph prints the solution over a range of t?
trange = [0, .01];
fplot(matlabFunction(Sol), trange)
The general solution on Wolfram Alpha contains terms such as C1, C2, etc., the number e raised to a powers, and the imaginary number i. The rewrite command produced an answer that has the number i, but no e or constants. The vpa command produced an answer with C1, C2, and the number e, but no i's. Why is the answer being produced differently, and how can I get the answer to have all three of these things (constants, e’s, and i’s)?
Well, first your question was how to find a general question. And in each question you keep adding an additional question in each question. Make some effort!! Experiment with rewrite(...) . You need to take differential equations class asap! Watch Cleve Moler’s videos!

Sign in to comment.

Asked:

on 21 Jun 2020

Edited:

on 22 Jun 2020

Community Treasure Hunt

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

Start Hunting!