How to integrate part of a function over specified timestep
8 次查看(过去 30 天)
显示 更早的评论
For a project I have to get a value for F_a at every time interval and then use that value to calculate v_veh, w_w, slip, Cf and lastly a new value for F_a to use in next iteration.
For parts of v_veh and w_w, I have to integrate over the timestep to get a value to use for the next calculation.
Below is my code so far, I have tried to implement cumtrapz to do this integration for me, but I have not been successful.
%Constants
m = 5 %[kg]
r = 0.02 %[m]
g = 9.81
Tm = m*g*0.2
N = m*g
F_rr = 0.03
F_res = m*g*F_rr
%Wheel moment calculation
spokes = 8
L_s = 0.02 %length of spokes[m]
m_s = 0.01 %mass per spoke[kg]
m_r = 0.1 %mass of rim[kg]
I_w = spokes*((1/3)*m_s*L_s^2)+(m_r*L_s^2)
%Constant Coefficients
B = 10
C = 1.9
D = 1
E = 0.97
%Create loop
t = 0:1:20
N = length(t)
v_veh= NaN(1,length(t)); %empty vehicle velocity vector
w_w= NaN(1,length(t)); %empty wheel velocity vector
slip = NaN(1,length(t)); %empty slip vector
CF =NaN(1,length(t)); %empty friction coefficient vector
v_veh(1) = 0
w_w(1) = r*((1/I_w)*(Tm*t(1)))
slip(1) = 1
CF(1) = D*sin(C*atan(B*slip(1)-E*(B*slip(1)-atan(B*slip(1)))))
F_a(1) = CF(1)*N
for i = 2:1:20
v_veh(i) = (1/m)*cumtrapz(F_a(i-1)-F_res)
w_w(i) = ((1/I_w)*cumtrapz(Tm-r*F_a(i-1)))
slip(i) = (r*w_w(i)-v_veh(i))/(r*w_w(i))
CF(i) = D*sin(C*atan(B*slip(i)-E*(B*slip(i)-atan(B*slip(i)))))
F_a(i+1) = CF(i)*N
end
figure(1)
plot(t,v_veh,'r',t,r*w_w,'b')
figure(2)
plot(t,F_a)
Any help would be greatly appreciated
2 个评论
Walter Roberson
2020-6-15
v_veh(i) = (1/m)*cumtrapz(F_a(i-1)-F_res)
F_a(i-1) is a scalar. F_res is a scalar. scalar minus scalar is scalar. So you are asking to cumtrapz() a scalar. trapz() applied to a scalar is always 0 -- a single point has no width.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!