I should get a straight line graph in this equation after substituting initial conditions. I dont know where I am getting wrong. Can anyone help me with this?

1 次查看(过去 30 天)
tspan=[0,1];
z0=[0,0.01,0,0]; %initial position and velocity
%[x0,vx0,y0,vy0]
%solve the ODEs
[t, z]=ode45(@rhs,tspan,z0);
% Unpack the variables
x1=z(:,1);
v1=z(:,2);
x2=z(:,3);
v2=z(:,4);
%Plot the results
plot(t,v1);
title(' x1 vs t');
xlabel('t(s)');
ylabel('x1(m/s)');
figure
plot(t,v2);
title(' x2 vs t');
xlabel('t(s)');
ylabel('x2(m/s)');
%set grid,xmin,xmax,ymin,ymax
%___________________
function zdot=rhs(t, z)
x1=z(1); v1=z(2); x2=z(3); v2=z(4);
%put in values for mass ,C and g below
m=1;
k=1;
c=0.001;
h=0.01;
% the linear momentum balance equation
x1dot=v1;
v1dot=0;
x2dot=v2;
v2dot=(k/m)*(x1-x2)-(c/h*m)*v2;
zdot=[x1dot;v1dot;x2dot;v2dot];
end

回答(1 个)

Torsten
Torsten 2024-1-19
编辑:Torsten 2024-1-19
For which solution variable do you expect a line as solution ?
syms t y(t)
Dy = diff(y,t);
D2y = diff(y,t,2);
m=1;
k=1;
c=0.001;
h=0.01;
eqn = D2y==(k/m)*(0.01*t-y)-c/(h*m)*Dy;
conds = [y(0)==0,Dy(0)==0];
ysol = dsolve(eqn,conds)
ysol = 
fplot(ysol,[0 1])
grid on

类别

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