merging two ode graphs

1 次查看(过去 30 天)
I tried to merge two ode function but getting an error. The first ode ranges upto T and thereafter I want result of other ode.

采纳的回答

Alan Stevens
Alan Stevens 2021-5-8
Your testode2 function must return a column vector. Try
function dy = testode2(~,y) %%% Must return a column vector
j=1;beta=0.025;k=j^4;c=2*j^2*beta;m=1;
f=zeros(2,1);
dy = [y(2);
(-k*y(1)/m-c*y(2)/m)];
end
  4 个评论
Alan Stevens
Alan Stevens 2021-5-11
Perhaps you mean more like this:
wb=14.25;eta=0.15;T=pi/(wb*eta);
tspan_1=[0:0.001:T];
tspan_2=[T:0.001:10];
y0_1=[0;0];
%y0_2=[0.02 0.05];
[t1,y1]=ode45(@diffeqn11,tspan_1,y0_1);
[r,c]=size(y1);
y0_2 = y1(r,:);
[t2,y2]=ode45(@testode2,tspan_2,y0_2);
%plot
plot(t1, y1(:,1), 'r', 'LineWidth',2);
hold on
plot(t2, y2(:,1), 'b', 'LineWidth',2);
function dy = testode2(~,y)
j=1;beta=0.025;k=j^4;c=2*j^2*beta;m=1;
f=zeros(2,1);
dy = [y(2);
-k*y(1)/m-c*y(2)/m];
end
function f= diffeqn11(t,y)
eta=0.15;wb=14.25;j=1;beta=0.025;P=6;L=20;mb=3000*9.81/20;v=27.77;x=0.5;
%A=sin(j*pi*x/L);
f=zeros(2,1);
f(1)=y(2);
f(2)=j^2*sin(j*eta*t)-(j^4*y(1))-(2*beta*j^2*y(2));%dimensionless
%f(2)=(2/mb*L)*P*sin(j*pi*v*t/L)-2*beta*wb*y(2)-wb^2*y(1);%non-dimensioned Qb
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by