How do i plot a derivative versus time
3 次查看(过去 30 天)
显示 更早的评论
I have the code below and want to plot for eg yp(2) vs time-
How can I do this?
function yp = reduced(t,y)
m_a = 0.5;
c_ay=1;
c_az=1;
k_ay= 1;
k_az =1;
Fy=@(t)1;
Fz=@(t)1;
T_a = @(t)178;
I_a = 2000;
R_a=1;
yp = zeros(6,1);
yp(1) = y(2);
yp(2) = (-Fy(t) - k_ay*y(1) - c_ay*y(2))/m_a;
yp(3) = y(4);
yp(4) = (-Fz(t) - k_az*y(3) - c_az*y(4))/m_a;
yp(5) = y(6);
yp(6) = (-T_a(t) - Fy(t)*R_a)/I_a;
end
0 个评论
回答(1 个)
Torsten
2022-11-16
[T,Y] = ode45(@reduced,tspan,y0)
for i = 1:numel(T)
dy(i,:) = reduced(T(i),Y(i,:));
end
plot(T,dy(:,2))
3 个评论
Torsten
2022-11-16
Runs without problems.
tspan = [0 10];
y0 = zeros(6,1);
[T,Y] = ode45(@reduced,tspan,y0);
for i = 1:numel(T)
dy(i,:) = reduced(T(i),Y(i,:));
end
plot(T,dy(:,2))
function yp = reduced(t,y)
m_a = 0.5;
c_ay=1;
c_az=1;
k_ay= 1;
k_az =1;
Fy=@(t)1;
Fz=@(t)1;
T_a = @(t)178;
I_a = 2000;
R_a=1;
yp = zeros(6,1);
yp(1) = y(2);
yp(2) = (-Fy(t) - k_ay*y(1) - c_ay*y(2))/m_a;
yp(3) = y(4);
yp(4) = (-Fz(t) - k_az*y(3) - c_az*y(4))/m_a;
yp(5) = y(6);
yp(6) = (-T_a(t) - Fy(t)*R_a)/I_a;
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!