merging two ode graphs

4 vues (au cours des 30 derniers jours)
Susmita Panda
Susmita Panda le 6 Mai 2021
Commenté : Susmita Panda le 16 Mai 2021
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.

Réponse acceptée

Alan Stevens
Alan Stevens le 8 Mai 2021
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 commentaires
Alan Stevens
Alan Stevens le 11 Mai 2021
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 le 16 Mai 2021
Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by