Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Sam Chak
Sam Chak le 19 Mai 2024
Please review if this approach is accceptable.
tspan = linspace(0, 5, 251);
opt = odeset('RelTol',1e-3);
[x1, y1] = ode23(@system1, tspan, [0], opt);
[x2, y2] = ode23(@system2, tspan, [0], opt);
figure(1)
plot(x1, y1(:,1), 'b','LineWidth',1.5)
hold on
plot(x2, y2(:,1), '--r','LineWidth',1.5)
L1 = length(x1)
L1 = 251
L2 = length(x2)
L2 = 251
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

Plus de réponses (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by