How can I plot graphs of the following variables?
1 view (last 30 days)
Show older comments
Hi,
I am trying to create a code that can show the variables "xwnew", "xbnew"," ywnew" and "ybnew" against time. The problem is that when plotting, the time t is showing as either a single point or a vertical straight line depending on how I mess around with the code. My equations are probably not right, but my focus is getting the graphs plotting properly before I move on to sorting the equations out properly.
Can anyone help please, thanks.
Zain
%Program to solve the Euler equations
clear all;
clc;
%Time Step
h = 0.01;
%Key Parameters
mb = 100; %Mass of Quarter Body (kg)
mw = 35; %Mass of Wheel (kg)
ks = 32; %Main Spring Stiffness (kN/m)
Ce = 2000; %Damping (Ns/m) (extension)
Cc = 1200; %Damping (Ns/m) (Compression)
kt = 50; %Tyre Stiffness (kN/m)
kbs = 80; %Bump Stop Stiffness (kN/m)
BSc = 20; %Bump Stop Clearance (mm)
% xw = (0:10);
% xb = (0:10);
% yw = (0:10);
% yb = (0:10);
% d = 0;
%Block to calculate number of timesteps
tstart = 0;
tend = 1.5;
N = (tend-tstart)/h;
%Main Loop
for n = 1:N
t = tstart+(n*h); %Current time
xw = n;
xb = n;
yw = n;
yb = n;
d = n;
%Limits for k
if (xb-xw)<0.02
k = ks;
else
k = ks+kbs;
end
%4 slope equations
xwdot = yw;
xbdot = xw;
%Limits for C
if (xbdot-xwdot)>0
c = Ce;
else
c = Cc;
end
ybdot = (-c*(yb-yw)-ks*(xb-xw))/mb;
ywdot = (-c*(yw-yb)-ks*(xw-xb)-kt*(xw-d))/mw;
%Euler
xwnew = xw+(xwdot*h);
xbnew = xb+(xbdot*h);
ywnew = yw+(ywdot*h);
ybnew = yb+(ybdot*h);
end
plot(t,xwnew)
plot(t,xbnew)
plot(t,ywnew)
plot(t,ybnew)
0 Comments
Accepted Answer
VBBV
on 2 Dec 2020
%Program to solve the Euler equations
clear all;
clc;
%Time Step
h = 0.01;
%Key Parameters
mb = 100; %Mass of Quarter Body (kg)
mw = 35; %Mass of Wheel (kg)
ks = 32; %Main Spring Stiffness (kN/m)
Ce = 2000; %Damping (Ns/m) (extension)
Cc = 1200; %Damping (Ns/m) (Compression)
kt = 50; %Tyre Stiffness (kN/m)
kbs = 80; %Bump Stop Stiffness (kN/m)
BSc = 20; %Bump Stop Clearance (mm)
% xw = (0:10);
% xb = (0:10);
% yw = (0:10);
% yb = (0:10);
% d = 0;
%Block to calculate number of timesteps
tstart = 0;
tend = 1.5;
N = (tend-tstart)/h;
%Main Loop
for n = 1:N
t(n) = tstart+(n*h); %Current time
xw = n;
xb = n;
yw = n;
yb = n;
d = n;
%Limits for k
if (xb-xw)<0.02
k = ks;
else
k = ks+kbs;
end
%4 slope equations
xwdot = yw;
xbdot = xw;
%Limits for C
if (xbdot-xwdot)>0
c = Ce;
else
c = Cc;
end
ybdot = (-c*(yb-yw)-ks*(xb-xw))/mb;
ywdot = (-c*(yw-yb)-ks*(xw-xb)-kt*(xw-d))/mw;
%Euler
xwnew(n) = xw+(xwdot*h);
xbnew(n) = xb+(xbdot*h);
ywnew(n) = yw+(ywdot*h);
ybnew(n) = yb+(ybdot*h);
end
plot(t,xwnew,t,xbnew,t,ywnew,t,ybnew)
Use single plot command if the vectors are of equal length
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!