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?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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

0 Kommentare
Antworten (1)
Torsten
am 19 Jan. 2024
Bearbeitet: Torsten
am 19 Jan. 2024
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)
fplot(ysol,[0 1])
grid on
0 Kommentare
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



