How do I solve this differential equation 2nd order numerically within matlab?
Show older comments
Hello everyone i am completly new to Matlab and I have a problem with an exercise in my practice book. I have this differential equation:
y(0) = 1 dy(0)=0
and I would like to solve it numerically. I could also solve it simbolically but i already know how to do that and i want to practice.
So first i have to change it in first order differential equation:
But how do i continue? I´m trying for hours at this point😅
Accepted Answer
More Answers (1)
Here is a corrected complete code:
F = @(t,y)([y(2); 2*sin(t) - 3*y(2) - y(1)]); % Note signa(t) = sin(t)
IC0 = [1; 0]; % Initial conditions
tspan = [0, 10]; % Time span
[t,ysol] = ode45(F,tspan,IC0);
plot(t,ysol(:,1),'b-', 'DisplayName', 'y(t)')
hold on
plot (t,ysol(:,2), 'r-', 'DisplayName', 'dy(t)')
legend show
xlabel('t, [s]')
ylabel('y(t), dy(t)')
grid on
hold off
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!