I am trying to plot a graph for a second order ODE for the midpoint method.
Mostrar comentarios más antiguos
My error is: Unable to perform assignment because the left and right sides have a different number of elements.
Error in Question3A (line 8)
x(2) = -5*heaviside(t-6)*exp((1/2)*(6-t))-4*A-8*B;
Error in Q3script (line 29)
A(:,i+1)= A(i) + (dt*Question3A(thalf,Ahalf,B(i)));
A = zeros(2,length(t1));
B = zeros(2,length(t1));
%Initial conditions
A(1) = 2;
B(1) = 3;
% Write a loop to solve the ODE using the midpoint method
for i = 1:length(t1)-1
thalf = 0.5*(t1(i) + t1(i+1));
Ahalf = A(i) + (0.5*dt*Question3A(t1(i),A(i),B(i)));
A(:,i+1)= A(i) + (dt*Question3A(thalf,Ahalf,B(i)));
end
my function file
function x = Question3A(t,A,B)
x = zeros(2,1);
x(1) = B;
x(2) = -5*heaviside(t-6)*exp((1/2)*(6-t))-4*A-8*B;
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!