merging two ode graphs

4 ビュー (過去 30 日間)
Susmita Panda
Susmita Panda 2021 年 5 月 6 日
コメント済み: Susmita Panda 2021 年 5 月 16 日
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
Susmita Panda
Susmita Panda 2021 年 5 月 16 日
Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by