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.
댓글 수: 0
채택된 답변
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
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!