필터 지우기
필터 지우기

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 (최근 30일)
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

채택된 답변

Sam Chak
Sam Chak 2024년 5월 19일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by