-
Notifications
You must be signed in to change notification settings - Fork 0
/
programin.m
70 lines (55 loc) · 1.66 KB
/
programin.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
clc
clear
%% Definition of initial values and solving
h=0.001; %step size
q=5; %end
t=0:h:q;% timestep vector
x0=[0;0;0.001;0.25];% initial values
% the method's function is called and bring the solutions
[t,x]=odeEulerMODMOD(@acc,t,x0); %EULER METHOD
% the solutions are plotted to get the system's response
figure(1)
% to plot the values of displacement in the suspension
% and also in the tires and brake system
plot(t,x(3,:),'r',t,x(4,:),'--b')
grid on
title('Euler method')
legend('suspension','wheel')
xlabel('t')
ylabel('x displacement (m)')
%%
[t,x]=odeMidPointEXP(@acc,t,x0); % MIDPOINT METHOD
% the solutions are plotted to get the system's response
figure(2)
% to plot the values of displacement in the suspension
% and also in the tires and brake system
plot(t,x(3,:),'r',t,x(4,:),'--b')
grid on
title('Midpoint method')
legend('suspension','wheel')
xlabel('t')
ylabel('x displacement (m)')
%%
[t,x]=odeRK4(@acc,t,x0); % RUNGE KUTTA 4TH METHOD
% the solutions are plotted to get the system's response
figure(3)
% to plot the values of displacement in the suspension
% and also in the tires and brake system
plot(t,x(3,:),'r',t,x(4,:),'--b')
grid on
title('Runge Kutta 4th method')
legend('suspension','wheel')
xlabel('t')
ylabel('x displacement (m)')
%%
[t,x]=odeHeun(@acc,t,x0); % HEUN METHOD
% the solutions are plotted to get the system's response
figure(4)
% to plot the values of displacement in the suspension
% and also in the tires and brake system
plot(t,x(3,:),'r',t,x(4,:),'--b')
grid on
title('Heun method')
legend('suspension','wheel')
xlabel('t')
ylabel('x displacement (m)')