error when plotting 3 first order differential equations
Show older comments
I get the error seen in the middle when trying to plot the 3 first order differential equations, what am I entering incorrectly? I included the problem and my work and code, what is this error;
Index in position 2 exceeds array bounds. Index must not exceed 1.
Error in indexing (line 968)
R_tilde = builtin('subsref',L_tilde,Idx); and how or what do I do to get it to solve with out any errors?

e) Re-write the 3rd order differential equation as a system of three first-order differential equations.
Solution:

e) Use the MATLAB ode45() function to solve the system of equations and plot your solution on a new figure. The result provided by ode45() and your solution from above should match.
clear
clc
syms x;
soln = ode45(@Problem03ODEFunction,[0 10],[0;0;0]);
y = x(:, 1); % y(t)
yd = x(:, 2); % y'(t)
ydd = x(:, 3); %y"(t)
figure;
plot(soln.x,soln.y(1,:),'-','linewidth',1);
hold on;
plot(soln.x,soln.y(2,:),':','linewidth',1);
plot(soln.x,soln.y(3,:),'--','LineWidth',1);
grid on;
title('Problem 3 ODE45 Solution');
xlabel('Time (s)');
ylabel('Solution');
legend('x_{1}(t)','x_{2}(t)','x_3{3}(t)','location','best');
function [dXdt] = Problem03ODEFunction(t,x)
dx1dt = x(2);
dx2dt = x(3);
dx3dt= - (19/12) * x(3) - (19/24) * x(2) - (1/8) * x(1) + f(t);
[dXdt]=[dx1dt;dx2dt;dx3dt];
function ft=f(t)
if t>=1 && t<10
ft=1;
else
ft=0;
end
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Numerical Integration and Differential Equations 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!