Solve Second Order Differential Equation with Initial Conditions

I am trying to solve using the dsolve function:
D^2y/dt + p(dy/dt) + 2y = cos(w*t) with the conditions y(0) = 0 and y'(0) = 0
Assuming p = 0 and w cannot be 0.
Also how would I go about plotting the solutions of y(t) vs t for different values of w such as 0.5,0.6,0.7,0.8,0.9 and 0.95
How do I go about doing this?

 채택된 답변

Star Strider
Star Strider 2016년 3월 3일
Here you go:
syms y(t) p w t
p = 0;
Deq = diff(y,2) + p*diff(y) + 2*y == cos(w*t);
Y = dsolve(Deq, diff(y(0)) == 0, y(0) == 0);
Y = simplify(Y, 'steps', 20);
Yfcn = matlabFunction(Y)
As for the plot, you will find the meshgrid function significantly helpful here. Read about it and surface and mesh in the documentation.

댓글 수: 3

How would I be able to edit the above code to accommodate for different values of w?
Use meshgrid to create your ‘t’ and ‘w’ matrices, then just give them to the ‘Yfcn’ anonymous function to create an output matrix, then plot the ‘t’ and ‘w’ matrices and the output matrix with surf or mesh.
When I input your code into Matlab, it did not return a general solution? Am I doing something wrong?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by