Solving second order differential equation with initial conditions
8 ビュー (過去 30 日間)
古いコメントを表示
Hi, I am completely new to Matlab and having trouble solving and plotting this second order DE.
I am asked to solve the equation: 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.
This is my attempt at a solution:
syms y(t) p w t
p = 0;
y = dsolve('D2y + p*Dy + 2*y = cos(w*t)','y(0) = 0','Dy(0) = 0','t');
When I enter this into Matlab, I get no answer. Any help on what I could do?
I am also asked to plot solution of the y(t) vs t for other values of w such as 0.5,0.6, etc. How would I go about doing this? Any help or solutions would be greatly appreciated!
0 件のコメント
回答 (1 件)
Star Strider
2016 年 3 月 3 日
This may be obsolete syntax:
y = dsolve('D2y + p*Dy + 2*y = cos(w*t)','y(0) = 0','Dy(0) = 0','t');
since I do not know what version of MATLAB you are using.
The code I posted in your previous Question Solve Second Order Differential Equation with Initial Conditions gives you the symbolic answer, and an anonymous function (that I put on one line here):
Yfcn = @(C,t,w) C.*sin(sqrt(2.0).*t)+(cos(sqrt(2.0).*t)-cos(t.*w))./(w.^2-2.0);
You have to supply the ‘C’ constant, but otherwise you can simply use the output from meshgrid to create your ‘t’ and ‘w’ matrices and supply them as arguments to the ‘Yfcn’ function. Then use surf or mesh with the matrix produced by a call to ‘Yfcn’ to plot the result.
4 件のコメント
Star Strider
2016 年 3 月 3 日
MATLAB can be a bit intimidating at the beginning because it’s possible to do so much with it.
This is what I would do:
Yfcn = @(C,t,w) C.*sin(sqrt(2.0).*t)+(cos(sqrt(2.0).*t)-cos(t.*w))./(w.^2-2.0);
t = linspace(0, 10, 25);
w = linspace(0, 2*pi, 50);
[T,W] = meshgrid(t,w);
C = 1; % Constant
Y = Yfcn(C,T,W);
figure(1)
surf(T, W, Y)
grid on
xlabel('Time')
ylabel('Angular Frequency (rad)')
zlabel('Y')
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!