I’m trying to solve two separate systems using ODE23 while controlling the number of indexes so that the indexes are equal for both systems, but I couldn’t. Can you help? Than
function [sol1,sol2] = two_system
clc
close all
clear all
opt = odeset(‘RelTol’,1e-3);
sol1 = ode23(@system1,[0 5],[0],opt);
sol2 = ode23(@system2,[0 5],[0],opt);
figure(1)
plot(sol1.x(1,:),sol1.y(1,:),’b’,’LineWidth’,1.5)
hold on
plot(sol2.x(1,:),sol2.y(1,:),’–r’,’LineWidth’,1.5)
L1=length(sol1.x(1,:))
L2=length(sol2.x(1,:))
end
function dydt = system1(t,y)
M1 = y(1);
F_M1= 2;
theta1=0*pi/180;
A1 = 0.01;
%%%%%%% equation_system1 %%%%%%%
dMdt=(A1*(2*pi*(F_M1))*cos(2*pi*(F_M1)*(t)+theta1));
dydt = [dMdt];
end
function dydt = system2(t,y)
M2 = y(1);
F_M2= 2;
theta2=90*pi/180;
A2 = 0.01;
%%%%%%% equation_system2 %%%%%%%
dMdt=(A2*(2*pi*(F_M2))*cos(2*pi*(F_M2)*(t)+theta2));
dydt = [dMdt];
endfunction [sol1,sol2] = two_system
clc
close all
clear all
opt = odeset(‘RelTol’,1e-3);
sol1 = ode23(@system1,[0 5],[0],opt);
sol2 = ode23(@system2,[0 5],[0],opt);
figure(1)
plot(sol1.x(1,:),sol1.y(1,:),’b’,’LineWidth’,1.5)
hold on
plot(sol2.x(1,:),sol2.y(1,:),’–r’,’LineWidth’,1.5)
L1=length(sol1.x(1,:))
L2=length(sol2.x(1,:))
end
function dydt = system1(t,y)
M1 = y(1);
F_M1= 2;
theta1=0*pi/180;
A1 = 0.01;
%%%%%%% equation_system1 %%%%%%%
dMdt=(A1*(2*pi*(F_M1))*cos(2*pi*(F_M1)*(t)+theta1));
dydt = [dMdt];
end
function dydt = system2(t,y)
M2 = y(1);
F_M2= 2;
theta2=90*pi/180;
A2 = 0.01;
%%%%%%% equation_system2 %%%%%%%
dMdt=(A2*(2*pi*(F_M2))*cos(2*pi*(F_M2)*(t)+theta2));
dydt = [dMdt];
end function [sol1,sol2] = two_system
clc
close all
clear all
opt = odeset(‘RelTol’,1e-3);
sol1 = ode23(@system1,[0 5],[0],opt);
sol2 = ode23(@system2,[0 5],[0],opt);
figure(1)
plot(sol1.x(1,:),sol1.y(1,:),’b’,’LineWidth’,1.5)
hold on
plot(sol2.x(1,:),sol2.y(1,:),’–r’,’LineWidth’,1.5)
L1=length(sol1.x(1,:))
L2=length(sol2.x(1,:))
end
function dydt = system1(t,y)
M1 = y(1);
F_M1= 2;
theta1=0*pi/180;
A1 = 0.01;
%%%%%%% equation_system1 %%%%%%%
dMdt=(A1*(2*pi*(F_M1))*cos(2*pi*(F_M1)*(t)+theta1));
dydt = [dMdt];
end
function dydt = system2(t,y)
M2 = y(1);
F_M2= 2;
theta2=90*pi/180;
A2 = 0.01;
%%%%%%% equation_system2 %%%%%%%
dMdt=(A2*(2*pi*(F_M2))*cos(2*pi*(F_M2)*(t)+theta2));
dydt = [dMdt];
end mischa kim MATLAB Answers — New Questions